Class: Docco::Builder

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

Defined Under Namespace

Classes: SectionBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#infoObject (readonly)

Returns the value of attribute info.



36
37
38
# File 'lib/docco/builder.rb', line 36

def info
  @info
end

#nodesObject (readonly)

Returns the value of attribute nodes.



36
37
38
# File 'lib/docco/builder.rb', line 36

def nodes
  @nodes
end

#pagesObject (readonly)

Returns the value of attribute pages.



36
37
38
# File 'lib/docco/builder.rb', line 36

def pages
  @pages
end

#pathObject (readonly)

Returns the value of attribute path.



36
37
38
# File 'lib/docco/builder.rb', line 36

def path
  @path
end

#rootObject (readonly)

Returns the value of attribute root.



36
37
38
# File 'lib/docco/builder.rb', line 36

def root
  @root
end

#sectionsObject (readonly)

Returns the value of attribute sections.



36
37
38
# File 'lib/docco/builder.rb', line 36

def sections
  @sections
end

#to_pathObject (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


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_htmlObject



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