Sha256: 381c8c7107edf1886492b482bb48aa9a52e1bd8f1d571dabd6c1feb27c4598eb

Contents?: true

Size: 904 Bytes

Versions: 1

Compression:

Stored size: 904 Bytes

Contents

module MenusHelper
  
  def find_or_create_menu(uid, locale = nil)
    if locale
      Menu.find_or_create_by_uid_and_locale(uid, locale.to_s, :name => "#{uid}".gsub("-", "_").humanize)
    else
      Menu.find_or_create_by_uid(uid, :name => "#{uid}".gsub("-", "_").humanize)         
    end
  end
  
  def nav_items_for(uid,  locale = nil)
    menu = find_or_create_menu(uid, locale)
    html = ""

    menu.links.each do |link|
      unless block_given?
        html << nav_item(link.label, link_url(link), :rel => link.nofollow ? "nofollow" : nil)      
      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)
    link.url.present? ? CGI::escape(link.url) : (link.linked ? page_path_for(link.linked) : "#")
  end
  
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fullstack-cms-0.2.5 app/helpers/menus_helper.rb