diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb
index 4efe3aa..4dd6519 100644
--- a/app/helpers/blog_helper.rb
+++ b/app/helpers/blog_helper.rb
@@ -50,7 +50,7 @@ module BlogHelper
def display_short_format(article)
html = content_tag('div',
- article.first_paragraph +
+ article.lead +
content_tag('div',
link_to_comments(article) +
link_to( _('Read more'), article.url),
diff --git a/app/models/article.rb b/app/models/article.rb
index 5e0c7e3..fe11233 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -345,6 +345,10 @@ class Article < ActiveRecord::Base
Hpricot(to_html).search('p').first.to_html
end
+ def lead
+ abstract.blank? ? first_paragraph : abstract
+ end
+
def creator
creator_id = versions[0][:last_changed_by_id]
creator_id && Profile.find(creator_id)
diff --git a/app/models/published_article.rb b/app/models/published_article.rb
index e3c3fe8..a7a3653 100644
--- a/app/models/published_article.rb
+++ b/app/models/published_article.rb
@@ -32,4 +32,9 @@ class PublishedArticle < Article
def to_html(options={})
reference_article ? reference_article.to_html : ('' + _('The original text was removed.') + '')
end
+
+ def abstract
+ reference_article && reference_article.abstract
+ end
+
end
diff --git a/app/views/cms/_textile_article.rhtml b/app/views/cms/_textile_article.rhtml
index 9a2c3b3..c0442c9 100644
--- a/app/views/cms/_textile_article.rhtml
+++ b/app/views/cms/_textile_article.rhtml
@@ -5,7 +5,7 @@
<%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %>
-<%= button_to_function :edit, _("Lead"), nil, :id => "lead-link", :style => "margin-left: 0px;" %>
+<%= button :add, _("Lead"), '#', :id => "lead-button", :style => "margin-left: 0px;" %>
<%= !highlighted.abstract.blank? ? highlighted.abstract : highlighted.first_paragraph %>
+<%= link_to(_('Read more'), highlighted.url) %>
diff --git a/public/javascripts/article.js b/public/javascripts/article.js index c73cdbc..f28a711 100644 --- a/public/javascripts/article.js +++ b/public/javascripts/article.js @@ -1,8 +1,7 @@ (function($) { - $("#lead-link").click(function(){ - if($('#article-lead').css('display') == 'none') - $('#article-lead').slideDown(); - else - $('#article-lead').slideUp(); + $("#lead-button").click(function(){ + $(this).toggleClass('icon-add').toggleClass('icon-remove'); + $('#article-lead').slideToggle(); + return false; }) })(jQuery) diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 2bda498..ff47d99 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -895,4 +895,22 @@ class ArticleTest < Test::Unit::TestCase article.name = 'a123456789abcdefghij' assert_equal 'a123456789ab...', article.short_title end + + should 'return abstract as lead' do + a = Article.new(:abstract => 'lead') + assert_equal 'lead', a.lead + end + + should 'return first paragraph as lead by default' do + a = Article.new + a.stubs(:first_paragraph).returns('first
') + assert_equal 'first
', a.lead + end + + should 'return first paragraph as lead with empty but non-null abstract' do + a = Article.new(:abstract => '') + a.stubs(:first_paragraph).returns('first
') + assert_equal 'first
', a.lead + end + end diff --git a/test/unit/published_article_test.rb b/test/unit/published_article_test.rb index af1660b..c08d1d8 100644 --- a/test/unit/published_article_test.rb +++ b/test/unit/published_article_test.rb @@ -110,6 +110,21 @@ class PublishedArticleTest < ActiveSupport::TestCase assert_match /removed/, p.to_html end + should 'use abstract from referenced article' do + original = Article.new(:abstract => 'this is the abstract') + published = PublishedArticle.new + published.stubs(:reference_article).returns(original) + + assert_equal 'this is the abstract', published.abstract + end + + should 'return no abstract when reference_article does not exist' do + published = PublishedArticle.new + published.stubs(:reference_article).returns(nil) + + assert_nil published.abstract + end + should 'specified parent overwrite blog' do parent = mock @article.stubs(:parent).returns(parent) -- libgit2 0.21.2