Module: SidebarHelpers
- Defined in:
- lib/coursegen/course/helpers/sidebar_helpers.rb
Overview
SidebarHelpers is a set of helpers to display the navigation sidebar.
Instance Method Summary collapse
- #collapsed_indicator(coll) ⇒ Object
- #flat_section(sect) ⇒ Object
- #flat_section_item_link(citem) ⇒ Object
- #icon_markup(icon_type) ⇒ Object
- #nested_section(sect) ⇒ Object
- #section_helper(title: nil, selector: nil) ⇒ Object
- #subsection(subsect, collapsed) ⇒ Object
- #subsection_body(sect) ⇒ Object
- #subsection_item_link(tree_node) ⇒ Object
Instance Method Details
#collapsed_indicator(coll) ⇒ Object
31 32 33 |
# File 'lib/coursegen/course/helpers/sidebar_helpers.rb', line 31 def collapsed_indicator(coll) icon_markup(coll ? :plus : :minus) end |
#flat_section(sect) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/coursegen/course/helpers/sidebar_helpers.rb', line 48 def flat_section(sect) disp_clause = sect.collapsed? ? 'display: none' : 'display: block' str = "<ul class=\"tree\" style=\"#{disp_clause}\">" str = sect.reduce(str) { |acc, item| acc + flat_section_item_link(item) } str + '</ul>' end |
#flat_section_item_link(citem) ⇒ Object
55 56 57 58 59 |
# File 'lib/coursegen/course/helpers/sidebar_helpers.rb', line 55 def flat_section_item_link(citem) bullet = @sect_def.[:bullet] path = @items[citem.identifier].path "<li class=\"#{citem.css_class}\">#{icon_markup(bullet)}<a href=\"#{path}\">#{citem.title}</a></li>" end |
#icon_markup(icon_type) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/coursegen/course/helpers/sidebar_helpers.rb', line 61 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) "<span class=\"glyphicon #{css_class}\" style=#{STYLING_CONFIG[:bullet_style]}></span>" end |
#nested_section(sect) ⇒ Object
15 16 17 |
# File 'lib/coursegen/course/helpers/sidebar_helpers.rb', line 15 def nested_section(sect) sect.subsections.reduce('') { |acc, subs| acc + subsection_body(subs) } end |
#section_helper(title: nil, selector: nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/coursegen/course/helpers/sidebar_helpers.rb', line 3 def section_helper(title: nil, selector: nil) sect = Toc.instance.section(selector) @sect_def = Toc.instance.section_def(selector) str = "<li> <label class=\"tree-toggler level1\"> #{collapsed_indicator(sect.collapsed?)} #{title} </label> #{sect.has_subsections? ? nested_section(sect) : flat_section(sect)} </li>" end |
#subsection(subsect, collapsed) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/coursegen/course/helpers/sidebar_helpers.rb', line 35 def subsection(subsect, collapsed) disp_clause = collapsed ? 'display: none' : 'display: block' str = "<ul class=\"tree\" style=\"#{disp_clause}\">" str = subsect.children.reduce(str) { |acc, item| acc + subsection_item_link(item) } str + '</ul>' end |
#subsection_body(sect) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/coursegen/course/helpers/sidebar_helpers.rb', line 19 def subsection_body(sect) "<ul class=\"tree\"> <li> <label class=\"tree-toggler level2\"> #{collapsed_indicator(sect.content.collapsed?)} #{sect.content.title} </label> #{subsection(sect, sect.content.collapsed?)} </li> </ul>" end |
#subsection_item_link(tree_node) ⇒ Object
42 43 44 45 46 |
# File 'lib/coursegen/course/helpers/sidebar_helpers.rb', line 42 def subsection_item_link(tree_node) bullet = @sect_def.[:bullet] link_path = @items[tree_node.content.identifier].path "<li class=\"#{tree_node.content.css_class}\">#{icon_markup(bullet)}<a href=\"#{link_path}\">#{tree_node.content.title}</a></li>" end |