diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 1a3bdf0..c8d2d39 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -129,11 +129,12 @@ class CmsController < MyProfileController redirect_to :action => 'view', :id => @article.id end - post_only :destroy def destroy @article = profile.articles.find(params[:id]) - @article.destroy - redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent + if request.post? + @article.destroy + redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent + end end def why_categorize diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index 8ed1b9c..8d33a49 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -62,6 +62,8 @@ class ContentViewerController < ApplicationController return end + @form_div = params[:form] + if request.post? && params[:comment] && params[self.icaptcha_field].blank? && @page.accept_comments? add_comment end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 626d3e1..849e79e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -719,4 +719,33 @@ module ApplicationHelper environment.top_url(request.ssl?) end + def helper_for_article(article) + article_helper = ActionView::Base.new + article_helper.extend ArticleHelper + begin + class_name = article.class.name + 'Helper' + klass = class_name.constantize + article_helper.extend klass + rescue + end + article_helper + end + + def label_for_new_article(article) + article_helper = helper_for_article(!article.nil? && !article.parent.nil? ? article.parent : article) + article_helper.cms_label_for_new_children + end + + def label_for_edit_article(article) + article_helper = helper_for_article(article) + article_helper.cms_label_for_edit + end + + def meta_tags_for_article(article) + if article and (article.blog? or (article.parent and article.parent.blog?)) + blog = article.blog? ? article : article.parent + "" + end + end + end diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index 8afe0c8..168eefd 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -11,4 +11,12 @@ module ArticleHelper ) end + def cms_label_for_new_children + _('New article') + end + + def cms_label_for_edit + _('Edit') + end + end diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb index 00c113f..754d385 100644 --- a/app/helpers/blog_helper.rb +++ b/app/helpers/blog_helper.rb @@ -6,4 +6,12 @@ module BlogHelper hidden_field_tag('article[accept_comments]', 0) end + def cms_label_for_new_children + _('New post') + end + + def cms_label_for_edit + _('Edit blog') + end + end diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index cb5548b..6d74b4b 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -12,14 +12,7 @@ module CmsHelper attr_reader :environment def options_for_article(article) - article_helper = ActionView::Base.new - article_helper.extend ArticleHelper - begin - class_name = article.class.name + 'Helper' - klass = class_name.constantize - article_helper.extend klass - rescue - end + article_helper = helper_for_article(article) article_helper.custom_options_for_article(article) end diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb index bf12cfb..851de62 100644 --- a/app/helpers/content_viewer_helper.rb +++ b/app/helpers/content_viewer_helper.rb @@ -35,7 +35,7 @@ module ContentViewerHelper def display_post(article) article_title(article) + content_tag('p', article.to_html) + - content_tag('p', link_to( number_of_comments(article), article.url ), :class => 'metadata') + content_tag('p', link_to( number_of_comments(article), article.url.merge(:form => 'opened', :anchor => 'comment_form') ), :class => 'metadata') end def article_to_html(article) diff --git a/app/models/blog_archives_block.rb b/app/models/blog_archives_block.rb index b414469..d2ee2f6 100644 --- a/app/models/blog_archives_block.rb +++ b/app/models/blog_archives_block.rb @@ -3,6 +3,7 @@ class BlogArchivesBlock < Block include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelper include ActionController::UrlWriter + include ActionView::Helpers::AssetTagHelper def self.description _('List posts of your blog') @@ -25,7 +26,8 @@ class BlogArchivesBlock < Block results << "" end block_title(title) + - content_tag('ul', results, :class => 'blog-archives') + content_tag('ul', results, :class => 'blog-archives') + + content_tag('div', link_to(_('Subscribe RSS Feed'), owner.blog.feed.url), :class => 'subscribe-feed') end end diff --git a/app/views/cms/_blog.rhtml b/app/views/cms/_blog.rhtml index 4d367e2..1e4f6ea 100644 --- a/app/views/cms/_blog.rhtml +++ b/app/views/cms/_blog.rhtml @@ -4,18 +4,14 @@ <%= f.text_field('title', :size => '64') %> -<%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64)) %> +<%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64, :rows => 10)) %> -

<%= _('Settings') %>

