Module: EffectiveMenusHelper
- Defined in:
- app/helpers/effective_menus_helper.rb
Instance Method Summary collapse
- #admin_menu_parent_collection(page = nil) ⇒ Object
- #breadcrumbs_fallback(page = @page, root: 'Home') ⇒ Object
- #breadcrumbs_root_url(page = @page, root: 'Home') ⇒ Object
- #render_breadcrumbs(menu, page = @page, root: 'Home') ⇒ Object (also: #render_breadcrumb)
- #render_menu(name, options = {}, &block) ⇒ Object
- #render_page_menu(page, options = {}, &block) ⇒ Object
Instance Method Details
#admin_menu_parent_collection(page = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/effective_menus_helper.rb', line 60 def (page = nil) raise('expected a page') if page.present? && !page.kind_of?(Effective::Page) pages = Effective::Page...root_level.where.not(id: page) if EffectivePages. == 2 # You can only select root level pages pages.group_by(&:menu_name) elsif EffectivePages. == 3 # You can only select root level pages and immediate children pages.map do |page| [[page.to_s, page.id, page.]] + page..map do |child| label = content_tag(:div) do arrow = "→" group = content_tag(:span, child., class: 'badge badge-info') if child..present? title = child. [arrow, group, title].compact.join(' ').html_safe end [child.to_s, child.id, { 'data-html': label }, child.] end end.flatten(1).group_by(&:last) end end |
#breadcrumbs_fallback(page = @page, root: 'Home') ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/effective_menus_helper.rb', line 49 def (page = @page, root: 'Home') label = (page if page.kind_of?(Effective::Page)) || @page_title || 'Here' content_tag(:ol, class: 'breadcrumb') do [ content_tag(:li, link_to(root, root_path, title: root), class: 'breadcrumb-item'), content_tag(:li, label, class: 'breadcrumb-item active', 'aria-current': 'page') ].join.html_safe end end |
#breadcrumbs_root_url(page = @page, root: 'Home') ⇒ Object
43 44 45 46 47 |
# File 'app/helpers/effective_menus_helper.rb', line 43 def (page = @page, root: 'Home') content_tag(:ol, class: 'breadcrumb') do content_tag(:li, root, class: 'breadcrumb-item active', 'aria-current': 'page') end end |
#render_breadcrumbs(menu, page = @page, root: 'Home') ⇒ Object Also known as:
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/effective_menus_helper.rb', line 21 def (, page = @page, root: 'Home') return (page, root: root) if request.path == '/' return (page, root: root) unless page.kind_of?(Effective::Page) parents = [page.&., page.].compact content_tag(:ol, class: 'breadcrumb') do ( [content_tag(:li, link_to(root, root_path, title: root), class: 'breadcrumb-item')] + parents.map do |page| next if page. # Don't show root pages because they have no content url = (page..presence || effective_pages.page_path(page)) content_tag(:li, link_to(page, url, title: page.title), class: 'breadcrumb-item') end + [content_tag(:li, page, class: 'breadcrumb-item active', 'aria-current': 'page')] ).join.html_safe end end |
#render_menu(name, options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/effective_menus_helper.rb', line 4 def (name, = {}, &block) name = name.to_s = Array(EffectivePages.).find { || .to_s == name } if .blank? raise("unable to find menu #{name}. Please add it to config/initializers/effective_pages.rb") end content_tag(:ul, ) { render('effective/pages/menu', menu: ) } end |
#render_page_menu(page, options = {}, &block) ⇒ Object
15 16 17 18 19 |
# File 'app/helpers/effective_menus_helper.rb', line 15 def (page, = {}, &block) raise('expected a page with menu true') unless page.kind_of?(Effective::Page) && page. content_tag(:ul, ) { render('effective/pages/page_menu', page: page) } end |