Sha256: eced05d33277a64fb3956955f90b30a4091691ec9e272f44f70b42a4cb21b1db
Contents?: true
Size: 942 Bytes
Versions: 14
Compression:
Stored size: 942 Bytes
Contents
module MenusHelper def find_or_create_menu(uid) Menu.find_or_create_by_uid(uid, :name => "#{uid}".gsub("-", "_").humanize) end def nav_items_for(uid) menu = find_or_create_menu(uid) html = "" menu.links.each do |link| unless block_given? html << nav_item(link.label, link_url(link)) else html << yield(link) end end html.html_safe end def render_menu(uid, options = nil, &block) content_tag :ul, nav_items_for(uid, &block), options, false end def link_url(link) url = link.url if url.blank? "#" elsif url.starts_with?("content://") klass_name, id = url.gsub("content://", "").split("#") klass = klass_name.constantize resource = klass.find(id) if resource page_path_for(resource) else "#" end else url end end end
Version data entries
14 entries across 14 versions & 1 rubygems