From 27b7acbcb2ad57c0284ed8cb7b4a0201eec62139 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 3 May 2016 16:39:48 -0300 Subject: [PATCH] comment_paragraph: add discussion content type --- plugins/comment_paragraph/lib/comment_paragraph_plugin.rb | 4 ++++ plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion.rb | 26 ++++++++++++++++++++++++++ plugins/comment_paragraph/test/unit/discussion_test.rb | 31 +++++++++++++++++++++++++++++++ plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb | 13 +++++++++++++ 4 files changed, 74 insertions(+), 0 deletions(-) create mode 100644 plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion.rb create mode 100644 plugins/comment_paragraph/test/unit/discussion_test.rb create mode 100644 plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb diff --git a/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb b/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb index 56c4688..87e24f6 100644 --- a/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb +++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin.rb @@ -59,6 +59,10 @@ class CommentParagraphPlugin < Noosfero::Plugin [CommentParagraphPlugin::API] end + def content_types + [CommentParagraphPlugin::Discussion] + end + end require_dependency 'comment_paragraph_plugin/macros/allow_comment' diff --git a/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion.rb b/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion.rb new file mode 100644 index 0000000..58bf799 --- /dev/null +++ b/plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion.rb @@ -0,0 +1,26 @@ +class CommentParagraphPlugin::Discussion < Event + + def self.type_name + _('Comments Discussion') + end + + def self.short_description + _('Comments Discussion') + end + + def self.description + _('Article with paragraph comments') + end + + def accept_comments? + current_time = Time.now + super && + (start_date.nil? || current_time >= start_date) && + (end_date.nil? || current_time <= end_date) + end + + def comment_paragraph_plugin_activated? + environment.plugin_enabled?(CommentParagraphPlugin) + end + +end diff --git a/plugins/comment_paragraph/test/unit/discussion_test.rb b/plugins/comment_paragraph/test/unit/discussion_test.rb new file mode 100644 index 0000000..b7dfd6a --- /dev/null +++ b/plugins/comment_paragraph/test/unit/discussion_test.rb @@ -0,0 +1,31 @@ +require_relative '../test_helper' + +class DiscussionTest < ActiveSupport::TestCase + + def setup + @profile = fast_create(Community) + @discussion = fast_create(TextArticle, :profile_id => profile.id) + @environment = Environment.default + @environment.enable_plugin(CommentParagraphPlugin) + end + + attr_reader :discussion, :environment, :profile + + should 'parse html when save discussion' do + discussion = CommentParagraphPlugin::Discussion.new(profile: profile, name: "discussion", start_date: Time.now, end_date: Time.now + 1.day) + discussion.body = '' + discussion.save! + assert_mark_paragraph discussion.body, 'li', 'item1' + assert_mark_paragraph discussion.body, 'li', 'item2' + end + + should 'not allow comments after end date' do + discussion = CommentParagraphPlugin::Discussion.create!(profile: profile, name: "discussion", start_date: Time.now - 2.days, end_date: Time.now - 1.day) + assert !discussion.accept_comments? + end + + should 'not allow comments before start date' do + discussion = CommentParagraphPlugin::Discussion.create!(profile: profile, name: "discussion", start_date: Time.now + 1.day, end_date: Time.now + 2.days) + assert !discussion.accept_comments? + end +end diff --git a/plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb b/plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb new file mode 100644 index 0000000..f313f1b --- /dev/null +++ b/plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb @@ -0,0 +1,13 @@ +<%= required_fields_message %> + +<%= render :file => 'shared/tiny_mce' %> + +
+ <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> + + <%= render :partial => 'text_fields' %> + <%= render :partial => 'general_fields' %> + <%= render :partial => 'translatable' %> + <%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, {:time => true}, {:id => 'article_start_date'} ) %> + <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %> +
-- libgit2 0.21.2