Commit 2323e52278b2b9fbd4f3fc40a1b6add65e3e8d08

Authored by Rodrigo Souto
1 parent 8ee471cc

[macro-support-review] Renaming CommentGroup plugin

Showing 28 changed files with 390 additions and 390 deletions   Show diff stats
plugins/comment_group/controllers/profile/comment_group_plugin_profile_controller.rb 0 → 100644
@@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
  1 +class CommentGroupPluginProfileController < ProfileController
  2 + append_view_path File.join(File.dirname(__FILE__) + '/../views')
  3 +
  4 + def view_comments
  5 + article_id = params[:article_id]
  6 + group_id = params[:group_id]
  7 +
  8 + article = profile.articles.find(article_id)
  9 + comments = article.group_comments.without_spam.in_group(group_id)
  10 + render :update do |page|
  11 + page.replace_html "comments_list_group_#{group_id}", :partial => 'comment/comment.rhtml', :collection => comments.as_thread
  12 + page.replace_html "comment-count-#{group_id}", comments.count
  13 + end
  14 + end
  15 +
  16 +end
plugins/comment_group/controllers/public/comment_group_plugin_public_controller.rb 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +class CommentGroupPluginPublicController < PublicController
  2 + append_view_path File.join(File.dirname(__FILE__) + '/../views')
  3 +
  4 + def comment_group
  5 + render :json => { :group_id => Comment.find(params[:id]).group_id }
  6 + end
  7 +
  8 +end
plugins/comment_group/db/migrate/20121220201629_add_group_id_to_comment.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class AddGroupIdToComment < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :comments, :group_id, :integer
  4 + end
  5 +
  6 + def self.down
  7 + remove_column :comments, :group_id
  8 + end
  9 +end
plugins/comment_group/lib/comment_group_plugin.rb 0 → 100644
@@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
  1 +require_dependency 'comment_group_plugin/ext/article'
  2 +require_dependency 'comment_group_plugin/ext/comment'
  3 +
  4 +#FIXME See a better way to generalize this parameter.
  5 +ActionView::Base.sanitized_allowed_attributes += ['data-macro', 'data-macro-group_id']
  6 +
  7 +class CommentGroupPlugin < Noosfero::Plugin
  8 +
  9 + def self.plugin_name
  10 + "Comment Group"
  11 + end
  12 +
  13 + def self.plugin_description
  14 + _("A plugin that display comment groups.")
  15 + end
  16 +
  17 + def load_comments(article)
  18 + article.comments.without_spam.without_group.as_thread
  19 + end
  20 +
  21 + #FIXME make this test
  22 + def macro_display_comments(params, inner_html, source)
  23 + group_id = params[:group_id].to_i
  24 + article = source
  25 + count = article.group_comments.without_spam.in_group(group_id).count
  26 +
  27 + lambda {render :partial => 'plugins/comment_group_macro/views/comment_group.rhtml', :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }}
  28 + end
  29 +
  30 + def macro_methods
  31 + 'macro_display_comments'
  32 + end
  33 +
  34 + def config_macro_display_comments
  35 + { :params => [], :skip_dialog => true, :generator => 'makeCommentable();', :js_files => 'comment_group.js', :icon_path => '/designs/icons/tango/Tango/16x16/emblems/emblem-system.png', :css_files => 'comment_group.css' }
  36 + end
  37 +
  38 + def comment_form_extra_contents(args)
  39 + comment = args[:comment]
  40 + group_id = comment.group_id || args[:group_id]
  41 + lambda {
  42 + hidden_field_tag('comment[group_id]', group_id) if group_id
  43 + }
  44 + end
  45 +
  46 + def js_files
  47 + 'comment_group_macro.js'
  48 + end
  49 +
  50 +end
