Commit 76ea301641d506ed4a30e45f3b956ed534f32728
1 parent
0f6edf86
Exists in
master
and in
29 other branches
move display_short_format to the generic ApplicationHelper
Showing
3 changed files
with
67 additions
and
12 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -998,6 +998,36 @@ module ApplicationHelper | @@ -998,6 +998,36 @@ module ApplicationHelper | ||
998 | content | 998 | content |
999 | end | 999 | end |
1000 | 1000 | ||
1001 | + # Please, use link_to by default! | ||
1002 | + # This method was created to work around to inexplicable | ||
1003 | + # chain of problems when display_short_format was called | ||
1004 | + # from Article model for an ArticleBlock. | ||
1005 | + def link_to_article(text, article, anchor=nil) | ||
1006 | + if article.profile.domains.empty? | ||
1007 | + href = "/#{article.url[:profile]}/" | ||
1008 | + else | ||
1009 | + href = "http://#{article.profile.domains.first.name}/" | ||
1010 | + end | ||
1011 | + href += article.url[:page].join('/') | ||
1012 | + href += '#' + anchor if anchor | ||
1013 | + content_tag('a', text, :href => href) | ||
1014 | + end | ||
1015 | + | ||
1016 | + def display_short_format(article, options={}) | ||
1017 | + options[:comments_link] ||= true | ||
1018 | + options[:read_more_link] ||= true | ||
1019 | + html = content_tag('div', | ||
1020 | + article.lead + | ||
1021 | + content_tag('div', | ||
1022 | + (options[:comments_link] ? link_to_comments(article) : '') + | ||
1023 | + (options[:read_more_link] ? link_to_article( _('Read more'), article) : ''), | ||
1024 | + :class => 'read-more' | ||
1025 | + ), | ||
1026 | + :class => 'short-post' | ||
1027 | + ) | ||
1028 | + html | ||
1029 | + end | ||
1030 | + | ||
1001 | def colorpicker_field(object_name, method, options = {}) | 1031 | def colorpicker_field(object_name, method, options = {}) |
1002 | text_field(object_name, method, options.merge(:class => 'colorpicker_field')) | 1032 | text_field(object_name, method, options.merge(:class => 'colorpicker_field')) |
1003 | end | 1033 | end |
app/helpers/blog_helper.rb
@@ -47,18 +47,6 @@ module BlogHelper | @@ -47,18 +47,6 @@ module BlogHelper | ||
47 | article_title(article, :no_comments => no_comments) + html | 47 | article_title(article, :no_comments => no_comments) + html |
48 | end | 48 | end |
49 | 49 | ||
50 | - def display_short_format(article) | ||
51 | - html = content_tag('div', | ||
52 | - article.lead + | ||
53 | - content_tag('div', | ||
54 | - link_to_comments(article) + | ||
55 | - link_to( _('Read more'), article.url), | ||
56 | - :class => 'read-more'), | ||
57 | - :class => 'short-post' | ||
58 | - ) | ||
59 | - html | ||
60 | - end | ||
61 | - | ||
62 | def display_full_format(article) | 50 | def display_full_format(article) |
63 | html = article_to_html(article) | 51 | html = article_to_html(article) |
64 | html = content_tag('p', html) if ! html.include?('</p>') | 52 | html = content_tag('p', html) if ! html.include?('</p>') |
test/unit/application_helper_test.rb
@@ -657,6 +657,43 @@ class ApplicationHelperTest < ActiveSupport::TestCase | @@ -657,6 +657,43 @@ class ApplicationHelperTest < ActiveSupport::TestCase | ||
657 | assert_not_nil add_zoom_to_images | 657 | assert_not_nil add_zoom_to_images |
658 | end | 658 | end |
659 | 659 | ||
660 | + should 'link to article' do | ||
661 | + c = fast_create(Community) | ||
662 | + a = fast_create(TinyMceArticle, :profile_id => c.id) | ||
663 | + assert_equal( | ||
664 | + "<a href=\"/#{c.identifier}/#{a.slug}\">x</a>", | ||
665 | + link_to_article('x', a) ) | ||
666 | + end | ||
667 | + | ||
668 | + should 'link to article, with anchor' do | ||
669 | + c = fast_create(Community) | ||
670 | + a = fast_create(TinyMceArticle, :profile_id => c.id) | ||
671 | + assert_equal( | ||
672 | + "<a href=\"/#{c.identifier}/#{a.slug}#place\">x</a>", | ||
673 | + link_to_article('x', a, 'place') ) | ||
674 | + end | ||
675 | + | ||
676 | + should 'link to article, in a blog' do | ||
677 | + c = fast_create(Community) | ||
678 | + b = fast_create(Blog, :profile_id => c.id) | ||
679 | + a = fast_create(TinyMceArticle, :profile_id => c.id, :parent_id => b.id) | ||
680 | + a.save! # needed to link to the parent blog | ||
681 | + assert_equal( | ||
682 | + "<a href=\"/#{c.identifier}/#{b.slug}/#{a.slug}\">x</a>", | ||
683 | + link_to_article('x', a) ) | ||
684 | + end | ||
685 | + | ||
686 | + should 'link to article, in a profile with domain' do | ||
687 | + c = fast_create(Community) | ||
688 | + c.domains << Domain.new(:name=>'domain.xyz') | ||
689 | + b = fast_create(Blog, :profile_id => c.id) | ||
690 | + a = fast_create(TinyMceArticle, :profile_id => c.id, :parent_id => b.id) | ||
691 | + a.save! | ||
692 | + assert_equal( | ||
693 | + "<a href=\"http://domain.xyz/#{b.slug}/#{a.slug}\">x</a>", | ||
694 | + link_to_article('x', a) ) | ||
695 | + end | ||
696 | + | ||
660 | protected | 697 | protected |
661 | include NoosferoTestHelper | 698 | include NoosferoTestHelper |
662 | 699 |