Class: Mail2FrontMatter::AutomaticEmbeds
- Inherits:
-
PreProcessor
- Object
- PreProcessor
- Mail2FrontMatter::AutomaticEmbeds
- Extended by:
- AutoHtml
- Defined in:
- lib/mail2frontmatter/automatic-embeds.rb
Class Method Summary collapse
Class Method Details
.register(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mail2frontmatter/automatic-embeds.rb', line 12 def self.register( = {}) super # I *could* introspect on auto_html here but I haven't vetted them all yet if [:white_list] @filters = [:white_list].map(&:to_sym) elsif [:black_list] @filters = @all_filters - [:black_list].map(&:to_sym) else @filters = @all_filters end end |
.run(metadata, body) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mail2frontmatter/automatic-embeds.rb', line 26 def self.run(, body) body = unwrap_links(body) body = auto_html(body, { filters: @filters, options: [:filters] }) { # use options passed to us... [:filters].each do |filter| = [:options] ? ([:options][filter.to_sym] || {}) : {} self.send(filter.to_sym, ) end # be sure to return @text here @text } return , body end |
.unwrap_links(body) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mail2frontmatter/automatic-embeds.rb', line 43 def self.unwrap_links(body) parsed_body = Nokogiri::HTML::DocumentFragment.parse(body) parsed_body.elements.css("a").each do |element| href = element.attributes["href"].value if href == element.inner_html body.gsub!(element.to_s, href) end end body end |