- -<%= f.text_field('posts_per_page') %> - -
<%= _('Feed options') %>
+<%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, [5, 10, 20, 50, 100])) %> <% fields_for 'article[feed]', @article.feed do |feed| %> -<%= labelled_form_field(_('Limit of articles'), feed.text_field(:limit)) %> +<%= labelled_form_field(_('Limit of posts in RSS Feed'), feed.select(:limit, ['5', '10', '20', '50'])) %> -<%= labelled_form_field(_('Use as item description:'), feed.select(:feed_item_description, [ [ _('Article abstract'), 'abstract'], [ _('Article body'), 'body']])) %> +<%= labelled_form_field(_('Use as description in RSS Feed:'), feed.select(:feed_item_description, [ [ _('Article abstract'), 'abstract'], [ _('Article body'), 'body']])) %> <% end %> diff --git a/app/views/cms/view.rhtml b/app/views/cms/view.rhtml index 8585035..da78c83 100644 --- a/app/views/cms/view.rhtml +++ b/app/views/cms/view.rhtml @@ -22,7 +22,7 @@ <% if !@article or !@article.blog? %> <%= button :add, _('New folder'), :action => 'new', :type => 'Folder', :parent_id => parent_id %> <% end %> - <%= lightbox_button('new', _('New article'), :action => 'new', :parent_id => parent_id) %> + <%= lightbox_button('new', label_for_new_article(@article), :action => 'new', :parent_id => parent_id) %> <% end %> diff --git a/app/views/content_viewer/_comment_form.rhtml b/app/views/content_viewer/_comment_form.rhtml index ff7f97e..081071b 100644 --- a/app/views/content_viewer/_comment_form.rhtml +++ b/app/views/content_viewer/_comment_form.rhtml @@ -15,7 +15,7 @@ f.commit.focus(); f['comment[<%= focus_on %>]'].focus(); this.onclick=null"> -

<%= _('Post a comment') %>

+

<%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %>

