Commit 3789a58e513c897e374383c2872a1392f171fe89

Authored by Moises Machado
Committed by Antonio Terceiro
1 parent 848805e6

ActionItem1040: improved the blog formatting

* moved the comments link to near the article title
 * added a anchor for the beginning of the comments
 * removed the link for comments at the end of the article
 * added warps for borders
 * changed h3 to h1 for post titles in blog view
 * removed h1 from tinyMCE format selector
 * added hr tag between blog posts
 * added a div with blog-posts tag for styling of this hr
app/helpers/blog_helper.rb
@@ -28,12 +28,11 @@ module BlogHelper @@ -28,12 +28,11 @@ module BlogHelper
28 content << content_tag('div', display_post(i), :class => 'blog-post' + css_add, :id => "post-#{i.id}") 28 content << content_tag('div', display_post(i), :class => 'blog-post' + css_add, :id => "post-#{i.id}")
29 end 29 end
30 } 30 }
31 - content.join("\n") + (pagination or '') 31 + content.join("\n<hr />\n") + (pagination or '')
32 end 32 end
33 33
34 def display_post(article) 34 def display_post(article)
35 - article_title(article) + content_tag('p', article.to_html) +  
36 - content_tag('p', link_to( number_of_comments(article), article.url.merge(:form => 'opened', :anchor => 'comment_form') ), :class => 'metadata') 35 + article_title(article) + content_tag('p', article.to_html)
37 end 36 end
38 37
39 end 38 end
app/helpers/content_viewer_helper.rb
@@ -18,9 +18,9 @@ module ContentViewerHelper @@ -18,9 +18,9 @@ module ContentViewerHelper
18 title = content_tag('h1', title, :class => 'title') 18 title = content_tag('h1', title, :class => 'title')
19 if article.belongs_to_blog? 19 if article.belongs_to_blog?
20 unless args[:no_link] 20 unless args[:no_link]
21 - title = content_tag('h3', link_to(article.name, article.url), :class => 'title') 21 + title = content_tag('h1', link_to(article.name, article.url), :class => 'title')
22 end 22 end
23 - title << content_tag('span', _("%s, by %s") % [show_date(article.published_at), link_to(article.author.name, article.author.url)], :class => 'created-at') 23 + title << content_tag('span', _("%s, by %s - %s") % [show_date(article.published_at), link_to(article.author.name, article.author.url), link_to_comments(article)], :class => 'created-at')
24 end 24 end
25 title 25 title
26 end 26 end
@@ -31,4 +31,8 @@ module ContentViewerHelper @@ -31,4 +31,8 @@ module ContentViewerHelper
31 content 31 content
32 end 32 end
33 33
  34 + def link_to_comments(article)
  35 + link_to( number_of_comments(article), article.url.merge(:form => 'opened', :anchor => 'comments_list') )
  36 + end
  37 +
34 end 38 end
app/views/content_viewer/blog_page.rhtml
@@ -2,4 +2,6 @@ @@ -2,4 +2,6 @@
2 2
3 <div><%= article.body %></div> 3 <div><%= article.body %></div>
4 <hr/> 4 <hr/>
5 -<%= (children.compact.empty? ? content_tag('em', _('(no posts)')) : list_posts(user, children)) %> 5 +<div class="blog-posts">
  6 + <%= (children.compact.empty? ? content_tag('em', _('(no posts)')) : list_posts(user, children)) %>
  7 +</div>
app/views/content_viewer/view_page.rhtml
1 <div id="article"> 1 <div id="article">
  2 +<div id="article-wraper-1">
  3 +<div id="article-wraper-2">
  4 +<div id="article-wraper-3">
  5 +<div id="article-wraper-4">
  6 +<div id="article-wraper-5">
  7 +<div id="article-wraper-6">
  8 +<div id="article-wraper-7">
  9 +<div id="article-wraper-8">
2 10
3 <% 11 <%
4 # AddThis Button 12 # AddThis Button
@@ -107,6 +115,7 @@ @@ -107,6 +115,7 @@
107 <% end %> 115 <% end %>
108 116
109 <div class="comments"> 117 <div class="comments">
  118 + <a name="comments_list"></a>
110 <% if @page.accept_comments? %> 119 <% if @page.accept_comments? %>
111 <h3 <%= 'class="no-comments-yet"' if @comments.size == 0 %>> 120 <h3 <%= 'class="no-comments-yet"' if @comments.size == 0 %>>
112 <%= number_of_comments(@page) %> 121 <%= number_of_comments(@page) %>
@@ -116,4 +125,6 @@ @@ -116,4 +125,6 @@
116 <% end %> 125 <% end %>
117 </div><!-- end class="comments" --> 126 </div><!-- end class="comments" -->
118 127
  128 +</div></div></div></div>
  129 +</div></div></div></div><!-- end id="article-warp-[1-8]" -->
