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 | 129 | redirect_to :action => 'view', :id => @article.id |
130 | 130 | end |
131 | 131 | |
132 | - post_only :destroy | |
133 | 132 | def destroy |
134 | 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 | 138 | end |
138 | 139 | |
139 | 140 | def why_categorize | ... | ... |
app/controllers/public/content_viewer_controller.rb
app/helpers/application_helper.rb
... | ... | @@ -719,4 +719,33 @@ module ApplicationHelper |
719 | 719 | environment.top_url(request.ssl?) |
720 | 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 | 751 | end | ... | ... |
app/helpers/article_helper.rb
app/helpers/blog_helper.rb
app/helpers/cms_helper.rb
... | ... | @@ -12,14 +12,7 @@ module CmsHelper |
12 | 12 | attr_reader :environment |
13 | 13 | |
14 | 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 | 16 | article_helper.custom_options_for_article(article) |
24 | 17 | end |
25 | 18 | ... | ... |
app/helpers/content_viewer_helper.rb
... | ... | @@ -35,7 +35,7 @@ module ContentViewerHelper |
35 | 35 | |
36 | 36 | def display_post(article) |
37 | 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 | 39 | end |
40 | 40 | |
41 | 41 | def article_to_html(article) | ... | ... |
app/models/blog_archives_block.rb
... | ... | @@ -3,6 +3,7 @@ class BlogArchivesBlock < Block |
3 | 3 | include ActionView::Helpers::TagHelper |
4 | 4 | include ActionView::Helpers::UrlHelper |
5 | 5 | include ActionController::UrlWriter |
6 | + include ActionView::Helpers::AssetTagHelper | |
6 | 7 | |
7 | 8 | def self.description |
8 | 9 | _('List posts of your blog') |
... | ... | @@ -25,7 +26,8 @@ class BlogArchivesBlock < Block |
25 | 26 | results << "</ul>" |
26 | 27 | end |
27 | 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 | 31 | end |
30 | 32 | |
31 | 33 | end | ... | ... |
app/views/cms/_blog.rhtml
... | ... | @@ -4,18 +4,14 @@ |
4 | 4 | |
5 | 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 | 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 | 17 | <% end %> | ... | ... |
app/views/cms/view.rhtml
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | <% if !@article or !@article.blog? %> |
23 | 23 | <%= button :add, _('New folder'), :action => 'new', :type => 'Folder', :parent_id => parent_id %> |
24 | 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 | 26 | <% end %> |
27 | 27 | |
28 | 28 | <table class='cms-articles'> | ... | ... |
app/views/content_viewer/_comment_form.rhtml
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | f.commit.focus(); f['comment[<%= focus_on %>]'].focus(); |
16 | 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 | 20 | <% form_tag( @page.url, { :id => comment_form_id } ) do %> |
21 | 21 | ... | ... |
app/views/content_viewer/view_page.rhtml
... | ... | @@ -32,15 +32,18 @@ |
32 | 32 | </script> |
33 | 33 | <% if logged_in? && current_user.person.has_permission?('post_content', profile) %> |
34 | 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 | 36 | { :controller => 'cms', :action => 'edit', :id => @page }, |
37 | 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 | 41 | <% if profile.kind_of?(Person) %> |
39 | 42 | <%= link_to content_tag( 'span', _('Spread this') ), |
40 | 43 | { :controller => 'cms', :action => 'publish', :id => @page }, |
41 | 44 | :class => 'button with-text icon-spread' %> |
42 | 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 | 47 | </div> |
45 | 48 | <% end %> |
46 | 49 | </div> | ... | ... |
app/views/layouts/application.rhtml
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | <meta name="description" content="FIXME: Descriptions of Noosfero" /> |
12 | 12 | <meta name="keywords" content="Noosfero, Community, Open Source" /> |
13 | 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 | 15 | <%= javascript_include_tag 'default-config' %> |
16 | 16 | <%= javascript_include_tag :defaults %> |
17 | 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 | 642 | |
643 | 643 | should 'display posts per page input with default value on edit blog' do |
644 | 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 | 646 | end |
647 | 647 | |
648 | 648 | should 'not offer to create special article types' do |
... | ... | @@ -725,4 +725,25 @@ class CmsControllerTest < Test::Unit::TestCase |
725 | 725 | assert_tag :tag => 'input', :attributes => { :name => 'article[title]', :type => 'text' } |
726 | 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 | 749 | end | ... | ... |
test/functional/content_viewer_controller_test.rb
... | ... | @@ -564,4 +564,59 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
564 | 564 | assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/new?parent_id=#{folder.id}" } } |
565 | 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 | 622 | end | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -225,8 +225,17 @@ class ApplicationHelperTest < Test::Unit::TestCase |
225 | 225 | assert_nil select_categories(mock) |
226 | 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 | 234 | protected |
229 | 235 | |
236 | + def url_for(args = {}) | |
237 | + args | |
238 | + end | |
230 | 239 | def content_tag(tag, content, options = {}) |
231 | 240 | content.strip |
232 | 241 | end | ... | ... |
test/unit/cms_helper_test.rb
test/unit/content_viewer_helper_test.rb
... | ... | @@ -46,7 +46,7 @@ class ContentViewerHelperTest < Test::Unit::TestCase |
46 | 46 | |
47 | 47 | should 'count total of comments from post' do |
48 | 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 | 50 | article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')]) |
51 | 51 | result = display_post(article) |
52 | 52 | assert_match /One comment/, result | ... | ... |