class PseudoHiki::PageComposer::HtmlComposer

Constants

TABLE

Public Class Methods

new(options) click to toggle source
# File lib/pseudohiki/converter.rb, line 52
def initialize(options)
  super(options)
  @link_manager = setup_link_manager(options)
  @relative_link = options[:relative_link]
end

Public Instance Methods

compose_body(tree) click to toggle source
# File lib/pseudohiki/converter.rb, line 58
def compose_body(tree)
  super(tree).tap do |html|
    if @relative_link and @link_manager
      @link_manager.use_relative_path_for_in_domain_links(html)
    end

    assign_table_header_scope(html) if @options[:accessibility]
  end
end
create_main(toc, body, h1) click to toggle source
# File lib/pseudohiki/converter.rb, line 78
def create_main(toc, body, h1)
  return nil unless @options[:toc]
  main = formatter.create_element("section").tap do |element|
    element["id"] = "main"
    element.push h1 unless h1.empty?
    element.push create_toc_container(toc)
    element.push create_contents_container(body)
  end
end
create_table_of_contents(tree) click to toggle source
# File lib/pseudohiki/converter.rb, line 68
def create_table_of_contents(tree)
  @options.formatter.format(create_toc_tree(tree)).tap do |toc|
    toc.traverse do |element|
      if element.kind_of? HtmlElement and element.tagname == "a"
        element["title"] = "toc_item: " + element.children.join.chomp
      end
    end
  end
end

Private Instance Methods

assign_table_header_scope(html) click to toggle source
# File lib/pseudohiki/converter.rb, line 98
def assign_table_header_scope(html)
  HtmlElement::Utils.collect_elements_by_name(html, TABLE).each do |table|
    HtmlElement::Utils::TableManager.assign_scope(table)
  end
end
create_contents_container(body) click to toggle source
# File lib/pseudohiki/converter.rb, line 127
def create_contents_container(body)
  formatter.create_element("section").tap do |elm|
    elm["id"] = "contents"
    elm.push body
  end
end
create_toc_container(toc) click to toggle source
# File lib/pseudohiki/converter.rb, line 118
def create_toc_container(toc)
  formatter.create_element("section").tap do |elm|
    elm["id"] = "toc"
    title = @options[:toc]
    elm.push formatter.create_element("h2", title) unless title.empty?
    elm.push toc
  end
end
create_toc_tree(tree, newline=nil) click to toggle source
# File lib/pseudohiki/converter.rb, line 108
def create_toc_tree(tree, newline=nil)
  toc_lines = collect_nodes_for_table_of_contents(tree).map do |line|
    format("%s[[%s|#%s]]#{newline}",
           '*' * line.level,
           to_plain(line).lstrip,
           line.node_id.upcase)
  end
  BlockParser.parse(toc_lines)
end
formatter() click to toggle source
# File lib/pseudohiki/converter.rb, line 104
def formatter
  @formatter ||= @options.html_template.new
end