Module: SiteMenusHelper
- Defined in:
- app/helpers/site_menus_helper.rb
Overview
:nodoc:
Instance Method Summary (collapse)
- - (Object) build_submenu_box(menu, &block)
- - (Object) close_submenu(menu)
- - (Object) current_root(view_context)
-
- (Boolean) current_root_menu_include?(menu)
Is path included in any current_root’s path?.
- - (Boolean) current_root_menu_include_path?(path)
- - (Boolean) current_root_path_include?(menu)
-
- (Object) menu_link_to(name, path, options = {})
if the link is a link to the current-page display it with a different css-class to inform the user about ‘here you are’.
-
- (Object) root_menus_including(menu)
Detect the root-menu-items including ‘path’.
- - (Object) site_menu_manage_buttons(menu)
- - (Object) submenu_header(menu)
- - (Object) submenu_margin_left
- - (Object) submenus(upto = 4)
Instance Method Details
60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/site_menus_helper.rb', line 60 def (,&block) = .first if .is_a?(Mongoid::Criteria) if && .target && (.role_needed||0) <= current_role yield( () ) + .children.map { |child| raw( (child,&block) ) }.join("") + () end end |
106 107 108 |
# File 'app/helpers/site_menus_helper.rb', line 106 def () .children.any? ? "</ul>" : "" end |
- (Object) current_root(view_context)
87 88 89 90 91 92 93 94 |
# File 'app/helpers/site_menus_helper.rb', line 87 def current_root(view_context) SiteMenu.roots.each do |root| if root.current_child?(view_context) Rails.logger.info("******** CURRENT ROOT = #{root.target} ****** ") return root end end end |
Is path included in any current_root’s path?
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/site_menus_helper.rb', line 19 def () begin if current_root(self) current_root(self).traverse(:depth_first) do || @current_root = if && && current_page?(.target) && .target[0] != '#' end end rescue => e Rails.logger.info("** NO ROOT PATH FOUND #{e.inspect}") return false end @current_root != nil end |
45 46 47 48 49 |
# File 'app/helpers/site_menus_helper.rb', line 45 def (path) return true if current_page?(path) && path[0] != '#' search_item = SiteMenu.where(:target => path).first (search_item) end |
- (Boolean) current_root_path_include?(menu)
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/site_menus_helper.rb', line 33 def current_root_path_include?() = [] .traverse { |m| << m if current_page?(m.target) && && .target && .target[0] != '#' } .ancestors.each do |anc| << anc if current_page?(anc.target) && .target[0] != '#' end .compact! .any? end |
if the link is a link to the current-page display it with a different css-class to inform the user about ‘here you are’.
53 54 55 56 57 58 |
# File 'app/helpers/site_menus_helper.rb', line 53 def (name,path,={}) style = "hmenu" style = "hmenu_current" if current_page?(path) .merge!( { :class => style } ) link_to( name, path, ) end |
Detect the root-menu-items including ‘path’
8 9 10 11 12 13 14 |
# File 'app/helpers/site_menus_helper.rb', line 8 def () = [] SiteMenu.roots.each do |root| << root if root.current_child?(self) end .flatten.uniq.compact end |
110 111 112 113 114 115 116 |
# File 'app/helpers/site_menus_helper.rb', line 110 def () ("<span style='height: 10px; vertical-align: middle;'>" + ( 'edit',t(:edit), ()) + sc(:nbsp) + ( 'delete',t(:delete), , :method => :delete, :confirm => t(:are_you_sure)) + sc(:nbsp) + ( 'add', t(:add_submenu_item), (:parent => .to_param)) + "</span>").html_safe end |
96 97 98 99 100 101 102 103 104 |
# File 'app/helpers/site_menus_helper.rb', line 96 def () if current_page?(.target) header = "<div class='hmenu_current'>" + link_to(.name,.target) + "</div>" else header = link_to(.name,.target) end header += raw("<ul>") if .children.any? header end |
70 71 72 73 74 75 76 77 |
# File 'app/helpers/site_menus_helper.rb', line 70 def margin = 0 (false) do |name,html| break if (html[/(.*) href=\"(.*)\" (.*)$/,2]) margin += (strip_links( (html||name||' ') ).length-1)*1.38 end margin.to_i end |
79 80 81 82 83 84 85 |
# File 'app/helpers/site_menus_helper.rb', line 79 def (upto=4) rc=(0..upto).to_a.map { |level| level if content_for?("submenu_level_#{level}".to_sym) }.compact Rails.logger.info("==== SUBMENUS #{rc.inspect}") rc end |