119 </div><!-- end id="article" --> 130 </div><!-- end id="article" -->
app/views/shared/tiny_mce.rhtml
@@ -16,6 +16,7 @@ tinyMCE.init({ @@ -16,6 +16,7 @@ tinyMCE.init({
16 theme_advanced_buttons1 : "print,separator,copy,paste,separator,undo,redo,separator,search,replace,separator,fontsizeselect,formatselect", 16 theme_advanced_buttons1 : "print,separator,copy,paste,separator,undo,redo,separator,search,replace,separator,fontsizeselect,formatselect",
17 theme_advanced_buttons2 : "bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,unlink,image,table,separator,cleanup,code", 17 theme_advanced_buttons2 : "bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,unlink,image,table,separator,cleanup,code",
18 theme_advanced_buttons3 : "", 18 theme_advanced_buttons3 : "",
  19 + theme_advanced_blockformats :"p,address,pre,h2,h3,h4,h5,h6",
19 paste_auto_cleanup_on_paste : true, 20 paste_auto_cleanup_on_paste : true,
20 paste_insert_word_content_callback : "convertWord", 21 paste_insert_word_content_callback : "convertWord",
21 paste_use_dialog: false, 22 paste_use_dialog: false,
test/functional/content_viewer_controller_test.rb
@@ -712,7 +712,7 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase @@ -712,7 +712,7 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
712 a = Blog.create!(:name => 'article folder', :profile => profile) 712 a = Blog.create!(:name => 'article folder', :profile => profile)
713 t = TextileArticle.create!(:name => 'first post', :parent => a, :profile => profile) 713 t = TextileArticle.create!(:name => 'first post', :parent => a, :profile => profile)
714 get :view_page, :profile => profile.identifier, :page => [a.path] 714 get :view_page, :profile => profile.identifier, :page => [a.path]
715 - assert_tag :tag => 'div', :attributes => { :id => "post-#{t.id}" }, :descendant => { :tag => 'a', :content => 'No comments yet', :attributes => { :href => /#{profile.identifier}\/blog\/first-post\?form=opened#comment_form/ } } 715 + assert_tag :tag => 'div', :attributes => { :id => "post-#{t.id}" }, :descendant => { :tag => 'a', :content => 'No comments yet', :attributes => { :href => /#{profile.identifier}\/blog\/first-post\?form=opened#comments_list/ } }
716 end 716 end
717 717
718 should 'hit the article when viewed' do 718 should 'hit the article when viewed' do
test/unit/blog_helper_test.rb
@@ -50,10 +50,8 @@ class BlogHelperTest &lt; Test::Unit::TestCase @@ -50,10 +50,8 @@ class BlogHelperTest &lt; Test::Unit::TestCase
50 blog.children << article = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => blog, :published => true) 50 blog.children << article = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => blog, :published => true)
51 expects(:article_title).with(article).returns('TITLE') 51 expects(:article_title).with(article).returns('TITLE')
52 expects(:content_tag).with('p', article.to_html).returns(' TO_HTML') 52 expects(:content_tag).with('p', article.to_html).returns(' TO_HTML')
53 - expects(:number_of_comments).with(article).returns('NUMBER OF COMMENTS')  
54 - expects(:content_tag).with('p', 'NUMBER OF COMMENTS', anything).returns(' COMMENTS').at_least_once  
55 53
56 - assert_equal 'TITLE TO_HTML COMMENTS', display_post(article) 54 + assert_equal 'TITLE TO_HTML', display_post(article)
57 end 55 end
58 56
59 def will_paginate(arg1, arg2) 57 def will_paginate(arg1, arg2)
test/unit/content_viewer_helper_test.rb
@@ -49,7 +49,7 @@ class ContentViewerHelperTest &lt; Test::Unit::TestCase @@ -49,7 +49,7 @@ class ContentViewerHelperTest &lt; Test::Unit::TestCase
49 article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile) 49 article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile)
50 article.stubs(:url).returns({}) 50 article.stubs(:url).returns({})
51 article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')]) 51 article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')])
52 - result = display_post(article) 52 + result = link_to_comments(article)
53 assert_match /One comment/, result 53 assert_match /One comment/, result
54 end 54 end
55 55