Class: RubyBBCode::TagCollection

Inherits:
Array
  • Object
show all
Defined in:
lib/ruby-bbcode-to-md/tag_collection.rb

Overview

This class holds TagNodes and helps build them into html when the time comes. It’s really just a simple array, with the addition of the #to_html method

Defined Under Namespace

Classes: HtmlTemplate

Instance Method Summary collapse

Instance Method Details

#to_html(tags) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby-bbcode-to-md/tag_collection.rb', line 5

def to_html(tags)
  html_string = ""
  self.each do |node|
    if node.type == :tag
      t = HtmlTemplate.new node
      
      t.inlay_between_text!
      
      if node.allow_tag_param? and node.param_set?
        t.inlay_inline_params!
      elsif node.allow_tag_param? and node.param_not_set?
        t.remove_unused_tokens!
      end
      
      html_string += t.opening_html
      
      # invoke "recursive" call if this node contains child nodes
      html_string += node.children.to_html(tags) if node.has_children?
      
      t.inlay_closing_html!
      
      html_string += t.closing_html
    elsif node.type == :text
      html_string += node[:text] unless node[:text].nil?
    end
  end
  
  html_string
end