class Juli::Visitor::Html::IdAssigner

assign DOM id on header node.

IdAssigner should be executed before running Html visitor since ContentsDrawer also refers DOM id. That is the reason why DOM id assignment is isolated from Html visitor.

Public Class Methods

new(opts={}) click to toggle source
Calls superclass method Juli::Absyn::Visitor::new
# File lib/juli/visitor/html.rb, line 30
def initialize(opts={})
  super
  @uniq_id_seed   = 0
end

Public Instance Methods

run(in_file, root) click to toggle source
# File lib/juli/visitor/html.rb, line 40
def run(in_file, root)
  root.accept(self)
end
visit_chapter(n) click to toggle source
# File lib/juli/visitor/html.rb, line 35
def visit_chapter(n)
  n.dom_id = uniq_id(n.level)
  n.blocks.accept(self)
end

Private Instance Methods

uniq_id(level) click to toggle source

generate uniq_id, and track it for each level to be used later

# File lib/juli/visitor/html.rb, line 46
def uniq_id(level)
  @uniq_id_seed += 1
  result = sprintf("j%05d", @uniq_id_seed)
  result
end