Module: Ramaze::Helper::MenuFrontend
- Defined in:
- lib/zen/package/menus/lib/menus/helper/menu_frontend.rb
Overview
Helper that allows you to render navigation menus in your templates.
Instance Method Summary (collapse)
-
- (String) render_menu(menu, options = {})
Renders a navigation menu's items based on the menu slug or ID.
-
- (Object) render_menu_item(item, g, options = {})
private
Generates the HTML for a single menu item.
Instance Method Details
- (String) render_menu(menu, options = {})
Renders a navigation menu's items based on the menu slug or ID.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/zen/package/menus/lib/menus/helper/menu_frontend.rb', line 35 def (, = {}) = { :limit => 20, :sub => true, :order => :asc }.merge() = Menus::Model::Menu.find_by_pk_or_slug() items = Menus::Model::MenuItem \ .filter(:parent_id => nil, :menu_id => .id) \ .limit([:limit]) \ .order(:sort_order.send([:order])) \ .eager(:parent) \ .all g = Ramaze::Gestalt.new attrs = {} tree = {} if !.html_class.nil? and !.html_class.empty? attrs[:class] = .html_class end if !.html_id.nil? and !.html_id.empty? attrs[:id] = .html_id end # Build the HTML g.ul(attrs) do items.each do |item| if item.parent_id.nil? (item, g, ) end end end return g.to_s end |
- (Object) render_menu_item(item, g, options = {}) (private)
Generates the HTML for a single menu item.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/zen/package/menus/lib/menus/helper/menu_frontend.rb', line 86 def (item, g, = {}) attrs = {} if !item.html_class.nil? and !item.html_class.empty? attrs[:class] = item.html_class end if !item.html_id.nil? and !item.html_id.empty? attrs[:id] = item.html_id end g.li(attrs) do g.a(:href => item.url, :title => item.name) { item.name } # Render any sub menu items if [:sub] == true children = item.children if !children.empty? g.ul(:class => :children) do children.each { |child| (child, g, ) } end end end end end |