class RTFDoc::Template

Attributes

app_name[R]
page_title[R]

Public Class Methods

new(nodes, config) click to toggle source
# File lib/rtfdoc.rb, line 134
def initialize(nodes, config)
  @content      = nodes.flat_map(&:output).join
  # @menu_content = nodes.map(&:menu_output).join
  @app_name     = config['app_name']
  @page_title   = config['title']

  generate_grouped_menu_content(nodes)
end

Public Instance Methods

output() click to toggle source
# File lib/rtfdoc.rb, line 143
def output
  template = Erubi::Engine.new(File.read(File.expand_path('../src/index.html.erb', __dir__)))
  eval(template.src)
end

Private Instance Methods

generate_grouped_menu_content(nodes) click to toggle source

Transform a list of nodes into a list of groups. If all nodes already are groups, it will return the same list. Otherwise, it will build group from consecutives single resources.

# File lib/rtfdoc.rb, line 152
def generate_grouped_menu_content(nodes)
  i   = 0
  res = []

  while i < nodes.length
    node = nodes[i]
    if node.is_a?(Group)
      res << node
      i += 1
    else
      inner = []
      j = i
      while node && !node.is_a?(Group)
        inner << node
        j += 1
        node = nodes[j]
      end

      res << Group.new(nil, inner)
      i = j
    end
  end

  @menu_content = res.map(&:menu_output).join
end