Commit 92c207ee44c3afd5d35db5191ba70187fb1b29d9

Authored by Rodrigo Souto
1 parent e7445aa3

[macro-support-review] Adjusting details of the plugin to comply with core changes

app/helpers/macros_helper.rb
@@ -6,13 +6,12 @@ module MacrosHelper @@ -6,13 +6,12 @@ module MacrosHelper
6 6
7 def macros_with_buttons 7 def macros_with_buttons
8 @plugins.dispatch(:macros).reject{ |macro| !macro.configuration[:icon_path] } 8 @plugins.dispatch(:macros).reject{ |macro| !macro.configuration[:icon_path] }
9 -  
10 end 9 end
11 10
12 def macro_title(macro) 11 def macro_title(macro)
13 macro.configuration[:title] || macro.name.humanize 12 macro.configuration[:title] || macro.name.humanize
14 end 13 end
15 - 14 +
16 def generate_macro_config_dialog(macro) 15 def generate_macro_config_dialog(macro)
17 if macro.configuration[:skip_dialog] 16 if macro.configuration[:skip_dialog]
18 "function(){#{macro_generator(macro)}}" 17 "function(){#{macro_generator(macro)}}"
@@ -55,7 +54,7 @@ module MacrosHelper @@ -55,7 +54,7 @@ module MacrosHelper
55 end 54 end
56 55
57 protected 56 protected
58 - 57 +
59 def macro_generator(macro) 58 def macro_generator(macro)
60 if macro.configuration[:generator] 59 if macro.configuration[:generator]
61 macro.configuration[:generator] 60 macro.configuration[:generator]
app/views/shared/tiny_mce.rhtml
@@ -31,7 +31,7 @@ tinymce.create('tinymce.plugins.MacrosPlugin', { @@ -31,7 +31,7 @@ tinymce.create('tinymce.plugins.MacrosPlugin', {
31 image : '/designs/icons/tango/Tango/16x16/emblems/emblem-system.png', 31 image : '/designs/icons/tango/Tango/16x16/emblems/emblem-system.png',
32 icons : false 32 icons : false
33 }); 33 });
34 - 34 +
35 <% macros_in_menu.each do |macro| %> 35 <% macros_in_menu.each do |macro| %>
36 c.onRenderMenu.add(function(c, m) { 36 c.onRenderMenu.add(function(c, m) {
37 m.add({ 37 m.add({
@@ -40,7 +40,7 @@ tinymce.create(&#39;tinymce.plugins.MacrosPlugin&#39;, { @@ -40,7 +40,7 @@ tinymce.create(&#39;tinymce.plugins.MacrosPlugin&#39;, {
40 }); 40 });
41 }); 41 });
42 <% end %> 42 <% end %>
43 - 43 +
44 // Return the new menu button instance 44 // Return the new menu button instance
45 return c; 45 return c;
46 <% end %> 46 <% end %>
lib/noosfero/plugin.rb
@@ -147,7 +147,7 @@ class Noosfero::Plugin @@ -147,7 +147,7 @@ class Noosfero::Plugin
147 def macros 147 def macros
148 self.class.constants.map do |constant_name| 148 self.class.constants.map do |constant_name|
149 self.class.const_get(constant_name) 149 self.class.const_get(constant_name)
150 - end.select {|klass| klass <= Noosfero::Plugin::Macro} 150 + end.select {|klass| klass < Noosfero::Plugin::Macro}
151 end 151 end
152 152
153 # Here the developer may specify the events to which the plugins can 153 # Here the developer may specify the events to which the plugins can
lib/noosfero/plugin/manager.rb
@@ -54,7 +54,7 @@ class Noosfero::Plugin::Manager @@ -54,7 +54,7 @@ class Noosfero::Plugin::Manager
54 end 54 end
55 55
56 def parse_macro(macro_name, macro, source = nil) 56 def parse_macro(macro_name, macro, source = nil)
57 - macro_instance = enabled_macros[macro_name] || enabled_macros['default'] 57 + macro_instance = enabled_macros[macro_name] || default_macro
58 macro_instance.convert(macro, source) 58 macro_instance.convert(macro, source)
59 end 59 end
60 60
@@ -64,10 +64,14 @@ class Noosfero::Plugin::Manager @@ -64,10 +64,14 @@ class Noosfero::Plugin::Manager
64 end 64 end
65 end 65 end
66 66
  67 + def default_macro
  68 + @default_macro ||= Noosfero::Plugin::Macro.new(context)
  69 + end
  70 +
67 def enabled_macros 71 def enabled_macros
68 @enabled_macros ||= dispatch(:macros).inject({}) do |memo, macro| 72 @enabled_macros ||= dispatch(:macros).inject({}) do |memo, macro|
69 memo.merge!(macro.identifier => macro.new(context)) 73 memo.merge!(macro.identifier => macro.new(context))
70 - end.merge('default' => Noosfero::Plugin::Macro.new(context)) 74 + end
71 end 75 end
72 76
73 def [](name) 77 def [](name)
plugins/comment_group/lib/comment_group_plugin.rb
@@ -28,3 +28,5 @@ class CommentGroupPlugin &lt; Noosfero::Plugin @@ -28,3 +28,5 @@ class CommentGroupPlugin &lt; Noosfero::Plugin
28 end 28 end
29 29
30 end 30 end
  31 +
  32 +require_dependency 'comment_group_plugin/macros/allow_comment'
plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb
@@ -17,6 +17,6 @@ class CommentGroupPlugin::AllowComment &lt; Noosfero::Plugin::Macro @@ -17,6 +17,6 @@ class CommentGroupPlugin::AllowComment &lt; Noosfero::Plugin::Macro
17 article = source 17 article = source
18 count = article.group_comments.without_spam.in_group(group_id).count 18 count = article.group_comments.without_spam.in_group(group_id).count
19 19
20 - 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 }} 20 + lambda {render :partial => 'plugins/comment_group/views/comment_group.rhtml', :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }}
21 end 21 end
22 end 22 end
plugins/comment_group/public/comment_group.js
@@ -29,7 +29,7 @@ function makeCommentable() { @@ -29,7 +29,7 @@ function makeCommentable() {
29 if(!hasTag) { 29 if(!hasTag) {
30 tags = start.siblings().add(start); 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); 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()+'\"/>'); 32 + tags.wrapAll('<div class=\"macro article_comments\" data-macro=\"comment_group_plugin/allow_comment\" data-macro-group_id=\"'+getNextGroupId()+'\"/>');
33 33
34 contents = jQuery('#article_body_ifr').contents(); 34 contents = jQuery('#article_body_ifr').contents();
35 lastP = contents.find('p.article_comments_last_paragraph'); 35 lastP = contents.find('p.article_comments_last_paragraph');
plugins/comment_group/public/comment_group_macro.js
@@ -5,12 +5,12 @@ jQuery(document).ready(function($) { @@ -5,12 +5,12 @@ jQuery(document).ready(function($) {
5 5
6 var val = anchor.split('-'); //anchor format = #comment-\d+ 6 var val = anchor.split('-'); //anchor format = #comment-\d+
7 if(val.length!=2 || val[0]!='#comment') return; 7 if(val.length!=2 || val[0]!='#comment') return;
8 - if($('div[data-macro=display_comments]').length==0) return; //display_comments div must exists 8 + if($('div[data-macro=comment_group_plugin/allow_comment]').length==0) return; //comment_group_plugin/allow_comment div must exists
9 var comment_id = val[1]; 9 var comment_id = val[1];
10 if(!/^\d+$/.test(comment_id)) return; //test for integer 10 if(!/^\d+$/.test(comment_id)) return; //test for integer
11 11
12 comment_group_anchor = anchor; 12 comment_group_anchor = anchor;
13 - var url = '/plugin/comment_group_macro/public/comment_group/'+comment_id; 13 + var url = '/plugin/comment_group/public/comment_group/'+comment_id;
14 $.getJSON(url, function(data) { 14 $.getJSON(url, function(data) {
15 if(data.group_id!=null) { 15 if(data.group_id!=null) {
16 var button = $('div.comment_group_'+ data.group_id + ' a'); 16 var button = $('div.comment_group_'+ data.group_id + ' a');
plugins/comment_group/views/_comment_group.rhtml
1 <div class="comments"> 1 <div class="comments">
2 <div class="comment_group_<%= group_id %>" style="float: left"> 2 <div class="comment_group_<%= group_id %>" style="float: left">
3 <div style="float: left"> 3 <div style="float: left">
4 - <%= link_to_remote(image_tag("/plugins/comment_group_macro/images/comments.gif"), 4 + <%= link_to_remote(image_tag("/plugins/comment_group/images/comments.gif"),
5 :url => { :profile => profile_identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id}, 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}"), 6 :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"),
7 :method => :post, 7 :method => :post,