Module: Spud::Cms::ApplicationHelper
- Defined in:
- app/helpers/spud/cms/application_helper.rb
Constant Summary collapse
- MENU_INDEX =
{}
Instance Method Summary collapse
- #sp_list_menu(options = {}) ⇒ Object
- #sp_list_pages(options = {}) ⇒ Object
- #sp_menu_with_seperator(options = {}) ⇒ Object
- #sp_snippet(name, snippets = nil) ⇒ Object
Instance Method Details
#sp_list_menu(options = {}) ⇒ Object
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'app/helpers/spud/cms/application_helper.rb', line 86 def ( = {}) max_depth = 0 = SpudMenu = nil = "" = {} = nil active_class = 'menu-active' if .has_key?(:active_class) active_class = [:active_class] end if Spud::Core.multisite_mode_enabled site_config = Spud::Core.site_config_for_host(request.host_with_port) = .site(site_config[:site_id]) if !site_config.blank? += "#{site_config[:site_id]}_" end if !.blank? = [:menu_id] if .has_key?(:menu_id) = [:link_options] if .has_key?(:link_options) if .has_key?(:name) += [:name] = .where(:name => [:name]) = MENU_INDEX[] if .blank? = .first if(!.blank?) = .id MENU_INDEX[] = .id end end end = [:start_menu_item_id] if .has_key?(:start_menu_item_id) if .has_key?(:id) content = "<ul id='#{[:id]}' #{"class='#{[:class]}'" if .has_key?(:class)}>" else content = "<ul #{"class='#{[:class]}'" if .has_key?(:class)}>" end max_depth = [:max_depth] if .has_key?(:max_depth) else content = "<ul>" end if .blank? return "" end = SpudMenuItem.where(:spud_menu_id => ).select(" #{SpudMenuItem.table_name}.id as id, #{SpudMenuItem.table_name}.url as url, #{SpudMenuItem.table_name}.classes as classes, #{SpudMenuItem.table_name}.parent_type as parent_type, #{SpudMenuItem.table_name}.menu_order as menu_order, #{SpudMenuItem.table_name}.parent_id as parent_id, #{SpudMenuItem.table_name}.name as name, #{SpudPage.table_name}.url_name as url_name").order(:parent_type,:parent_id).joins("LEFT JOIN #{SpudPage.table_name} ON (#{SpudPage.table_name}.id = #{SpudMenuItem.table_name}.spud_page_id)").load grouped_items = .group_by(&:parent_type) if grouped_items["SpudMenu"].blank? return "" end child_items = grouped_items["SpudMenuItem"].blank? ? [] : grouped_items["SpudMenuItem"].group_by(&:parent_id) parent_items = grouped_items["SpudMenu"] if != nil parent_items = child_items[] end parent_items.sort_by{|p| p.}.each do |item| active = false if !item.url_name.blank? if current_page?(page_path(:id => item.url_name)) active = true elsif item.url_name == Spud::Cms.root_page_name && current_page?(root_path) active = true end elsif current_page?(item.url) active = true end link_tag = link_to item.name, !item.url_name.blank? ? (item.url_name == Spud::Cms.root_page_name ? root_path() : page_path(:id => item.url_name)) : item.url, {:class => "#{'menu-active' if active} #{item.classes if !item.classes.blank?}"}.merge() content += "<li class='#{active_class if active} #{item.classes if !item.classes.blank?}'>#{link_tag}" if max_depth == 0 || max_depth > 1 content += (child_items,item.id,2,max_depth,) end content += "</li>" end content += "</ul>" return content.html_safe end |
#sp_list_pages(options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 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 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/spud/cms/application_helper.rb', line 25 def sp_list_pages( = {}) pages = SpudPage.is_public.published_pages if Spud::Core.multisite_mode_enabled site_config = Spud::Core.site_config_for_host(request.host_with_port) pages = pages.site(site_config[:site_id]) if !site_config.blank? end start_page = nil max_depth = 0 active_class = "menu-active" if !.blank? if .has_key?(:exclude) pages = pages.where(["name NOT IN (?)",[:exclude]]) end if .has_key?(:start_page_id) start_page = [:start_page_id] end if .has_key?(:id) content = "<ul id='#{[:id]}' #{"class='#{[:class]}'" if .has_key?(:class)}>" else content = "<ul #{"class='#{[:class]}'" if .has_key?(:class)}>" end if .has_key?(:active_class) active_class = [:active_class] end if .has_key?(:max_depth) max_depth = [:max_depth] end else content = "<ul>" end pages = pages.load.group_by(&:spud_page_id) if pages[start_page].blank? return "" end pages[start_page].sort_by{|p| p.page_order}.each do |page| active = false if !page.url_name.blank? if current_page?(page_path(:id => page.url_name)) active = true elsif page.url_name == Spud::Cms.root_page_name && current_page?(root_path) active = true end end content += "<li class='#{active_class if active}'><a href='#{page_path(:id => page.url_name)}'>#{page.name}</a>" if max_depth == 0 || max_depth > 1 content += sp_list_page(page,pages,2,max_depth,) end content += "</li>" end content += "</ul>" return content.html_safe end |
#sp_menu_with_seperator(options = {}) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'app/helpers/spud/cms/application_helper.rb', line 181 def (={}) seperator = " | ".html_safe if(.has_key?(:seperator)) seperator = [:seperator] end = SpudMenu.where(:name => [:name]) if Spud::Core.multisite_mode_enabled site_config = Spud::Core.site_config_for_host(request.host_with_port) = .site(site_config[:site_id]) if !site_config.blank? end = .first if(.blank?) return "" end = ..select(" #{SpudMenuItem.table_name}.id as id, #{SpudMenuItem.table_name}.url as url, #{SpudMenuItem.table_name}.classes as classes, #{SpudMenuItem.table_name}.parent_type as parent_type, #{SpudMenuItem.table_name}.menu_order as menu_order, #{SpudMenuItem.table_name}.parent_id as parent_id, #{SpudMenuItem.table_name}.name as name, #{SpudPage.table_name}.url_name as url_name").order(:parent_type,:parent_id).joins("LEFT JOIN #{SpudPage.table_name} ON (#{SpudPage.table_name}.id = #{SpudMenuItem.table_name}.spud_page_id)").load = [] .sort_by{|p| p.}.each do |item| += ["<a #{"class='#{item.classes}' " if !item.classes.blank?}href='#{!item.url_name.blank? ? (item.url_name == Spud::Cms.root_page_name ? root_path() : page_path(:id => item.url_name)) : item.url}'>#{item.name}</a>"] end return .join(seperator).html_safe end |
#sp_snippet(name, snippets = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/spud/cms/application_helper.rb', line 4 def sp_snippet(name,snippets=nil) if name.blank? return '' end if !snippets.blank? snippet = snippets.select {|s| s.name == name} else snippet = SpudSnippet.where(:name => name).first end if !snippet.blank? cache snippet do return snippet.content_processed.html_safe end else return nil end end |