Class: TextFilterPlugin::Macro
- Inherits:
-
TextFilterPlugin
- Object
- TextFilterPlugin
- TextFilterPlugin::Macro
- Defined in:
- lib/text_filter_plugin.rb
Class Method Summary collapse
-
.attributes_parse(string) ⇒ Object
Utility function – hand it a XML string like <a href=“foo” title=“bar”> and it’ll give you back { “href” => “foo”, “title” => “bar” }.
- .filtertext(text) ⇒ Object
Methods inherited from TextFilterPlugin
available_filter_types, available_filters, component_name, config_value, default_config, default_helper_module!, filter_map, filter_type, help_text, inherited, logger, macro_filters, reloadable?, sanitize, short_name
Methods included from PublifyPlugins
#plugin_description, #plugin_display_name, #plugin_public_action, #plugin_public_actions
Class Method Details
.attributes_parse(string) ⇒ Object
Utility function – hand it a XML string like <a href=“foo” title=“bar”> and it’ll give you back { “href” => “foo”, “title” => “bar” }
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/text_filter_plugin.rb', line 109 def self.attributes_parse(string) attributes = {} string.gsub(/([^ =]+="[^"]*")/) do |match| key, value = match.split(/=/, 2) attributes[key] = value.delete('"') end string.gsub(/([^ =]+='[^']*')/) do |match| key, value = match.split(/=/, 2) attributes[key] = value.delete("'") end attributes end |
.filtertext(text) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/text_filter_plugin.rb', line 125 def self.filtertext(text) regex1 = %r{<publify:#{short_name}(?:[ \t][^>]*)?/>} regex2 = %r{<publify:#{short_name}([ \t][^>]*)?>(.*?)</publify:#{short_name}>}m new_text = text.gsub(regex1) do |match| macrofilter(attributes_parse(match)) end new_text.gsub(regex2) do |_match| macrofilter(attributes_parse(Regexp.last_match[1].to_s), Regexp.last_match[2].to_s) end end |