Commit 27b7acbcb2ad57c0284ed8cb7b4a0201eec62139

Authored by Victor Costa
1 parent 930a5a02

comment_paragraph: add discussion content type

plugins/comment_paragraph/lib/comment_paragraph_plugin.rb
... ... @@ -59,6 +59,10 @@ class CommentParagraphPlugin < Noosfero::Plugin
59 59 [CommentParagraphPlugin::API]
60 60 end
61 61  
  62 + def content_types
  63 + [CommentParagraphPlugin::Discussion]
  64 + end
  65 +
62 66 end
63 67  
64 68 require_dependency 'comment_paragraph_plugin/macros/allow_comment'
... ...
plugins/comment_paragraph/lib/comment_paragraph_plugin/discussion.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +class CommentParagraphPlugin::Discussion < Event
  2 +
  3 + def self.type_name
  4 + _('Comments Discussion')
  5 + end
  6 +
  7 + def self.short_description
  8 + _('Comments Discussion')
  9 + end
  10 +
  11 + def self.description
  12 + _('Article with paragraph comments')
  13 + end
  14 +
  15 + def accept_comments?
  16 + current_time = Time.now
  17 + super &&
  18 + (start_date.nil? || current_time >= start_date) &&
  19 + (end_date.nil? || current_time <= end_date)
  20 + end
  21 +
  22 + def comment_paragraph_plugin_activated?
  23 + environment.plugin_enabled?(CommentParagraphPlugin)
  24 + end
  25 +
  26 +end
... ...
plugins/comment_paragraph/test/unit/discussion_test.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require_relative '../test_helper'
  2 +
  3 +class DiscussionTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @profile = fast_create(Community)
  7 + @discussion = fast_create(TextArticle, :profile_id => profile.id)
  8 + @environment = Environment.default
  9 + @environment.enable_plugin(CommentParagraphPlugin)
  10 + end
  11 +
  12 + attr_reader :discussion, :environment, :profile
  13 +
  14 + should 'parse html when save discussion' do
  15 + discussion = CommentParagraphPlugin::Discussion.new(profile: profile, name: "discussion", start_date: Time.now, end_date: Time.now + 1.day)
  16 + discussion.body = '<ul><li class="custom_class">item1</li><li>item2</li></ul>'
  17 + discussion.save!
  18 + assert_mark_paragraph discussion.body, 'li', 'item1'
  19 + assert_mark_paragraph discussion.body, 'li', 'item2'
  20 + end
  21 +
  22 + should 'not allow comments after end date' do
  23 + discussion = CommentParagraphPlugin::Discussion.create!(profile: profile, name: "discussion", start_date: Time.now - 2.days, end_date: Time.now - 1.day)
  24 + assert !discussion.accept_comments?
  25 + end
  26 +
  27 + should 'not allow comments before start date' do
  28 + discussion = CommentParagraphPlugin::Discussion.create!(profile: profile, name: "discussion", start_date: Time.now + 1.day, end_date: Time.now + 2.days)
  29 + assert !discussion.accept_comments?
  30 + end
  31 +end
... ...
plugins/comment_paragraph/views/cms/comment_paragraph_plugin/_discussion.html.erb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +<%= required_fields_message %>
  2 +
  3 +<%= render :file => 'shared/tiny_mce' %>
  4 +
  5 +<div>
  6 + <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %>
  7 +
  8 + <%= render :partial => 'text_fields' %>
  9 + <%= render :partial => 'general_fields' %>
  10 + <%= render :partial => 'translatable' %>
  11 + <%= date_range_field('article[start_date]', 'article[end_date]', @article.start_date, @article.end_date, {:time => true}, {:id => 'article_start_date'} ) %>
  12 + <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %>
  13 +</div>
... ...