Class: Docco::Parser::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/docco/parser/section.rb

Constant Summary collapse

HEADING_EXP =
/<\s*h([1-6])\b[^>]*>(.*?)<\/\s*h\1\s*>/im

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(converter:, node:) ⇒ Section

Returns a new instance of Section.



10
11
12
13
14
15
16
# File 'lib/docco/parser/section.rb', line 10

def initialize(converter:, node:)
  @converter = converter
  @node = node
  @id = node.attr['id']
  @options = node.options
  @nodes = []
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/docco/parser/section.rb', line 8

def id
  @id
end

#nodesObject (readonly)

Returns the value of attribute nodes.



8
9
10
# File 'lib/docco/parser/section.rb', line 8

def nodes
  @nodes
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/docco/parser/section.rb', line 8

def options
  @options
end

Instance Method Details

#<<(section) ⇒ Object



23
24
25
# File 'lib/docco/parser/section.rb', line 23

def <<(section)
  @nodes << section
end

#add_content(node) ⇒ Object



27
28
29
# File 'lib/docco/parser/section.rb', line 27

def add_content(node)
  @nodes << ContentNode.new(@converter, node)
end

#inspectObject



18
# File 'lib/docco/parser/section.rb', line 18

def inspect = %(<#{self.class}:H#{level}##{id} [#{nodes.size} nodes]>)

#levelObject



21
# File 'lib/docco/parser/section.rb', line 21

def level = @options[:level]

#section?Boolean

Returns:

  • (Boolean)


19
# File 'lib/docco/parser/section.rb', line 19

def section? = true

#titleObject



35
36
37
# File 'lib/docco/parser/section.rb', line 35

def title
  @title ||= title_html.match(HEADING_EXP)[2]
end

#title_htmlObject



31
32
33
# File 'lib/docco/parser/section.rb', line 31

def title_html
  @to_html ||= @converter.convert(@node, 0)
end

#to_htmlObject



39
40
41
42
43
# File 'lib/docco/parser/section.rb', line 39

def to_html
  @nodes.reduce(title_html) do |str, node|
    str << "\n" << node.to_html
  end
end