Module: MenusHelper
- Defined in:
- app/helpers/menus_helper.rb
Instance Method Summary collapse
- #fetch_menu!(uid, locale) ⇒ Object
- #find_or_create_menu(uid, locale = nil) ⇒ Object
-
#link_url(link) ⇒ Object
= Deprecated Methods = ======================.
- #links(uid, options = {}) ⇒ Object
- #menu(uid, options = {}, &block) ⇒ Object
- #menu_link(link, options = {}) ⇒ Object
- #menu_link_url(link) ⇒ Object
-
#menu_links_for(menu, link_options = {}) ⇒ Object
= Private Methods = ===================.
- #nav_items_for(uid, locale = nil) ⇒ Object
- #render_menu(uid, options = nil, &block) ⇒ Object
Instance Method Details
#fetch_menu!(uid, locale) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/helpers/menus_helper.rb', line 101 def (uid, locale) query = Menu.where(:uid => uid.to_s) if locale query = query.where(:locale => locale.to_s) end = query.first raise "Menu '#{uid}' not found for locale '#{locale}'" if .nil? end |
#find_or_create_menu(uid, locale = nil) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/helpers/menus_helper.rb', line 54 def (uid, locale = nil) ActiveSupport::Deprecation.warn("This method is deprecated use 'menu(uid, :locale => locale_name)' instead") if locale Menu.find_or_create_by_uid_and_locale(uid, locale.to_s, :name => "#{uid}".gsub("-", "_").humanize) else Menu.find_or_create_by_uid(uid, :name => "#{uid}".gsub("-", "_").humanize) end end |
#link_url(link) ⇒ Object
Deprecated Methods =
49 50 51 52 |
# File 'app/helpers/menus_helper.rb', line 49 def link_url(link) ActiveSupport::Deprecation.warn("This method is deprecated use 'menu_link_url(link)' instead") (link) end |
#links(uid, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/menus_helper.rb', line 22 def links(uid, = {}) .reverse_merge!({:locale => Fullstack::Cms.localized? ? I18n.locale.to_s : nil }) locale = .delete(:locale) = (uid, locale) if block_given? yield(.links) "" else .links end end |
#menu(uid, options = {}, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/menus_helper.rb', line 3 def (uid, = {}, &block) .reverse_merge!({:locale => Fullstack::Cms.localized? ? I18n.locale.to_s : nil, :wrap => true}) locale = .delete(:locale) wrap = .delete(:wrap) = .delete(:wrapper_html) || {} = .delete(:link_html) || {} = (uid, locale) if wrap content_tag :ul, , false do (, ) end else (, ) end end |
#menu_link(link, options = {}) ⇒ Object
34 35 36 37 |
# File 'app/helpers/menus_helper.rb', line 34 def (link, = {}) .reverse_merge({:rel => link.nofollow ? "nofollow" : nil}) link_to(link.label, (link), ) end |
#menu_link_url(link) ⇒ Object
39 40 41 42 |
# File 'app/helpers/menus_helper.rb', line 39 def (link) return "#" unless link link.url.present? ? link.url : (link.linked ? page_path_for(link.linked) : "#") end |
#menu_links_for(menu, link_options = {}) ⇒ Object
Private Methods =
89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/helpers/menus_helper.rb', line 89 def (, = {}) html = "" .links.each do |link| unless block_given? html << content_tag(:li, (link, )) else html << yield(link) end end html.html_safe end |
#nav_items_for(uid, locale = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/menus_helper.rb', line 63 def nav_items_for(uid, locale = nil) ActiveSupport::Deprecation.warn("This method is deprecated use 'menu(uid, :locale => locale_name, :wrap => false)' instead") = (uid, locale) html = "" .links.each do |link| unless block_given? html << nav_item(link.label, link_url(link), :rel => link.nofollow ? "nofollow" : nil) else html << yield(link) end end html.html_safe end |
#render_menu(uid, options = nil, &block) ⇒ Object
80 81 82 83 |
# File 'app/helpers/menus_helper.rb', line 80 def (uid, = nil, &block) ActiveSupport::Deprecation.warn("This method is deprecated use 'menu(uid, :locale => locale_name)' instead") content_tag :ul, nav_items_for(uid, &block), , false end |