plugins/comment_group/lib/comment_group_plugin/ext/article.rb 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +require_dependency 'article'
  2 +
  3 +class Article
  4 +
  5 + #FIXME make this test
  6 + has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL']
  7 +
  8 + #FIXME make this test
  9 + validate :not_empty_group_comments_removed
  10 +
  11 + #FIXME make this test
  12 + def not_empty_group_comments_removed
  13 + if body
  14 + groups_with_comments = group_comments.collect {|comment| comment.group_id}.uniq
  15 + groups = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-group_id'].to_i}
  16 + errors.add_to_base(N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty?
  17 + end
  18 + end
  19 +
  20 +end
  21 +
plugins/comment_group/lib/comment_group_plugin/ext/comment.rb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +require_dependency 'comment'
  2 +
  3 +class Comment
  4 +
  5 + named_scope :without_group, :conditions => {:group_id => nil }
  6 +
  7 + named_scope :in_group, lambda { |group_id| {
  8 + :conditions => ['group_id = ?', group_id]
  9 + }
  10 + }
  11 +
  12 +end
plugins/comment_group/public/comment_group.css 0 → 100644
@@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
  1 +div.article_comments {
  2 + background-color:#dddddd;
  3 + border-style: solid;
  4 + border-color:#bbbbbb;
  5 + border-width:2px;
  6 +}
plugins/comment_group/public/comment_group.js 0 → 100644
@@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
  1 +function getNextGroupId() {
  2 + max = -1;
  3 + groups = jQuery('#article_body_ifr').contents().find('.article_comments');
  4 + groups.each(function(key, value) {
  5 + value = jQuery(value).attr('data-macro-group_id');
  6 + if(value>max) max = parseInt(value);
  7 + });
  8 + return max+1;
  9 +}
  10 +
  11 +function makeCommentable() {
  12 + tinyMCE.activeEditor.focus();
  13 + start = jQuery(tinyMCE.activeEditor.selection.getStart()).closest('p');
  14 + end = jQuery(tinyMCE.activeEditor.selection.getEnd()).closest('p');
  15 +
  16 + //text = start.parent().children();
  17 + text = jQuery('#article_body_ifr').contents().find('*');
  18 + selection = text.slice(text.index(start), text.index(end)+1);
  19 +
  20 + hasTag = false;
  21 + selection.each(function(key, value) {
  22 + commentTag = jQuery(value).closest('.article_comments');
  23 + if(commentTag.length) {
  24 + commentTag.children().unwrap('<div class=\"article_comments\"/>');
  25 + hasTag = true;
  26 + }
  27 + });
  28 +
  29 + if(!hasTag) {
  30 + tags = start.siblings().add(start);
  31 + tags = tags.slice(tags.index(start), tags.index(end)>=0?tags.index(end)+1:tags.index(start)+1);
  32 + tags.wrapAll('<div class=\"macro article_comments\" data-macro=\"display_comments\" data-macro-group_id=\"'+getNextGroupId()+'\"/>');
  33 +
  34 + contents = jQuery('#article_body_ifr').contents();
  35 + lastP = contents.find('p.article_comments_last_paragraph');
  36 + if(lastP.text().trim().length > 0) {
  37 + lastP.removeClass('article_comments_last_paragraph');
  38 + } else {
  39 + lastP.remove();
  40 + }
  41 + lastDiv = contents.find('div.article_comments').last();
  42 + if(lastDiv.next().length==0) {
  43 + lastDiv.after("<p class='article_comments_last_paragraph'>&nbsp;</p>");
  44 + }
  45 + }
  46 +}
  47 +
plugins/comment_group/public/comment_group_macro.js 0 → 100644
@@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
  1 +var comment_group_anchor;
  2 +jQuery(document).ready(function($) {
  3 + var anchor = window.location.hash;
  4 + if(anchor.length==0) return;
  5 +
  6 + var val = anchor.split('-'); //anchor format = #comment-\d+
  7 + if(val.length!=2 || val[0]!='#comment') return;
  8 + if($('div[data-macro=display_comments]').length==0) return; //display_comments div must exists
  9 + var comment_id = val[1];
  10 + if(!/^\d+$/.test(comment_id)) return; //test for integer
  11 +
  12 + comment_group_anchor = anchor;
  13 + var url = '/plugin/comment_group_macro/public/comment_group/'+comment_id;
  14 + $.getJSON(url, function(data) {
  15 + if(data.group_id!=null) {
  16 + var button = $('div.comment_group_'+ data.group_id + ' a');
  17 + button.click();
  18 + $.scrollTo(button);
  19 + }
  20 + });
  21 +});
  22 +
  23 +function toggleGroup(group) {
  24 + var div = jQuery('div.comments_list_toggle_group_'+group);
  25 + var visible = div.is(':visible');
  26 + if(!visible)
  27 + jQuery('div.comment-group-loading-'+group).addClass('comment-button-loading');
  28 +
  29 + div.toggle('fast');
  30 + return visible;
  31 +}
  32 +
  33 +function loadCompleted(group) {
  34 + jQuery('div.comment-group-loading-'+group).removeClass('comment-button-loading')
  35 + if(comment_group_anchor) {
  36 + jQuery.scrollTo(jQuery(comment_group_anchor));
  37 + comment_group_anchor = null;
  38 + }
  39 +}
plugins/comment_group/public/images/comments.gif 0 → 100644

1.66 KB

plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb 0 → 100644
@@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../../controllers/profile/comment_group_plugin_profile_controller'
  3 +
  4 +# Re-raise errors caught by the controller.
  5 +class CommentGroupPluginProfileController; def rescue_action(e) raise e end; end
  6 +
  7 +class CommentGroupPluginProfileControllerTest < ActionController::TestCase
  8 +
  9 + def setup
  10 + @controller = CommentGroupPluginProfileController.new
  11 + @request = ActionController::TestRequest.new
  12 + @response = ActionController::TestResponse.new
  13 +
  14 + @profile = create_user('testuser').person
  15 + @article = profile.articles.build(:name => 'test')
  16 + @article.save!
  17 + end
  18 + attr_reader :article
  19 + attr_reader :profile
  20 +
  21 + should 'be able to show group comments' do
  22 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  23 + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0
  24 + assert_template 'comment/_comment.rhtml'
  25 + assert_match /comments_list_group_0/, @response.body
  26 + assert_match /\"comment-count-0\", \"1\"/, @response.body
  27 + end
  28 +
  29 + should 'do not show global comments' do
  30 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :group_id => nil)
  31 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  32 + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0
  33 + assert_template 'comment/_comment.rhtml'
  34 + assert_match /comments_list_group_0/, @response.body
  35 + assert_match /\"comment-count-0\", \"1\"/, @response.body
  36 + end
  37 +
  38 +end
