Class: MultipartErb::Formatter
- Inherits:
-
Object
- Object
- MultipartErb::Formatter
- Defined in:
- lib/multiparterb/formatter.rb
Class Method Summary collapse
- .lookup(child, formatter) ⇒ Object
- .parse(node, formatter) ⇒ Object
- .to_html(compiled_source) ⇒ Object
- .to_text(compiled_source) ⇒ Object
Class Method Details
.lookup(child, formatter) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/multiparterb/formatter.rb', line 25 def self.lookup(child, formatter) return child.text if child.name == 'text' parsed_text = parse(child, formatter).html_safe if SUPPORTED_TAG_METHODS.keys.include?(child.name) if child.name == 'a' formatter.public_send(SUPPORTED_TAG_METHODS[child.name], parsed_text, child.attributes['href'].content) else formatter.public_send(SUPPORTED_TAG_METHODS[child.name], parsed_text) end else parsed_text end end |
.parse(node, formatter) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/multiparterb/formatter.rb', line 17 def self.parse(node, formatter) "".tap do |result| node.children.each do |child| result << lookup(child, formatter) end end end |
.to_html(compiled_source) ⇒ Object
40 41 42 43 |
# File 'lib/multiparterb/formatter.rb', line 40 def self.to_html(compiled_source) html_doc = Nokogiri::HTML compiled_source parse html_doc, MultipartErb.html_formatter end |
.to_text(compiled_source) ⇒ Object
45 46 47 48 |
# File 'lib/multiparterb/formatter.rb', line 45 def self.to_text(compiled_source) html_doc = Nokogiri::HTML compiled_source parse html_doc, MultipartErb.text_formatter end |