Class: RKit::Parser::Leaf

Inherits:
Object show all
Defined in:
lib/r_kit/parser/leaf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, frame:) ⇒ Leaf

Returns a new instance of Leaf.



5
6
7
8
9
10
# File 'lib/r_kit/parser/leaf.rb', line 5

def initialize raw, frame:;
  @raw = raw
  @frame = frame
  @tag, @attributes, @content = parse_blocks
  @attributes ||= {}
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/r_kit/parser/leaf.rb', line 3

def attributes
  @attributes
end

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/r_kit/parser/leaf.rb', line 3

def content
  @content
end

#frameObject

Returns the value of attribute frame.



3
4
5
# File 'lib/r_kit/parser/leaf.rb', line 3

def frame
  @frame
end

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/r_kit/parser/leaf.rb', line 3

def raw
  @raw
end

#tagObject

Returns the value of attribute tag.



3
4
5
# File 'lib/r_kit/parser/leaf.rb', line 3

def tag
  @tag
end

Instance Method Details

#parsedObject



12
13
14
15
16
17
18
19
20
# File 'lib/r_kit/parser/leaf.rb', line 12

def parsed
  if content && tag
    "<#{ tag } #{ attributes.map{|k,v| "#{k}='#{v}'"}.join }>#{ parsed_content }</#{ tag }>"
  elsif tag
    "<#{ tag } #{ attributes.map{|k,v| "#{k}='#{v}'"}.join }/>"
  elsif content
    content
  end
end

#parsed_contentObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/r_kit/parser/leaf.rb', line 22

def parsed_content
  Array(content)
    .map{ |c|
      case c
      when String
        parse_inlines
      when RKit::Parser::Leaf
        c.parsed
      end
    }
    .join("")
end