Noosfero/noosfero

View on GitHub
plugins/variables/lib/variables_plugin/macros/profile.rb

Summary

Maintainability
A
0 mins
Test Coverage
# 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