Sha256: b2f6d5fc10f19303a23e32ea858e057ede10971a428a6ee84f13702dd1411503

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

module AppFrame
  module MenuHelper
    def menu_link(key, path = '#', options = {}, &block)
      active = false
      highlight = options.delete(:highlights_on)
      highlight ||= options.delete(:exact) ? /^#{path}$/ : /#{path}/
      dropdown = options.delete(:dropdown)

      Array(highlight).each do |regex|
        active = true if request.path =~ regex
      end
    
      options[:class] ||= ""
      options[:class] << ' active' if active
      options[:class] << ' dropdown' if dropdown
      options[:class] = options[:class].present? ? options[:class].strip : nil
    
      key = t(:"menu.#{key}") if key.is_a?(Symbol)
    
      a_class = dropdown ? 'dropdown-toggle' : nil
      ul_class = dropdown ? 'dropdown-menu' : nil
    
      content = link_to(key, path, :class => a_class)
      content += content_tag(:ul, capture(&block), :class => ul_class) if block_given?
    
      content_tag :li, content, options
    end 
  
    def content_locale_switch(obj = nil)
      return unless obj.respond_to?(:translated_locales)
      
      current_locale = (params[:content_locale] || I18n.default_locale).to_sym
      
      locales = I18n.available_locales.map do |s|
        text = s.to_s.upcase
        text << "*" if obj && !obj.translated_locales.include?(s)
        content_tag :li, link_to(text, url_for(:content_locale => s)), :class => current_locale == s ? 'active' : nil
      end
      
      content_tag :ul, locales.join("").html_safe, :class => 'nav nav-pills'
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
app_frame-0.5.8 app/helpers/app_frame/menu_helper.rb