Commit 04962ef3e6cfc8c5c86179aaa1d039ffbf1b6bc6

Authored by Rodrigo Souto
2 parents 9630fd21 419bcf2a

Merge branch 'parse-everything' into stable

app/helpers/application_helper.rb
... ... @@ -1401,7 +1401,7 @@ module ApplicationHelper
1401 1401 end
1402 1402  
1403 1403 def filter_html(html, source)
1404   - if @plugins
  1404 + if @plugins && source.has_macro?
1405 1405 html = convert_macro(html, source)
1406 1406 #TODO This parse should be done through the macro infra, but since there
1407 1407 # are old things that do not support it we are keeping this hot spot.
... ...
app/helpers/boxes_helper.rb
... ... @@ -100,9 +100,7 @@ module BoxesHelper
100 100 options[:title] = _("This block is invisible. Your visitors will not see it.")
101 101 end
102 102  
103   - if @controller.send(:content_editor?)
104   - result = filter_html(result, block)
105   - end
  103 + result = filter_html(result, block)
106 104  
107 105 box_decorator.block_target(block.box, block) +
108 106 content_tag('div',
... ...
app/models/article.rb
... ... @@ -673,6 +673,10 @@ class Article < ActiveRecord::Base
673 673  
674 674 delegate :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true
675 675  
  676 + def has_macro?
  677 + true
  678 + end
  679 +
676 680 private
677 681  
678 682 def sanitize_tag_list
... ...
app/models/block.rb
... ... @@ -138,4 +138,8 @@ class Block < ActiveRecord::Base
138 138 4.hours
139 139 end
140 140  
  141 + def has_macro?
  142 + false
  143 + end
  144 +
141 145 end
... ...
app/models/raw_html_block.rb
... ... @@ -10,4 +10,7 @@ class RawHTMLBlock < Block
10 10 (title.blank? ? '' : block_title(title)).html_safe + html.to_s.html_safe
11 11 end
12 12  
  13 + def has_macro?
  14 + true
  15 + end
13 16 end
... ...
test/unit/application_helper_test.rb
... ... @@ -791,6 +791,29 @@ class ApplicationHelperTest < ActiveSupport::TestCase
791 791 '<br style=\'clear: left;\' /></div>', result
792 792 end
793 793  
  794 + should 'not filter html if source does not have macros' do
  795 + class Plugin1 < Noosfero::Plugin
  796 + end
  797 +
  798 + class Plugin1::Macro1 < Noosfero::Plugin::Macro
  799 + def parse(params, inner_html, source)
  800 + 'Test1'
  801 + end
  802 + end
  803 +
  804 + environment = Environment.default
  805 + environment.enable_plugin(Plugin1)
  806 + @plugins = Noosfero::Plugin::Manager.new(environment, self)
  807 + macro1_name = Plugin1::Macro1.identifier
  808 + source = mock
  809 + source.stubs(:has_macro?).returns(false)
  810 +
  811 + html = "<div class='macro nonEdit' data-macro='#{macro1_name}' data-macro-param='123'></div>"
  812 + parsed_html = filter_html(html, source)
  813 +
  814 + assert_no_match /Test1/, parsed_html
  815 + end
  816 +
794 817 protected
795 818 include NoosferoTestHelper
796 819  
... ...