Sha256: 34573442db4ef130d39294c932267b53df6c5506f51573680f4ea1d028c74269

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

module AppFrame
  module MenuHelper
    def menu_link(key, path = '#', options = {}, &block)
      active = false
      highlight = options.delete(:highlights_on) || /#{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

3 entries across 3 versions & 1 rubygems

Version Path
app_frame-0.5.7 app/helpers/app_frame/menu_helper.rb
app_frame-0.5.6 app/helpers/app_frame/menu_helper.rb
app_frame-0.5.5 app/helpers/app_frame/menu_helper.rb