Class: Docco::Builder
- Inherits:
-
Object
- Object
- Docco::Builder
- Defined in:
- lib/docco/builder.rb
Defined Under Namespace
Classes: SectionBuilder
Instance Attribute Summary collapse
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#to_path ⇒ Object
readonly
Returns the value of attribute to_path.
Instance Method Summary collapse
- #build(*args) ⇒ Object
-
#initialize(nodes:, info:, root: self) ⇒ Builder
constructor
A new instance of Builder.
- #link(node, template, path) ⇒ Object
- #to_html ⇒ Object
- #visit(theme) ⇒ Object
Constructor Details
#initialize(nodes:, info:, root: self) ⇒ Builder
Returns a new instance of Builder.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/docco/builder.rb', line 38 def initialize(nodes:, info:, root: self) @to_path = '' @path = [@to_path].freeze @nodes = nodes.map do |n| wrap_node(n, @path) end @sections = @nodes.filter(&:section?) @info = info @root = root @pages = {} end |
Instance Attribute Details
#info ⇒ Object (readonly)
Returns the value of attribute info.
36 37 38 |
# File 'lib/docco/builder.rb', line 36 def info @info end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
36 37 38 |
# File 'lib/docco/builder.rb', line 36 def nodes @nodes end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
36 37 38 |
# File 'lib/docco/builder.rb', line 36 def pages @pages end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
36 37 38 |
# File 'lib/docco/builder.rb', line 36 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
36 37 38 |
# File 'lib/docco/builder.rb', line 36 def root @root end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
36 37 38 |
# File 'lib/docco/builder.rb', line 36 def sections @sections end |
#to_path ⇒ Object (readonly)
Returns the value of attribute to_path.
36 37 38 |
# File 'lib/docco/builder.rb', line 36 def to_path @to_path end |
Instance Method Details
#build(*args) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/docco/builder.rb', line 66 def build(*args) case args in [template] link self, template, to_path in [String => path, template] link self, template, path end end |
#link(node, template, path) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/docco/builder.rb', line 53 def link(node, template, path) return path if @pages.key?(path) @pages[path] = true content = template.(node) @pages[path] = content path end |
#to_html ⇒ Object
51 |
# File 'lib/docco/builder.rb', line 51 def to_html = @nodes.reduce(+'') { |str, n| str << n.to_html } |
#visit(theme) ⇒ Object
62 63 64 |
# File 'lib/docco/builder.rb', line 62 def visit(theme) link self, theme, to_path end |