Commit 62be815f13c02da663f6aa5991adf00cb4b66655
1 parent
07caf3d4
Exists in
master
and in
28 other branches
[macro-support-review] Adding identifier method for macro
Showing
6 changed files
with
19 additions
and
14 deletions
Show diff stats
app/helpers/macros_helper.rb
| ... | ... | @@ -67,13 +67,12 @@ module MacrosHelper |
| 67 | 67 | |
| 68 | 68 | def macro_default_generator(macro) |
| 69 | 69 | code = "var params = {};" |
| 70 | - macro_name = macro.name.undescore | |
| 71 | 70 | configuration = macro_configuration(macro) |
| 72 | 71 | configuration[:params].map do |field| |
| 73 | 72 | code += "params.#{field[:name]} = jQuery('*[name=#{field[:name]}]', dialog).val();" |
| 74 | 73 | end |
| 75 | 74 | code + " |
| 76 | - var html = jQuery('<div class=\"macro mceNonEditable\" data-macro=\"#{macro_name}\">'+#{macro_title(macro).to_json}+'</div>')[0]; | |
| 75 | + var html = jQuery('<div class=\"macro mceNonEditable\" data-macro=\"#{macro.identifier}\">'+#{macro_title(macro).to_json}+'</div>')[0]; | |
| 77 | 76 | for(key in params) html.setAttribute('data-macro-'+key,params[key]); |
| 78 | 77 | return html.outerHTML; |
| 79 | 78 | " | ... | ... |
app/views/shared/tiny_mce.rhtml
| ... | ... | @@ -12,7 +12,7 @@ |
| 12 | 12 | first_line = "print,separator,copy,paste,separator,undo,redo,separator,search,replace,separator,forecolor,fontsizeselect,formatselect" |
| 13 | 13 | second_line = "bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,unlink,image,table,separator,cleanup,code,macros" |
| 14 | 14 | <% macros_with_buttons.each do |macro| %> |
| 15 | - second_line += ',<%=macro.name.underscore %>' | |
| 15 | + second_line += ',<%=macro.identifier %>' | |
| 16 | 16 | <% end %> |
| 17 | 17 | <% end %> |
| 18 | 18 | |
| ... | ... | @@ -76,7 +76,7 @@ tinyMCE.init({ |
| 76 | 76 | entity_encoding: 'raw', |
| 77 | 77 | setup : function(ed) { |
| 78 | 78 | <% macros_with_buttons.each do |macro| %> |
| 79 | - ed.addButton('<%= macro.name.underscore %>', { | |
| 79 | + ed.addButton('<%= macro.identifier %>', { | |
| 80 | 80 | title: <%= macro_title(macro).to_json %>, |
| 81 | 81 | onclick: <%= generate_macro_config_dialog(macro) %>, |
| 82 | 82 | image : '<%= macro.configuration[:icon_path]%>' | ... | ... |
lib/noosfero/plugin/macro.rb
| ... | ... | @@ -2,12 +2,18 @@ class Noosfero::Plugin::Macro |
| 2 | 2 | |
| 3 | 3 | attr_accessor :context |
| 4 | 4 | |
| 5 | - def self.configuration | |
| 6 | -# {:generator => ''} | |
| 7 | - end | |
| 5 | + class << self | |
| 6 | + def configuration | |
| 7 | + # {:generator => ''} | |
| 8 | + end | |
| 8 | 9 | |
| 9 | - def self.plugin | |
| 10 | - name.split('::')[0...-1].join('::').constantize | |
| 10 | + def plugin | |
| 11 | + name.split('::')[0...-1].join('::').constantize | |
| 12 | + end | |
| 13 | + | |
| 14 | + def identifier | |
| 15 | + name.underscore | |
| 16 | + end | |
| 11 | 17 | end |
| 12 | 18 | |
| 13 | 19 | def initialize(context=nil) | ... | ... |
lib/noosfero/plugin/manager.rb
| ... | ... | @@ -66,7 +66,7 @@ class Noosfero::Plugin::Manager |
| 66 | 66 | |
| 67 | 67 | def enabled_macros |
| 68 | 68 | @enabled_macros ||= dispatch(:macros).inject({}) do |memo, macro| |
| 69 | - memo.merge!(macro.name.underscore => macro.new(context)) | |
| 69 | + memo.merge!(macro.identifier => macro.new(context)) | |
| 70 | 70 | end.merge('default' => Noosfero::Plugin::Macro.new(context)) |
| 71 | 71 | end |
| 72 | 72 | ... | ... |
test/unit/application_helper_test.rb
| ... | ... | @@ -678,8 +678,8 @@ class ApplicationHelperTest < ActiveSupport::TestCase |
| 678 | 678 | environment = Environment.default |
| 679 | 679 | environment.enable_plugin(Plugin1) |
| 680 | 680 | @plugins = Noosfero::Plugin::Manager.new(environment, self) |
| 681 | - macro1_name = Plugin1::Macro1.name.underscore | |
| 682 | - macro2_name = Plugin1::Macro2.name.underscore | |
| 681 | + macro1_name = Plugin1::Macro1.identifier | |
| 682 | + macro2_name = Plugin1::Macro2.identifier | |
| 683 | 683 | |
| 684 | 684 | html = " |
| 685 | 685 | <div class='macro nonEdit' data-macro='#{macro1_name}' data-macro-param='123'></div> | ... | ... |
test/unit/plugin_manager_test.rb
| ... | ... | @@ -190,8 +190,8 @@ class PluginManagerTest < ActiveSupport::TestCase |
| 190 | 190 | environment.enable_plugin(Plugin1) |
| 191 | 191 | macro = 'My name is %{name}!' |
| 192 | 192 | |
| 193 | - assert_equal 'My name is Macro1!', manager.parse_macro(Plugin1::Macro1.name.underscore, macro) | |
| 194 | - assert_equal 'My name is Macro2!', manager.parse_macro(Plugin1::Macro2.name.underscore, macro) | |
| 193 | + assert_equal 'My name is Macro1!', manager.parse_macro(Plugin1::Macro1.identifier, macro) | |
| 194 | + assert_equal 'My name is Macro2!', manager.parse_macro(Plugin1::Macro2.identifier, macro) | |
| 195 | 195 | end |
| 196 | 196 | |
| 197 | 197 | end | ... | ... |