Commit 974f333d0fc73c9f9d002d3e711cb93b239138ba
Committed by
Antonio Terceiro
1 parent
4b393886
Exists in
master
and in
29 other branches
ActionItem806: some enhancements in blog
- display comment form opened - links to subscribe rss feed - show 'Edit blog' on view blog - display button to remove article when view - use select box instead of text fields to blog configuration - decreasing size of the field description - use 'New post' instead of 'New article'
Showing
19 changed files
with
161 additions
and
28 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -129,11 +129,12 @@ class CmsController < MyProfileController | @@ -129,11 +129,12 @@ class CmsController < MyProfileController | ||
129 | redirect_to :action => 'view', :id => @article.id | 129 | redirect_to :action => 'view', :id => @article.id |
130 | end | 130 | end |
131 | 131 | ||
132 | - post_only :destroy | ||
133 | def destroy | 132 | def destroy |
134 | @article = profile.articles.find(params[:id]) | 133 | @article = profile.articles.find(params[:id]) |
135 | - @article.destroy | ||
136 | - redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent | 134 | + if request.post? |
135 | + @article.destroy | ||
136 | + redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent | ||
137 | + end | ||
137 | end | 138 | end |
138 | 139 | ||
139 | def why_categorize | 140 | def why_categorize |
app/controllers/public/content_viewer_controller.rb
@@ -62,6 +62,8 @@ class ContentViewerController < ApplicationController | @@ -62,6 +62,8 @@ class ContentViewerController < ApplicationController | ||
62 | return | 62 | return |
63 | end | 63 | end |
64 | 64 | ||
65 | + @form_div = params[:form] | ||
66 | + | ||
65 | if request.post? && params[:comment] && params[self.icaptcha_field].blank? && @page.accept_comments? | 67 | if request.post? && params[:comment] && params[self.icaptcha_field].blank? && @page.accept_comments? |
66 | add_comment | 68 | add_comment |
67 | end | 69 | end |
app/helpers/application_helper.rb
@@ -719,4 +719,33 @@ module ApplicationHelper | @@ -719,4 +719,33 @@ module ApplicationHelper | ||
719 | environment.top_url(request.ssl?) | 719 | environment.top_url(request.ssl?) |
720 | end | 720 | end |
721 | 721 | ||
722 | + def helper_for_article(article) | ||
723 | + article_helper = ActionView::Base.new | ||
724 | + article_helper.extend ArticleHelper | ||
725 | + begin | ||
726 | + class_name = article.class.name + 'Helper' | ||
727 | + klass = class_name.constantize | ||
728 | + article_helper.extend klass | ||
729 | + rescue | ||
730 | + end | ||
731 | + article_helper | ||
732 | + end | ||
733 | + | ||
734 | + def label_for_new_article(article) | ||
735 | + article_helper = helper_for_article(!article.nil? && !article.parent.nil? ? article.parent : article) | ||
736 | + article_helper.cms_label_for_new_children | ||
737 | + end | ||
738 | + | ||
739 | + def label_for_edit_article(article) | ||
740 | + article_helper = helper_for_article(article) | ||
741 | + article_helper.cms_label_for_edit | ||
742 | + end | ||
743 | + | ||
744 | + def meta_tags_for_article(article) | ||
745 | + if article and (article.blog? or (article.parent and article.parent.blog?)) | ||
746 | + blog = article.blog? ? article : article.parent | ||
747 | + "<link rel='alternate' type='application/rss+xml' title='#{blog.feed.title}' href='#{url_for blog.feed.url}' />" | ||
748 | + end | ||
749 | + end | ||
750 | + | ||
722 | end | 751 | end |
app/helpers/article_helper.rb
app/helpers/blog_helper.rb
@@ -6,4 +6,12 @@ module BlogHelper | @@ -6,4 +6,12 @@ module BlogHelper | ||
6 | hidden_field_tag('article[accept_comments]', 0) | 6 | hidden_field_tag('article[accept_comments]', 0) |
7 | end | 7 | end |
8 | 8 | ||
9 | + def cms_label_for_new_children | ||
10 | + _('New post') | ||
11 | + end | ||
12 | + | ||
13 | + def cms_label_for_edit | ||
14 | + _('Edit blog') | ||
15 | + end | ||
16 | + | ||
9 | end | 17 | end |
app/helpers/cms_helper.rb
@@ -12,14 +12,7 @@ module CmsHelper | @@ -12,14 +12,7 @@ module CmsHelper | ||
12 | attr_reader :environment | 12 | attr_reader :environment |
13 | 13 | ||
14 | def options_for_article(article) | 14 | def options_for_article(article) |
15 | - article_helper = ActionView::Base.new | ||
16 | - article_helper.extend ArticleHelper | ||
17 | - begin | ||
18 | - class_name = article.class.name + 'Helper' | ||
19 | - klass = class_name.constantize | ||
20 | - article_helper.extend klass | ||
21 | - rescue | ||
22 | - end | 15 | + article_helper = helper_for_article(article) |
23 | article_helper.custom_options_for_article(article) | 16 | article_helper.custom_options_for_article(article) |
24 | end | 17 | end |
25 | 18 |
app/helpers/content_viewer_helper.rb
@@ -35,7 +35,7 @@ module ContentViewerHelper | @@ -35,7 +35,7 @@ module ContentViewerHelper | ||
35 | 35 | ||
36 | def display_post(article) | 36 | def display_post(article) |
37 | article_title(article) + content_tag('p', article.to_html) + | 37 | article_title(article) + content_tag('p', article.to_html) + |
38 | - content_tag('p', link_to( number_of_comments(article), article.url ), :class => 'metadata') | 38 | + content_tag('p', link_to( number_of_comments(article), article.url.merge(:form => 'opened', :anchor => 'comment_form') ), :class => 'metadata') |
39 | end | 39 | end |
40 | 40 | ||
41 | def article_to_html(article) | 41 | def article_to_html(article) |
app/models/blog_archives_block.rb
@@ -3,6 +3,7 @@ class BlogArchivesBlock < Block | @@ -3,6 +3,7 @@ class BlogArchivesBlock < Block | ||
3 | include ActionView::Helpers::TagHelper | 3 | include ActionView::Helpers::TagHelper |
4 | include ActionView::Helpers::UrlHelper | 4 | include ActionView::Helpers::UrlHelper |
5 | include ActionController::UrlWriter | 5 | include ActionController::UrlWriter |
6 | + include ActionView::Helpers::AssetTagHelper | ||
6 | 7 | ||
7 | def self.description | 8 | def self.description |
8 | _('List posts of your blog') | 9 | _('List posts of your blog') |
@@ -25,7 +26,8 @@ class BlogArchivesBlock < Block | @@ -25,7 +26,8 @@ class BlogArchivesBlock < Block | ||
25 | results << "</ul>" | 26 | results << "</ul>" |
26 | end | 27 | end |
27 | block_title(title) + | 28 | block_title(title) + |
28 | - content_tag('ul', results, :class => 'blog-archives') | 29 | + content_tag('ul', results, :class => 'blog-archives') + |
30 | + content_tag('div', link_to(_('Subscribe RSS Feed'), owner.blog.feed.url), :class => 'subscribe-feed') | ||
29 | end | 31 | end |
30 | 32 | ||
31 | end | 33 | end |
app/views/cms/_blog.rhtml
@@ -4,18 +4,14 @@ | @@ -4,18 +4,14 @@ | ||
4 | 4 | ||
5 | <%= f.text_field('title', :size => '64') %> | 5 | <%= f.text_field('title', :size => '64') %> |
6 | 6 | ||
7 | -<%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64)) %> | 7 | +<%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64, :rows => 10)) %> |
8 | 8 | ||
9 | -<h4><%= _('Settings') %></h4> | ||
10 | - | ||
11 | -<%= f.text_field('posts_per_page') %> | ||
12 | - | ||
13 | -<h5><%= _('Feed options') %></h5> | 9 | +<%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, [5, 10, 20, 50, 100])) %> |
14 | 10 | ||
15 | <% fields_for 'article[feed]', @article.feed do |feed| %> | 11 | <% fields_for 'article[feed]', @article.feed do |feed| %> |
16 | 12 | ||
17 | -<%= labelled_form_field(_('Limit of articles'), feed.text_field(:limit)) %> | 13 | +<%= labelled_form_field(_('Limit of posts in RSS Feed'), feed.select(:limit, ['5', '10', '20', '50'])) %> |
18 | 14 | ||
19 | -<%= labelled_form_field(_('Use as item description:'), feed.select(:feed_item_description, [ [ _('Article abstract'), 'abstract'], [ _('Article body'), 'body']])) %> | 15 | +<%= labelled_form_field(_('Use as description in RSS Feed:'), feed.select(:feed_item_description, [ [ _('Article abstract'), 'abstract'], [ _('Article body'), 'body']])) %> |
20 | 16 | ||
21 | <% end %> | 17 | <% end %> |
app/views/cms/view.rhtml
@@ -22,7 +22,7 @@ | @@ -22,7 +22,7 @@ | ||
22 | <% if !@article or !@article.blog? %> | 22 | <% if !@article or !@article.blog? %> |
23 | <%= button :add, _('New folder'), :action => 'new', :type => 'Folder', :parent_id => parent_id %> | 23 | <%= button :add, _('New folder'), :action => 'new', :type => 'Folder', :parent_id => parent_id %> |
24 | <% end %> | 24 | <% end %> |
25 | - <%= lightbox_button('new', _('New article'), :action => 'new', :parent_id => parent_id) %> | 25 | + <%= lightbox_button('new', label_for_new_article(@article), :action => 'new', :parent_id => parent_id) %> |
26 | <% end %> | 26 | <% end %> |
27 | 27 | ||
28 | <table class='cms-articles'> | 28 | <table class='cms-articles'> |
app/views/content_viewer/_comment_form.rhtml
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | f.commit.focus(); f['comment[<%= focus_on %>]'].focus(); | 15 | f.commit.focus(); f['comment[<%= focus_on %>]'].focus(); |
16 | this.onclick=null"> | 16 | this.onclick=null"> |
17 | 17 | ||
18 | -<h4><%= _('Post a comment') %></h4> | 18 | +<h4><%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %></h4> |
19 | 19 | ||
20 | <% form_tag( @page.url, { :id => comment_form_id } ) do %> | 20 | <% form_tag( @page.url, { :id => comment_form_id } ) do %> |
21 | 21 |
app/views/content_viewer/view_page.rhtml
@@ -32,15 +32,18 @@ | @@ -32,15 +32,18 @@ | ||
32 | </script> | 32 | </script> |
33 | <% if logged_in? && current_user.person.has_permission?('post_content', profile) %> | 33 | <% if logged_in? && current_user.person.has_permission?('post_content', profile) %> |
34 | <div id="article-actions" class="hidden"> | 34 | <div id="article-actions" class="hidden"> |
35 | - <%= link_to content_tag( 'span', _('Edit') ), | 35 | + <%= link_to content_tag( 'span', label_for_edit_article(@page) ), |
36 | { :controller => 'cms', :action => 'edit', :id => @page }, | 36 | { :controller => 'cms', :action => 'edit', :id => @page }, |
37 | :class => 'button with-text icon-edit' %> | 37 | :class => 'button with-text icon-edit' %> |
38 | + <%= link_to content_tag( 'span', _('Delete') ), | ||
39 | + { :controller => 'cms', :action => 'destroy', :id => @page }, | ||
40 | + :class => 'button with-text icon-delete' %> | ||
38 | <% if profile.kind_of?(Person) %> | 41 | <% if profile.kind_of?(Person) %> |
39 | <%= link_to content_tag( 'span', _('Spread this') ), | 42 | <%= link_to content_tag( 'span', _('Spread this') ), |
40 | { :controller => 'cms', :action => 'publish', :id => @page }, | 43 | { :controller => 'cms', :action => 'publish', :id => @page }, |
41 | :class => 'button with-text icon-spread' %> | 44 | :class => 'button with-text icon-spread' %> |
42 | <% end %> | 45 | <% end %> |
43 | - <%= lightbox_button(:new, _('New publication'), :controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent))) %> | 46 | + <%= lightbox_button(:new, label_for_new_article(@page), :controller => 'cms', :action => 'new', :parent_id => (@page.folder? ? @page : (@page.parent.nil? ? nil : @page.parent))) %> |
44 | </div> | 47 | </div> |
45 | <% end %> | 48 | <% end %> |
46 | </div> | 49 | </div> |
app/views/layouts/application.rhtml
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | <meta name="description" content="FIXME: Descriptions of Noosfero" /> | 11 | <meta name="description" content="FIXME: Descriptions of Noosfero" /> |
12 | <meta name="keywords" content="Noosfero, Community, Open Source" /> | 12 | <meta name="keywords" content="Noosfero, Community, Open Source" /> |
13 | <link rel="shortcut icon" href="<%= '/designs/themes/' + current_theme + '/images/favicon.ico' %>" type="image/x-icon" /> | 13 | <link rel="shortcut icon" href="<%= '/designs/themes/' + current_theme + '/images/favicon.ico' %>" type="image/x-icon" /> |
14 | - | 14 | + <%= meta_tags_for_article(@page) if @controller.controller_name == 'content_viewer' %> |
15 | <%= javascript_include_tag 'default-config' %> | 15 | <%= javascript_include_tag 'default-config' %> |
16 | <%= javascript_include_tag :defaults %> | 16 | <%= javascript_include_tag :defaults %> |
17 | <%# javascript_include_tag 'animator' %> | 17 | <%# javascript_include_tag 'animator' %> |
public/stylesheets/blocks/blog-archives-block.css
test/functional/cms_controller_test.rb
@@ -642,7 +642,7 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -642,7 +642,7 @@ class CmsControllerTest < Test::Unit::TestCase | ||
642 | 642 | ||
643 | should 'display posts per page input with default value on edit blog' do | 643 | should 'display posts per page input with default value on edit blog' do |
644 | get :new, :profile => profile.identifier, :type => 'Blog' | 644 | get :new, :profile => profile.identifier, :type => 'Blog' |
645 | - assert_tag :tag => 'input', :attributes => { :name => 'article[posts_per_page]', :type => 'text', :value => '20' } | 645 | + assert_tag :tag => 'select', :attributes => { :name => 'article[posts_per_page]' }, :child => { :tag => 'option', :attributes => {:value => '20', :selected => 'selected'} } |
646 | end | 646 | end |
647 | 647 | ||
648 | should 'not offer to create special article types' do | 648 | should 'not offer to create special article types' do |
@@ -725,4 +725,25 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -725,4 +725,25 @@ class CmsControllerTest < Test::Unit::TestCase | ||
725 | assert_tag :tag => 'input', :attributes => { :name => 'article[title]', :type => 'text' } | 725 | assert_tag :tag => 'input', :attributes => { :name => 'article[title]', :type => 'text' } |
726 | end | 726 | end |
727 | 727 | ||
728 | + should "display 'New article' when create children of folder" do | ||
729 | + a = Folder.new(:name => 'article folder'); profile.articles << a; a.save! | ||
730 | + Article.stubs(:short_description).returns('bli') | ||
731 | + get :view, :profile => profile.identifier, :id => a | ||
732 | + assert_tag :tag => 'a', :content => 'New article' | ||
733 | + end | ||
734 | + | ||
735 | + should "display 'New post' when create children of blog" do | ||
736 | + a = Blog.create!(:name => 'blog_for_test', :profile => profile) | ||
737 | + Article.stubs(:short_description).returns('bli') | ||
738 | + get :view, :profile => profile.identifier, :id => a | ||
739 | + assert_tag :tag => 'a', :content => 'New post' | ||
740 | + end | ||
741 | + | ||
742 | + should 'offer confirmation to remove article' do | ||
743 | + a = profile.articles.create!(:name => 'my-article') | ||
744 | + get :destroy, :profile => profile.identifier, :id => a.id | ||
745 | + assert_response :success | ||
746 | + assert_tag :tag => 'input', :attributes => {:type => 'submit', :value => 'Yes, I want.' } | ||
747 | + end | ||
748 | + | ||
728 | end | 749 | end |
test/functional/content_viewer_controller_test.rb
@@ -564,4 +564,59 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -564,4 +564,59 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
564 | assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/new?parent_id=#{folder.id}" } } | 564 | assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/new?parent_id=#{folder.id}" } } |
565 | end | 565 | end |
566 | 566 | ||
567 | + should "display 'New article' when create children of folder" do | ||
568 | + login_as(profile.identifier) | ||
569 | + a = Folder.new(:name => 'article folder'); profile.articles << a; a.save! | ||
570 | + Article.stubs(:short_description).returns('bli') | ||
571 | + get :view_page, :profile => profile.identifier, :page => [a.path] | ||
572 | + assert_tag :tag => 'a', :content => 'New article' | ||
573 | + end | ||
574 | + | ||
575 | + should "display 'New post' when create children of blog" do | ||
576 | + login_as(profile.identifier) | ||
577 | + a = Blog.create!(:name => 'article folder', :profile => profile) | ||
578 | + Article.stubs(:short_description).returns('bli') | ||
579 | + get :view_page, :profile => profile.identifier, :page => [a.path] | ||
580 | + assert_tag :tag => 'a', :content => 'New post' | ||
581 | + end | ||
582 | + | ||
583 | + should "display same label for new article button of parent" do | ||
584 | + login_as(profile.identifier) | ||
585 | + a = Blog.create!(:name => 'article folder', :profile => profile) | ||
586 | + Article.stubs(:short_description).returns('bli') | ||
587 | + t = TextileArticle.create!(:name => 'first post', :parent => a, :profile => profile) | ||
588 | + get :view_page, :profile => profile.identifier, :page => [t.path] | ||
589 | + assert_tag :tag => 'a', :content => 'New post' | ||
590 | + end | ||
591 | + | ||
592 | + should 'display button to remove article' do | ||
593 | + login_as(profile.identifier) | ||
594 | + t = TextileArticle.create!(:name => 'article to destroy', :profile => profile) | ||
595 | + get :view_page, :profile => profile.identifier, :page => [t.path] | ||
596 | + assert_tag :tag => 'a', :content => 'Delete', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/destroy/#{t.id}"} | ||
597 | + end | ||
598 | + | ||
599 | + should 'add meta tag to rss feed on view blog' do | ||
600 | + login_as(profile.identifier) | ||
601 | + a = Blog.create!(:name => 'article folder', :profile => profile) | ||
602 | + get :view_page, :profile => profile.identifier, :page => [a.path] | ||
603 | + assert_tag :tag => 'link', :attributes => { :rel => 'alternate', :type => 'application/rss+xml', :title => 'feed', :href => /\/#{profile.identifier}\/blog\/feed/} | ||
604 | + end | ||
605 | + | ||
606 | + should 'add meta tag to rss feed on view post blog' do | ||
607 | + login_as(profile.identifier) | ||
608 | + a = Blog.create!(:name => 'article folder', :profile => profile) | ||
609 | + t = TextileArticle.create!(:name => 'first post', :parent => a, :profile => profile) | ||
610 | + get :view_page, :profile => profile.identifier, :page => [t.path] | ||
611 | + assert_tag :tag => 'link', :attributes => { :rel => 'alternate', :type => 'application/rss+xml', :title => 'feed', :href => /\/#{profile.identifier}\/blog\/feed/} | ||
612 | + end | ||
613 | + | ||
614 | + should 'link to post with comment form opened' do | ||
615 | + login_as(profile.identifier) | ||
616 | + a = Blog.create!(:name => 'article folder', :profile => profile) | ||
617 | + t = TextileArticle.create!(:name => 'first post', :parent => a, :profile => profile) | ||
618 | + get :view_page, :profile => profile.identifier, :page => [a.path] | ||
619 | + 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/ } } | ||
620 | + end | ||
621 | + | ||
567 | end | 622 | end |
test/unit/application_helper_test.rb
@@ -225,8 +225,17 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -225,8 +225,17 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
225 | assert_nil select_categories(mock) | 225 | assert_nil select_categories(mock) |
226 | end | 226 | end |
227 | 227 | ||
228 | + should 'create rss feed link to blog' do | ||
229 | + p = create_user('testuser').person | ||
230 | + b = Blog.create!(:profile => p, :name => 'blog_feed_test') | ||
231 | + assert_tag_in_string meta_tags_for_article(b), :tag => 'link', :attributes => {:type => 'application/rss+xml', :title => 'feed'} | ||
232 | + end | ||
233 | + | ||
228 | protected | 234 | protected |
229 | 235 | ||
236 | + def url_for(args = {}) | ||
237 | + args | ||
238 | + end | ||
230 | def content_tag(tag, content, options = {}) | 239 | def content_tag(tag, content, options = {}) |
231 | content.strip | 240 | content.strip |
232 | end | 241 | end |
test/unit/cms_helper_test.rb
@@ -4,6 +4,7 @@ class CmsHelperTest < Test::Unit::TestCase | @@ -4,6 +4,7 @@ class CmsHelperTest < Test::Unit::TestCase | ||
4 | 4 | ||
5 | include CmsHelper | 5 | include CmsHelper |
6 | include BlogHelper | 6 | include BlogHelper |
7 | + include ApplicationHelper | ||
7 | 8 | ||
8 | should 'show default options for article' do | 9 | should 'show default options for article' do |
9 | result = options_for_article(RssFeed.new) | 10 | result = options_for_article(RssFeed.new) |
test/unit/content_viewer_helper_test.rb
@@ -46,7 +46,7 @@ class ContentViewerHelperTest < Test::Unit::TestCase | @@ -46,7 +46,7 @@ class ContentViewerHelperTest < Test::Unit::TestCase | ||
46 | 46 | ||
47 | should 'count total of comments from post' do | 47 | should 'count total of comments from post' do |
48 | article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile) | 48 | article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile) |
49 | - article.stubs(:url).returns('') | 49 | + article.stubs(:url).returns({}) |
50 | article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')]) | 50 | article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')]) |
51 | result = display_post(article) | 51 | result = display_post(article) |
52 | assert_match /One comment/, result | 52 | assert_match /One comment/, result |