# Set of helpers to display the navigation sidebar
module SidebarHelpers
def section_helper title: nil, selector: nil
sect = Toc.instance.section(selector)
@sect_def = Toc.instance.section_def(selector)
str = "
"
str += sect.has_subsections? ? nested_section(sect) : flat_section(sect)
str + ""
end
def nested_section sect
sect.subsections.reduce("") {|acc, subs| acc + subsection_body(subs)}
end
def subsection_body sect
"
-
#{subsection(sect, sect.content.collapsed?)}
"
end
def collapsed_indicator(coll)
icon_markup(coll ? :plus : :minus)
end
def subsection(subsect, collapsed)
disp_clause = collapsed ? "display: none" : "display: block"
str = ""
str = subsect.children.reduce(str) { |acc, item| acc + subsection_item_link(item) }
str + "
"
end
def subsection_item_link tree_node
bullet = @sect_def.options[:bullet]
link_path = @items[tree_node.content.identifier].path
"#{icon_markup(bullet)}#{tree_node.content.title}"
end
def flat_section sect
disp_clause = sect.collapsed? ? "display: none" : "display: block"
str = ""
str = sect.reduce(str) { |acc, item| acc + flat_section_item_link(item) }
str + "
"
end
def flat_section_item_link citem
bullet = @sect_def.options[:bullet]
path = @items[citem.identifier].path
"#{icon_markup(bullet)}#{citem.title}"
end
def icon_markup icon_type
return "" if icon_type.nil?
css_class = {dash: "glyphicon-minus", star: "glyphicon-star", plus: "glyphicon-plus-sign", minus: "glyphicon-minus-sign"}.fetch(icon_type)
""
end
end