cirandas.net

ref: master

plugins/variables/lib/variables_plugin/macros/profile.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# FIXME See a better way to generalize this parameter.
Loofah::HTML5::WhiteList::ALLOWED_ATTRIBUTES.merge %w[data-macro]

class VariablesPlugin::Profile < Noosfero::Plugin::Macro

  def self.configuration
    {
      :title => _('Variables'),
      :skip_dialog => false,
      :generator => method(:macro_default_generator),
      :params => [
        {
          :name   => 'variable',
          :label  => _('Select the desired variable'),
          :type   => 'select',
          :values => ['{profile}', '{name}']
        }
      ],
    }
  end

  def self.macro_default_generator(macro)
    "
      '<div class=\"macro mceNonEditable\" data-macro=\"#{macro.identifier}\">'
      + jQuery('*[name=variable]', dialog).val()
      + '</div>';
    "
  end

  def parse(params, inner_html, source)
    if context.profile
      inner_html.gsub!(/\{profile\}/, context.profile.identifier)
      inner_html.gsub!(/\{name\}/, context.profile.name)
    end
    inner_html
  end

end