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

Version Path
fullstack-cms-0.2.4 app/helpers/menus_helper.rb
fullstack-cms-0.2.3 app/helpers/menus_helper.rb
fullstack-cms-0.2.2 app/helpers/menus_helper.rb
fullstack-cms-0.2.1 app/helpers/menus_helper.rb
fullstack-cms-0.1.17 app/helpers/menus_helper.rb
fullstack-cms-0.1.15 app/helpers/menus_helper.rb
fullstack-cms-0.1.14 app/helpers/menus_helper.rb
fullstack-cms-0.1.13 app/helpers/menus_helper.rb
fullstack-cms-0.1.12 app/helpers/menus_helper.rb
fullstack-cms-0.1.11 app/helpers/menus_helper.rb
fullstack-cms-0.1.9 app/helpers/menus_helper.rb
fullstack-cms-0.1.8 app/helpers/menus_helper.rb
fullstack-cms-0.1.7 app/helpers/menus_helper.rb
fullstack-cms-0.1.6 app/helpers/menus_helper.rb