Sha256: 5ad5afa0b2b44d9dcae4f2b43e7ac3f8123011777adf3a3a3f810cecec95808f

Contents?: true

Size: 891 Bytes

Versions: 4

Compression:

Stored size: 891 Bytes

Contents

module MenusHelper
  
  def nav_items_for(uid)
    menu = Menu.find_or_create_by_uid(uid, :name => "#{uid}".humanize)
    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 menu(uid, options = nil, &block)
    content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &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)
      page_path_for(resource)
      
    else
      url
          
    end

  end
  
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fullstack-cms-0.1.5 app/helpers/menus_helper.rb
fullstack-cms-0.1.4 app/helpers/menus_helper.rb
fullstack-cms-0.1.3 app/helpers/menus_helper.rb
fullstack-cms-0.1.2 app/helpers/menus_helper.rb