Class: Reacco::Extractor::Block
- Inherits:
-
Object
- Object
- Reacco::Extractor::Block
- Defined in:
- lib/reacco/extractor/block.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#body ⇒ Object
readonly
body [method] Returns the body text as a raw string.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#title ⇒ Object
readonly
title [method] Returns the title of the block.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#<<(blk) ⇒ Object
<< [method] Adds a block to it’s children.
-
#children ⇒ Object
children [method] Returns an array of child blocks.
-
#doc ⇒ Object
Nokogiri node.
-
#initialize(options) ⇒ Block
constructor
A new instance of Block.
- #raw_html ⇒ Object
-
#to_html ⇒ Object
to_html [method] Returns the raw HTML to be included in the documentation.
- #transform! ⇒ Object
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() @body = [:body] @type = [:type] && [:type].downcase @args = [:args] @title = [:title] @parent = [:parent] @tag = [:tag] @source_line = [:source_line] @source_path = [:source_path] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
16 17 18 |
# File 'lib/reacco/extractor/block.rb', line 16 def args @args end |
#body ⇒ Object (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 |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
15 16 17 |
# File 'lib/reacco/extractor/block.rb', line 15 def parent @parent end |
#title ⇒ Object (readonly)
title [method] Returns the title of the block.
13 14 15 |
# File 'lib/reacco/extractor/block.rb', line 13 def title @title end |
#type ⇒ Object (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 |
#children ⇒ Object
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 |
#doc ⇒ Object
Nokogiri node.
46 47 48 |
# File 'lib/reacco/extractor/block.rb', line 46 def doc @doc ||= Nokogiri::HTML(raw_html) end |
#raw_html ⇒ Object
41 42 43 |
# File 'lib/reacco/extractor/block.rb', line 41 def raw_html Reacco.markdown.render(@body) end |
#to_html ⇒ Object
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 |