class Mail2FrontMatter::AutomaticEmbed
Public Class Methods
register(options = {})
click to toggle source
Calls superclass method
# File lib/mail2frontmatter/automatic-embeds.rb, line 13 def self.register(options = {}) super # I *could* introspect on auto_html here but I haven't vetted them all yet if @options[:white_list] @filters = @options[:white_list].map(&:to_sym) elsif @options[:black_list] @filters = @all_filters - @options[:black_list].map(&:to_sym) else @filters = @all_filters end end
run(metadata, body)
click to toggle source
# File lib/mail2frontmatter/automatic-embeds.rb, line 27 def self.run(metadata, body) body = unwrap_links(body) body = auto_html(body, { filters: @filters, options: @options[:filters] }) { # use options passed to us... @options[:filters].each do |filter| options_for_filter = @options[:options] ? (@options[:options][filter.to_sym] || {}) : {} self.send(filter.to_sym, options_for_filter) end # be sure to return @text here @text } return metadata, body end
unwrap_links(body)
click to toggle source
# File lib/mail2frontmatter/automatic-embeds.rb, line 44 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