Module: RbbCode::TagNode
- Includes:
- RecursiveConversion
- Defined in:
- lib/rbbcode/node_extensions.rb
Constant Summary collapse
- TAG_MAPPINGS =
{'b' => 'strong', 'i' => 'em', 'u' => 'u', 'url' => URLTagNode, 'img' => ImgTagNode}
Instance Method Summary collapse
Methods included from RecursiveConversion
Instance Method Details
#contents ⇒ Object
95 96 97 98 99 |
# File 'lib/rbbcode/node_extensions.rb', line 95 def contents # The first element is the opening tag, the second is everything inside, # and the third is the closing tag. elements[1] end |
#inner_bbcode ⇒ Object
105 106 107 |
# File 'lib/rbbcode/node_extensions.rb', line 105 def inner_bbcode contents.elements.collect { |e| e.text_value }.join end |
#inner_html ⇒ Object
109 110 111 112 113 |
# File 'lib/rbbcode/node_extensions.rb', line 109 def inner_html contents.elements.collect do |node| recursively_convert(node) end.join end |
#tag_name ⇒ Object
101 102 103 |
# File 'lib/rbbcode/node_extensions.rb', line 101 def tag_name elements.first.text_value.slice(1..-2).downcase end |
#to_html ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/rbbcode/node_extensions.rb', line 115 def to_html t = TAG_MAPPINGS[tag_name] if t.nil? raise "No tag mapping found for #{tag_name}" elsif t.is_a?(Module) extend(t) send(tag_name + '_to_html') # Thus, if our tag_name is"url, and TAG_MAPPINGS points us to URLTagNode, # that module must define url_to_html. else "<#{t}>" + inner_html + "</#{t}>" end end |