<% form_tag( @page.url, { :id => comment_form_id } ) do %> diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index bfce2ac..79b524f 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -32,15 +32,18 @@ <% if logged_in? && current_user.person.has_permission?('post_content', profile) %> <% end %> diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index 2801840..5df0a84 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -11,7 +11,7 @@ - + <%= meta_tags_for_article(@page) if @controller.controller_name == 'content_viewer' %> <%= javascript_include_tag 'default-config' %> <%= javascript_include_tag :defaults %> <%# javascript_include_tag 'animator' %> diff --git a/public/stylesheets/blocks/blog-archives-block.css b/public/stylesheets/blocks/blog-archives-block.css index 114964f..7ab86ae 100644 --- a/public/stylesheets/blocks/blog-archives-block.css +++ b/public/stylesheets/blocks/blog-archives-block.css @@ -15,3 +15,8 @@ .blog-archives-block a { text-decoration: none; } + +.blog-archives-block .subscribe-feed { + padding: 5px 0px 10px 10px; + font-size: small; +} diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 467304b..a0d4b17 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -642,7 +642,7 @@ class CmsControllerTest < Test::Unit::TestCase should 'display posts per page input with default value on edit blog' do get :new, :profile => profile.identifier, :type => 'Blog' - assert_tag :tag => 'input', :attributes => { :name => 'article[posts_per_page]', :type => 'text', :value => '20' } + assert_tag :tag => 'select', :attributes => { :name => 'article[posts_per_page]' }, :child => { :tag => 'option', :attributes => {:value => '20', :selected => 'selected'} } end should 'not offer to create special article types' do @@ -725,4 +725,25 @@ class CmsControllerTest < Test::Unit::TestCase assert_tag :tag => 'input', :attributes => { :name => 'article[title]', :type => 'text' } end + should "display 'New article' when create children of folder" do + a = Folder.new(:name => 'article folder'); profile.articles << a; a.save! + Article.stubs(:short_description).returns('bli') + get :view, :profile => profile.identifier, :id => a + assert_tag :tag => 'a', :content => 'New article' + end + + should "display 'New post' when create children of blog" do + a = Blog.create!(:name => 'blog_for_test', :profile => profile) + Article.stubs(:short_description).returns('bli') + get :view, :profile => profile.identifier, :id => a + assert_tag :tag => 'a', :content => 'New post' + end + + should 'offer confirmation to remove article' do + a = profile.articles.create!(:name => 'my-article') + get :destroy, :profile => profile.identifier, :id => a.id + assert_response :success + assert_tag :tag => 'input', :attributes => {:type => 'submit', :value => 'Yes, I want.' } + end + end diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 238ad2b..5236f51 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -564,4 +564,59 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => "/myprofile/testinguser/cms/new?parent_id=#{folder.id}" } } end + should "display 'New article' when create children of folder" do + login_as(profile.identifier) + a = Folder.new(:name => 'article folder'); profile.articles << a; a.save! + Article.stubs(:short_description).returns('bli') + get :view_page, :profile => profile.identifier, :page => [a.path] + assert_tag :tag => 'a', :content => 'New article' + end + + should "display 'New post' when create children of blog" do + login_as(profile.identifier) + a = Blog.create!(:name => 'article folder', :profile => profile) + Article.stubs(:short_description).returns('bli') + get :view_page, :profile => profile.identifier, :page => [a.path] + assert_tag :tag => 'a', :content => 'New post' + end + + should "display same label for new article button of parent" do + login_as(profile.identifier) + a = Blog.create!(:name => 'article folder', :profile => profile) + Article.stubs(:short_description).returns('bli') + t = TextileArticle.create!(:name => 'first post', :parent => a, :profile => profile) + get :view_page, :profile => profile.identifier, :page => [t.path] + assert_tag :tag => 'a', :content => 'New post' + end + + should 'display button to remove article' do + login_as(profile.identifier) + t = TextileArticle.create!(:name => 'article to destroy', :profile => profile) + get :view_page, :profile => profile.identifier, :page => [t.path] + assert_tag :tag => 'a', :content => 'Delete', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/destroy/#{t.id}"} + end + + should 'add meta tag to rss feed on view blog' do + login_as(profile.identifier) + a = Blog.create!(:name => 'article folder', :profile => profile) + get :view_page, :profile => profile.identifier, :page => [a.path] + assert_tag :tag => 'link', :attributes => { :rel => 'alternate', :type => 'application/rss+xml', :title => 'feed', :href => /\/#{profile.identifier}\/blog\/feed/} + end + + should 'add meta tag to rss feed on view post blog' do + login_as(profile.identifier) + a = Blog.create!(:name => 'article folder', :profile => profile) + t = TextileArticle.create!(:name => 'first post', :parent => a, :profile => profile) + get :view_page, :profile => profile.identifier, :page => [t.path] + assert_tag :tag => 'link', :attributes => { :rel => 'alternate', :type => 'application/rss+xml', :title => 'feed', :href => /\/#{profile.identifier}\/blog\/feed/} + end + + should 'link to post with comment form opened' do + login_as(profile.identifier) + a = Blog.create!(:name => 'article folder', :profile => profile) + t = TextileArticle.create!(:name => 'first post', :parent => a, :profile => profile) + get :view_page, :profile => profile.identifier, :page => [a.path] + 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/ } } + end + end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 8d63c3a..841be9d 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -225,8 +225,17 @@ class ApplicationHelperTest < Test::Unit::TestCase assert_nil select_categories(mock) end + should 'create rss feed link to blog' do + p = create_user('testuser').person + b = Blog.create!(:profile => p, :name => 'blog_feed_test') + assert_tag_in_string meta_tags_for_article(b), :tag => 'link', :attributes => {:type => 'application/rss+xml', :title => 'feed'} + end + protected + def url_for(args = {}) + args + end def content_tag(tag, content, options = {}) content.strip end diff --git a/test/unit/cms_helper_test.rb b/test/unit/cms_helper_test.rb index 5142057..162c658 100644 --- a/test/unit/cms_helper_test.rb +++ b/test/unit/cms_helper_test.rb @@ -4,6 +4,7 @@ class CmsHelperTest < Test::Unit::TestCase include CmsHelper include BlogHelper + include ApplicationHelper should 'show default options for article' do result = options_for_article(RssFeed.new) diff --git a/test/unit/content_viewer_helper_test.rb b/test/unit/content_viewer_helper_test.rb index f9ef754..e4b64ec 100644 --- a/test/unit/content_viewer_helper_test.rb +++ b/test/unit/content_viewer_helper_test.rb @@ -46,7 +46,7 @@ class ContentViewerHelperTest < Test::Unit::TestCase should 'count total of comments from post' do article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile) - article.stubs(:url).returns('') + article.stubs(:url).returns({}) article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')]) result = display_post(article) assert_match /One comment/, result -- libgit2 0.21.2