From 76ea301641d506ed4a30e45f3b956ed534f32728 Mon Sep 17 00:00:00 2001
From: Aurélio A. Heckert
Date: Thu, 28 Mar 2013 22:38:01 -0300
Subject: [PATCH] move display_short_format to the generic ApplicationHelper
---
app/helpers/application_helper.rb | 30 ++++++++++++++++++++++++++++++
app/helpers/blog_helper.rb | 12 ------------
test/unit/application_helper_test.rb | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 12 deletions(-)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 4f1e4a1..e90a0b3 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -998,6 +998,36 @@ module ApplicationHelper
content
end
+ # Please, use link_to by default!
+ # This method was created to work around to inexplicable
+ # chain of problems when display_short_format was called
+ # from Article model for an ArticleBlock.
+ def link_to_article(text, article, anchor=nil)
+ if article.profile.domains.empty?
+ href = "/#{article.url[:profile]}/"
+ else
+ href = "http://#{article.profile.domains.first.name}/"
+ end
+ href += article.url[:page].join('/')
+ href += '#' + anchor if anchor
+ content_tag('a', text, :href => href)
+ end
+
+ def display_short_format(article, options={})
+ options[:comments_link] ||= true
+ options[:read_more_link] ||= true
+ html = content_tag('div',
+ article.lead +
+ content_tag('div',
+ (options[:comments_link] ? link_to_comments(article) : '') +
+ (options[:read_more_link] ? link_to_article( _('Read more'), article) : ''),
+ :class => 'read-more'
+ ),
+ :class => 'short-post'
+ )
+ html
+ end
+
def colorpicker_field(object_name, method, options = {})
text_field(object_name, method, options.merge(:class => 'colorpicker_field'))
end
diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb
index a74650f..ae131c2 100644
--- a/app/helpers/blog_helper.rb
+++ b/app/helpers/blog_helper.rb
@@ -47,18 +47,6 @@ module BlogHelper
article_title(article, :no_comments => no_comments) + html
end
- def display_short_format(article)
- html = content_tag('div',
- article.lead +
- content_tag('div',
- link_to_comments(article) +
- link_to( _('Read more'), article.url),
- :class => 'read-more'),
- :class => 'short-post'
- )
- html
- end
-
def display_full_format(article)
html = article_to_html(article)
html = content_tag('p', html) if ! html.include?('
')
diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb
index 0efbddf..3af2278 100644
--- a/test/unit/application_helper_test.rb
+++ b/test/unit/application_helper_test.rb
@@ -657,6 +657,43 @@ class ApplicationHelperTest < ActiveSupport::TestCase
assert_not_nil add_zoom_to_images
end
+ should 'link to article' do
+ c = fast_create(Community)
+ a = fast_create(TinyMceArticle, :profile_id => c.id)
+ assert_equal(
+ "x",
+ link_to_article('x', a) )
+ end
+
+ should 'link to article, with anchor' do
+ c = fast_create(Community)
+ a = fast_create(TinyMceArticle, :profile_id => c.id)
+ assert_equal(
+ "x",
+ link_to_article('x', a, 'place') )
+ end
+
+ should 'link to article, in a blog' do
+ c = fast_create(Community)
+ b = fast_create(Blog, :profile_id => c.id)
+ a = fast_create(TinyMceArticle, :profile_id => c.id, :parent_id => b.id)
+ a.save! # needed to link to the parent blog
+ assert_equal(
+ "x",
+ link_to_article('x', a) )
+ end
+
+ should 'link to article, in a profile with domain' do
+ c = fast_create(Community)
+ c.domains << Domain.new(:name=>'domain.xyz')
+ b = fast_create(Blog, :profile_id => c.id)
+ a = fast_create(TinyMceArticle, :profile_id => c.id, :parent_id => b.id)
+ a.save!
+ assert_equal(
+ "x",
+ link_to_article('x', a) )
+ end
+
protected
include NoosferoTestHelper
--
libgit2 0.21.2