plugins/comment_group/test/functional/comment_group_plugin_public_controller_test.rb 0 → 100644
@@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../../controllers/public/comment_group_plugin_public_controller'
  3 +
  4 +# Re-raise errors caught by the controller.
  5 +class CommentGroupPluginPublicController; def rescue_action(e) raise e end; end
  6 +
  7 +class CommentGroupPluginPublicControllerTest < ActionController::TestCase
  8 +
  9 + def setup
  10 + @controller = CommentGroupPluginPublicController.new
  11 + @request = ActionController::TestRequest.new
  12 + @response = ActionController::TestResponse.new
  13 +
  14 + @profile = create_user('testuser').person
  15 + @article = profile.articles.build(:name => 'test')
  16 + @article.save!
  17 + end
  18 + attr_reader :article
  19 + attr_reader :profile
  20 +
  21 + should 'be able to return group_id for a comment' do
  22 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)
  23 + xhr :get, :comment_group, :id => comment.id
  24 + assert_match /\{\"group_id\":0\}/, @response.body
  25 + end
  26 +
  27 + should 'return group_id=null for a global comment' do
  28 + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' )
  29 + xhr :get, :comment_group, :id => comment.id
  30 + assert_match /\{\"group_id\":null\}/, @response.body
  31 + end
  32 +
  33 +end
plugins/comment_group/test/unit/comment_group_plugin_test.rb 0 → 100644
@@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +
  3 +class CommentGroupPluginTest < ActiveSupport::TestCase
  4 +
  5 + include Noosfero::Plugin::HotSpot
  6 +
  7 + def setup
  8 + @environment = Environment.default
  9 + end
  10 +
  11 + attr_reader :environment
  12 +
  13 + should 'register comment_group_macro in environment' do
  14 + Environment.macros = {}
  15 + Environment.macros[environment.id] = {}
  16 + macros = Environment.macros[environment.id]
  17 + context = mock()
  18 + context.stubs(:environment).returns(environment)
  19 + plugin = CommentGroupPlugin.new(context)
  20 + assert_equal ['macro_display_comments'], macros.keys
  21 + end
  22 +
  23 + should 'load_comments returns all the comments wihout group of an article passed as parameter' do
  24 + article = fast_create(Article)
  25 + c1 = fast_create(Comment, :source_id => article.id, :group_id => 1)
  26 + c2 = fast_create(Comment, :source_id => article.id)
  27 + c3 = fast_create(Comment, :source_id => article.id)
  28 +
  29 + plugin = CommentGroupPlugin.new
  30 + assert_equal [], [c2, c3] - plugin.load_comments(article)
  31 + assert_equal [], plugin.load_comments(article) - [c2, c3]
  32 + end
  33 +
  34 + should 'load_comments not returns spam comments' do
  35 + article = fast_create(Article)
  36 + c1 = fast_create(Comment, :source_id => article.id, :group_id => 1)
  37 + c2 = fast_create(Comment, :source_id => article.id)
  38 + c3 = fast_create(Comment, :source_id => article.id, :spam => true)
  39 +
  40 + plugin = CommentGroupPlugin.new
  41 + assert_equal [], [c2] - plugin.load_comments(article)
  42 + assert_equal [], plugin.load_comments(article) - [c2]
  43 + end
  44 +
  45 + should 'load_comments returns only root comments of article' do
  46 + article = fast_create(Article)
  47 + c1 = fast_create(Comment, :source_id => article.id, :group_id => 1)
  48 + c2 = fast_create(Comment, :source_id => article.id)
  49 + c3 = fast_create(Comment, :source_id => article.id, :reply_of_id => c2.id)
  50 +
  51 + plugin = CommentGroupPlugin.new
  52 + assert_equal [], [c2] - plugin.load_comments(article)
  53 + assert_equal [], plugin.load_comments(article) - [c2]
  54 + end
  55 +
  56 + should 'params of macro display comments configuration be an empty array' do
  57 + plugin = CommentGroupPlugin.new
  58 + assert_equal [], plugin.config_macro_display_comments[:params]
  59 + end
  60 +
  61 + should 'skip_dialog of macro display comments configuration be true' do
  62 + plugin = CommentGroupPlugin.new
  63 + assert plugin.config_macro_display_comments[:skip_dialog]
  64 + end
  65 +
  66 + should 'generator of macro display comments configuration be the makeCommentable function' do
  67 + plugin = CommentGroupPlugin.new
  68 + assert_equal 'makeCommentable();', plugin.config_macro_display_comments[:generator]
  69 + end
  70 +
  71 + should 'js_files of macro display comments configuration return comment_group.js' do
  72 + plugin = CommentGroupPlugin.new
  73 + assert_equal 'comment_group.js', plugin.config_macro_display_comments[:js_files]
  74 + end
  75 +
  76 + should 'css_files of macro display comments configuration return comment_group.css' do
  77 + plugin = CommentGroupPlugin.new
  78 + assert_equal 'comment_group.css', plugin.config_macro_display_comments[:css_files]
  79 + end
  80 +
  81 +end
plugins/comment_group/views/_comment_group.rhtml 0 → 100644
@@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
  1 +<div class="comments">
  2 + <div class="comment_group_<%= group_id %>" style="float: left">
  3 + <div style="float: left">
  4 + <%= link_to_remote(image_tag("/plugins/comment_group_macro/images/comments.gif"),
  5 + :url => { :profile => profile_identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id},
  6 + :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"),
  7 + :method => :post,
  8 + :condition => "!toggleGroup(#{group_id})",
  9 + :complete => "loadCompleted(#{group_id})")%>
  10 + </div>
  11 + <!-- FIXME: css file -->
  12 + <div id="comments_group_count_<%= group_id %>" style="float: right; vertical-align: middle; padding-left: 3px; padding-right: 5px; color: #5AC1FC"><span id="comment-count-<%= group_id %>" class='comment-count'><%= count %></span></div>
  13 +
  14 + </div>
  15 +
  16 + <div>
  17 + <%= inner_html %>
  18 + </div>
  19 +
  20 + <div class="comment-group-loading-<%= group_id %>"/>
  21 +
  22 + <div class="comments_list_toggle_group_<%= group_id %>" style="display:none">
  23 + <div class="article-comments-list">
  24 + <div id="comments_list_group_<%= group_id %>"></div>
  25 + </div>
  26 +
  27 + <div id="page-comment-form-<%= group_id %>" class='post_comment_box closed'><%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :group_id => group_id}%></div>
  28 +
  29 + </div>
  30 +</div>
plugins/comment_group_macro/controllers/profile/comment_group_macro_plugin_profile_controller.rb
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -class CommentGroupMacroPluginProfileController < ProfileController  
2 - append_view_path File.join(File.dirname(__FILE__) + '/../views')  
3 -  
4 - def view_comments  
5 - article_id = params[:article_id]  
6 - group_id = params[:group_id]  
7 -  
8 - article = profile.articles.find(article_id)  
9 - comments = article.group_comments.without_spam.in_group(group_id)  
10 - render :update do |page|  
11 - page.replace_html "comments_list_group_#{group_id}", :partial => 'comment/comment.rhtml', :collection => comments.as_thread  
12 - page.replace_html "comment-count-#{group_id}", comments.count  
13 - end  
14 - end  
15 -  
16 -end  
plugins/comment_group_macro/controllers/public/comment_group_macro_plugin_public_controller.rb
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -class CommentGroupMacroPluginPublicController < PublicController  
2 - append_view_path File.join(File.dirname(__FILE__) + '/../views')  
3 -  
4 - def comment_group  
5 - render :json => { :group_id => Comment.find(params[:id]).group_id }  
6 - end  
7 -  
8 -end  
plugins/comment_group_macro/db/migrate/20121220201629_add_group_id_to_comment.rb
@@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
1 -class AddGroupIdToComment < ActiveRecord::Migration  
2 - def self.up  
3 - add_column :comments, :group_id, :integer  
4 - end  
5 -  
6 - def self.down  
7 - remove_column :comments, :group_id  
8 - end  
9 -end  
plugins/comment_group_macro/lib/comment_group_macro_plugin.rb
@@ -1,50 +0,0 @@ @@ -1,50 +0,0 @@
1 -require_dependency 'comment_group_macro_plugin/ext/article'  
2 -require_dependency 'comment_group_macro_plugin/ext/comment'  
3 -  
4 -#FIXME See a better way to generalize this parameter.  
5 -ActionView::Base.sanitized_allowed_attributes += ['data-macro', 'data-macro-group_id']  
6 -  
7 -class CommentGroupMacroPlugin < Noosfero::Plugin  
8 -  
9 - def self.plugin_name  
10 - "Comment Group"  
11 - end  
12 -  
13 - def self.plugin_description  
14 - _("A plugin that display comment groups.")  
15 - end  
16 -  
17 - def load_comments(article)  
18 - article.comments.without_spam.without_group.as_thread  
19 - end  
20 -  
21 - #FIXME make this test  
22 - def macro_display_comments(params, inner_html, source)  
23 - group_id = params[:group_id].to_i  
24 - article = source  
25 - count = article.group_comments.without_spam.in_group(group_id).count  
26 -  
27 - lambda {render :partial => 'plugins/comment_group_macro/views/comment_group.rhtml', :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }}  
28 - end  
29 -  
30 - def macro_methods  
31 - 'macro_display_comments'  
32 - end  
33 -  
34 - def config_macro_display_comments  
35 - { :params => [], :skip_dialog => true, :generator => 'makeCommentable();', :js_files => 'comment_group.js', :icon_path => '/designs/icons/tango/Tango/16x16/emblems/emblem-system.png', :css_files => 'comment_group.css' }  
36 - end  
37 -  
38 - def comment_form_extra_contents(args)  
39 - comment = args[:comment]  
40 - group_id = comment.group_id || args[:group_id]  
41 - lambda {  
42 - hidden_field_tag('comment[group_id]', group_id) if group_id  
43 - }  
44 - end  
45 -  
46 - def js_files  
47 - 'comment_group_macro.js'  
48 - end  
49 -  
50 -end  
plugins/comment_group_macro/lib/comment_group_macro_plugin/ext/article.rb
@@ -1,21 +0,0 @@ @@ -1,21 +0,0 @@
1 -require_dependency 'article'  
2 -  
3 -class Article  
4 -  
5 - #FIXME make this test  
6 - has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL']  
7 -  
8 - #FIXME make this test  
9 - validate :not_empty_group_comments_removed  
10 -  
11 - #FIXME make this test  
12 - def not_empty_group_comments_removed  
13 - if body  
14 - groups_with_comments = group_comments.collect {|comment| comment.group_id}.uniq  
15 - groups = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-group_id'].to_i}  
16 - errors.add_to_base(N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty?  
17 - end  
18 - end  
19 -  
20 -end  
21 -  
plugins/comment_group_macro/lib/comment_group_macro_plugin/ext/comment.rb
@@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
1 -require_dependency 'comment'  
2 -  
3 -class Comment  
4 -  
5 - named_scope :without_group, :conditions => {:group_id => nil }  
6 -  
7 - named_scope :in_group, lambda { |group_id| {  
8 - :conditions => ['group_id = ?', group_id]  
9 - }  
10 - }  
11 -  
12 -end  
plugins/comment_group_macro/public/comment_group.css
@@ -1,6 +0,0 @@ @@ -1,6 +0,0 @@
1 -div.article_comments {  
2 - background-color:#dddddd;  
3 - border-style: solid;  
4 - border-color:#bbbbbb;  
5 - border-width:2px;  
6 -}  
plugins/comment_group_macro/public/comment_group.js
@@ -1,47 +0,0 @@ @@ -1,47 +0,0 @@
1 -function getNextGroupId() {  
2 - max = -1;  
3 - groups = jQuery('#article_body_ifr').contents().find('.article_comments');  
4 - groups.each(function(key, value) {  
5 - value = jQuery(value).attr('data-macro-group_id');  
6 - if(value>max) max = parseInt(value);  
7 - });  
8 - return max+1;  
9 -}  
10 -  
11 -function makeCommentable() {  
12 - tinyMCE.activeEditor.focus();  
13 - start = jQuery(tinyMCE.activeEditor.selection.getStart()).closest('p');  
14 - end = jQuery(tinyMCE.activeEditor.selection.getEnd()).closest('p');  
15 -  
16 - //text = start.parent().children();  
17 - text = jQuery('#article_body_ifr').contents().find('*');  
18 - selection = text.slice(text.index(start), text.index(end)+1);  
19 -  
20 - hasTag = false;  
21 - selection.each(function(key, value) {  
22 - commentTag = jQuery(value).closest('.article_comments');  
23 - if(commentTag.length) {  
24 - commentTag.children().unwrap('<div class=\"article_comments\"/>');  
25 - hasTag = true;  
26 - }  
27 - });  
28 -  
29 - if(!hasTag) {  
30 - tags = start.siblings().add(start);  
31 - tags = tags.slice(tags.index(start), tags.index(end)>=0?tags.index(end)+1:tags.index(start)+1);  
32 - tags.wrapAll('<div class=\"macro article_comments\" data-macro=\"display_comments\" data-macro-group_id=\"'+getNextGroupId()+'\"/>');  
33 -  
34 - contents = jQuery('#article_body_ifr').contents();  
35 - lastP = contents.find('p.article_comments_last_paragraph');  
36 - if(lastP.text().trim().length > 0) {  
37 - lastP.removeClass('article_comments_last_paragraph');  
38 - } else {  
39 - lastP.remove();  
40 - }  
41 - lastDiv = contents.find('div.article_comments').last();  
42 - if(lastDiv.next().length==0) {  
43 - lastDiv.after("<p class='article_comments_last_paragraph'>&nbsp;</p>");  
44 - }  
45 - }  
46 -}  
47 -  
plugins/comment_group_macro/public/comment_group_macro.js
@@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
1 -var comment_group_anchor;  
2 -jQuery(document).ready(function($) {  
3 - var anchor = window.location.hash;  
4 - if(anchor.length==0) return;  
5 -  
6 - var val = anchor.split('-'); //anchor format = #comment-\d+  
7 - if(val.length!=2 || val[0]!='#comment') return;  
8 - if($('div[data-macro=display_comments]').length==0) return; //display_comments div must exists  
9 - var comment_id = val[1];  
10 - if(!/^\d+$/.test(comment_id)) return; //test for integer  
11 -  
12 - comment_group_anchor = anchor;  
13 - var url = '/plugin/comment_group_macro/public/comment_group/'+comment_id;  
14 - $.getJSON(url, function(data) {  
15 - if(data.group_id!=null) {  
16 - var button = $('div.comment_group_'+ data.group_id + ' a');  
17 - button.click();  
18 - $.scrollTo(button);  
19 - }  
20 - });  
21 -});  
22 -  
23 -function toggleGroup(group) {  
24 - var div = jQuery('div.comments_list_toggle_group_'+group);  
25 - var visible = div.is(':visible');  
26 - if(!visible)  
27 - jQuery('div.comment-group-loading-'+group).addClass('comment-button-loading');  
28 -  
29 - div.toggle('fast');  
30 - return visible;  
31 -}  
32 -  
33 -function loadCompleted(group) {  
34 - jQuery('div.comment-group-loading-'+group).removeClass('comment-button-loading')  
35 - if(comment_group_anchor) {  
36 - jQuery.scrollTo(jQuery(comment_group_anchor));  
37 - comment_group_anchor = null;  
38 - }  
39 -}  
plugins/comment_group_macro/public/images/comments.gif

1.66 KB

plugins/comment_group_macro/test/functional/comment_group_macro_plugin_profile_controller_test.rb
@@ -1,38 +0,0 @@ @@ -1,38 +0,0 @@
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper'  
2 -require File.dirname(__FILE__) + '/../../controllers/profile/comment_group_macro_plugin_profile_controller'  
3 -  
4 -# Re-raise errors caught by the controller.  
5 -class CommentGroupMacroPluginProfileController; def rescue_action(e) raise e end; end  
6 -  
7 -class CommentGroupMacroPluginProfileControllerTest < ActionController::TestCase  
8 -  
9 - def setup  
10 - @controller = CommentGroupMacroPluginProfileController.new  
11 - @request = ActionController::TestRequest.new  
12 - @response = ActionController::TestResponse.new  
13 -  
14 - @profile = create_user('testuser').person  
15 - @article = profile.articles.build(:name => 'test')  
16 - @article.save!  
17 - end  
18 - attr_reader :article  
19 - attr_reader :profile  
20 -  
21 - should 'be able to show group comments' do  
22 - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)  
23 - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0  
24 - assert_template 'comment/_comment.rhtml'  
25 - assert_match /comments_list_group_0/, @response.body  
26 - assert_match /\"comment-count-0\", \"1\"/, @response.body  
27 - end  
28 -  
29 - should 'do not show global comments' do  
30 - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'global comment', :body => 'global', :group_id => nil)  
31 - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)  
32 - xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0  
33 - assert_template 'comment/_comment.rhtml'  
34 - assert_match /comments_list_group_0/, @response.body  
35 - assert_match /\"comment-count-0\", \"1\"/, @response.body  
36 - end  
37 -  
38 -end  
plugins/comment_group_macro/test/functional/comment_group_macro_plugin_public_controller_test.rb
@@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper'  
2 -require File.dirname(__FILE__) + '/../../controllers/public/comment_group_macro_plugin_public_controller'  
3 -  
4 -# Re-raise errors caught by the controller.  
5 -class CommentGroupMacroPluginPublicController; def rescue_action(e) raise e end; end  
6 -  
7 -class CommentGroupMacroPluginPublicControllerTest < ActionController::TestCase  
8 -  
9 - def setup  
10 - @controller = CommentGroupMacroPluginPublicController.new  
11 - @request = ActionController::TestRequest.new  
12 - @response = ActionController::TestResponse.new  
13 -  
14 - @profile = create_user('testuser').person  
15 - @article = profile.articles.build(:name => 'test')  
16 - @article.save!  
17 - end  
18 - attr_reader :article  
19 - attr_reader :profile  
20 -  
21 - should 'be able to return group_id for a comment' do  
22 - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0)  
23 - xhr :get, :comment_group, :id => comment.id  
24 - assert_match /\{\"group_id\":0\}/, @response.body  
25 - end  
26 -  
27 - should 'return group_id=null for a global comment' do  
28 - comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' )  
29 - xhr :get, :comment_group, :id => comment.id  
30 - assert_match /\{\"group_id\":null\}/, @response.body  
31 - end  
32 -  
33 -end  
plugins/comment_group_macro/test/unit/comment_group_macro_plugin_test.rb
@@ -1,81 +0,0 @@ @@ -1,81 +0,0 @@
1 -require File.dirname(__FILE__) + '/../../../../test/test_helper'  
2 -  
3 -class CommentGroupMacroPluginTest < ActiveSupport::TestCase  
4 -  
5 - include Noosfero::Plugin::HotSpot  
6 -  
7 - def setup  
8 - @environment = Environment.default  
9 - end  
10 -  
11 - attr_reader :environment  
12 -  
13 - should 'register comment_group_macro in environment' do  
14 - Environment.macros = {}  
15 - Environment.macros[environment.id] = {}  
16 - macros = Environment.macros[environment.id]  
17 - context = mock()  
18 - context.stubs(:environment).returns(environment)  
19 - plugin = CommentGroupMacroPlugin.new(context)  
20 - assert_equal ['macro_display_comments'], macros.keys  
21 - end  
22 -  
23 - should 'load_comments returns all the comments wihout group of an article passed as parameter' do  
24 - article = fast_create(Article)  
25 - c1 = fast_create(Comment, :source_id => article.id, :group_id => 1)  
26 - c2 = fast_create(Comment, :source_id => article.id)  
27 - c3 = fast_create(Comment, :source_id => article.id)  
28 -  
29 - plugin = CommentGroupMacroPlugin.new  
30 - assert_equal [], [c2, c3] - plugin.load_comments(article)  
31 - assert_equal [], plugin.load_comments(article) - [c2, c3]  
32 - end  
33 -  
34 - should 'load_comments not returns spam comments' do  
35 - article = fast_create(Article)  
36 - c1 = fast_create(Comment, :source_id => article.id, :group_id => 1)  
37 - c2 = fast_create(Comment, :source_id => article.id)  
38 - c3 = fast_create(Comment, :source_id => article.id, :spam => true)  
39 -  
40 - plugin = CommentGroupMacroPlugin.new  
41 - assert_equal [], [c2] - plugin.load_comments(article)  
42 - assert_equal [], plugin.load_comments(article) - [c2]  
43 - end  
44 -  
45 - should 'load_comments returns only root comments of article' do  
46 - article = fast_create(Article)  
47 - c1 = fast_create(Comment, :source_id => article.id, :group_id => 1)  
48 - c2 = fast_create(Comment, :source_id => article.id)  
49 - c3 = fast_create(Comment, :source_id => article.id, :reply_of_id => c2.id)  
50 -  
51 - plugin = CommentGroupMacroPlugin.new  
52 - assert_equal [], [c2] - plugin.load_comments(article)  
53 - assert_equal [], plugin.load_comments(article) - [c2]  
54 - end  
55 -  
56 - should 'params of macro display comments configuration be an empty array' do  
57 - plugin = CommentGroupMacroPlugin.new  
58 - assert_equal [], plugin.config_macro_display_comments[:params]  
59 - end  
60 -  
61 - should 'skip_dialog of macro display comments configuration be true' do  
62 - plugin = CommentGroupMacroPlugin.new  
63 - assert plugin.config_macro_display_comments[:skip_dialog]  
64 - end  
65 -  
66 - should 'generator of macro display comments configuration be the makeCommentable function' do  
67 - plugin = CommentGroupMacroPlugin.new  
68 - assert_equal 'makeCommentable();', plugin.config_macro_display_comments[:generator]  
69 - end  
70 -  
71 - should 'js_files of macro display comments configuration return comment_group.js' do  
72 - plugin = CommentGroupMacroPlugin.new  
73 - assert_equal 'comment_group.js', plugin.config_macro_display_comments[:js_files]  
74 - end  
75 -  
76 - should 'css_files of macro display comments configuration return comment_group.css' do  
77 - plugin = CommentGroupMacroPlugin.new  
78 - assert_equal 'comment_group.css', plugin.config_macro_display_comments[:css_files]  
79 - end  
80 -  
81 -end  
plugins/comment_group_macro/views/_comment_group.rhtml
@@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
1 -<div class="comments">  
2 - <div class="comment_group_<%= group_id %>" style="float: left">  
3 - <div style="float: left">  
4 - <%= link_to_remote(image_tag("/plugins/comment_group_macro/images/comments.gif"),  
5 - :url => { :profile => profile_identifier, :controller => 'comment_group_macro_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id},  
6 - :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"),  
7 - :method => :post,  
8 - :condition => "!toggleGroup(#{group_id})",  
9 - :complete => "loadCompleted(#{group_id})")%>  
10 - </div>  
11 - <!-- FIXME: css file -->  
12 - <div id="comments_group_count_<%= group_id %>" style="float: right; vertical-align: middle; padding-left: 3px; padding-right: 5px; color: #5AC1FC"><span id="comment-count-<%= group_id %>" class='comment-count'><%= count %></span></div>  
13 -  
14 - </div>  
15 -  
16 - <div>  
17 - <%= inner_html %>  
18 - </div>  
19 -  
20 - <div class="comment-group-loading-<%= group_id %>"/>  
21 -  
22 - <div class="comments_list_toggle_group_<%= group_id %>" style="display:none">  
23 - <div class="article-comments-list">  
24 - <div id="comments_list_group_<%= group_id %>"></div>  
25 - </div>  
26 -  
27 - <div id="page-comment-form-<%= group_id %>" class='post_comment_box closed'><%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :group_id => group_id}%></div>  
28 -  
29 - </div>  
30 -</div>