Class: Reacco::Extractor::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/reacco/extractor/block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Block

Returns a new instance of Block.



18
19
20
21
22
23
24
25
26
27
# File 'lib/reacco/extractor/block.rb', line 18

def initialize(options)
  @body        = options[:body]
  @type        = options[:type] && options[:type].downcase
  @args        = options[:args]
  @title       = options[:title]
  @parent      = options[:parent]
  @tag         = options[:tag]
  @source_line = options[:source_line]
  @source_path = options[:source_path]
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



16
17
18
# File 'lib/reacco/extractor/block.rb', line 16

def args
  @args
end

#bodyObject (readonly)

body [method] Returns the body text as a raw string.



9
10
11
# File 'lib/reacco/extractor/block.rb', line 9

def body
  @body
end

#parentObject (readonly)

Returns the value of attribute parent.



15
16
17
# File 'lib/reacco/extractor/block.rb', line 15

def parent
  @parent
end

#titleObject (readonly)

title [method] Returns the title of the block.



13
14
15
# File 'lib/reacco/extractor/block.rb', line 13

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/reacco/extractor/block.rb', line 14

def type
  @type
end

Instance Method Details

#<<(blk) ⇒ Object

<< [method] Adds a block to it’s children.



37
38
39
# File 'lib/reacco/extractor/block.rb', line 37

def <<(blk)
  children << blk
end

#childrenObject

children [method] Returns an array of child blocks.



31
32
33
# File 'lib/reacco/extractor/block.rb', line 31

def children
  @children ||= Array.new
end

#docObject

Nokogiri node.



46
47
48
# File 'lib/reacco/extractor/block.rb', line 46

def doc
  @doc ||= Nokogiri::HTML(raw_html)
end

#raw_htmlObject



41
42
43
# File 'lib/reacco/extractor/block.rb', line 41

def raw_html
  Reacco.markdown.render(@body)
end

#to_htmlObject

to_html [method] Returns the raw HTML to be included in the documentation.



79
80
81
# File 'lib/reacco/extractor/block.rb', line 79

def to_html
  @to_html ||= transform!.at_css('body').inner_html
end

#transform!Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/reacco/extractor/block.rb', line 50

def transform!
  # Create heading.
  name = @tag
  node = Nokogiri::XML::Node.new(name, doc)
  node['class'] = 'api'
  node.content  = title

  # Add '(args)'.
  if args
    span = Nokogiri::XML::Node.new("span", doc)
    span['class'] = 'args'
    span.content = args
    node.add_child span
  end

  # Add '(class method)'.
  span = Nokogiri::XML::Node.new("span", doc)
  span['class'] = 'type'
  span.content = type
  node.add_child Nokogiri::XML::Text.new(' ', doc)
  node.add_child span

  # Add heading.
  doc.at_css('body>*:first-child').add_previous_sibling node
  doc
end