Sha256: 43deab61e2b2490f90e4f4d7911de2be9149d89ec4ac6a7fc3b1593bb09de1b6

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

module Ecm::CmsNavigationHelper
  def cms_render_navigation(name, options = {})
 
    navigation = Ecm::CmsNavigation::Navigation.where(:name => name.to_s, :locale => I18n.locale.to_s).first

    return I18n.t('ecm.navigation.navigation_not_found', {:lang => I18n.locale.to_s, :name => name.to_s}) unless navigation
 
    options[:items] = []
    navigation.navigation_items.roots.all.each do |navigation_item|
      options[:items] << build_navigation(navigation_item)  
    end
     
    # return I18n.t('ecm.navigation.navigation_empty', {:locale => I18n.locale.to_s, :name => name}) if options[:items].empty?
    return I18n.t('ecm.navigation.navigation_empty', :lang => I18n.locale.to_s, :name => name) if options[:items].empty?    
    render_navigation(options)
  end
  
  def build_navigation(navigation_item)
    if navigation_item.children.count > 0
      items = []
      navigation_item.children.each do |child|
        items << build_navigation(child)
      end
      output = { :key => navigation_item.key, :name => navigation_item.name, :url => eval(navigation_item.url), :items => items }
    else  
      output = { :key => navigation_item.key, :name => navigation_item.name, :url => eval(navigation_item.url) }
    end
    
    begin
      options = eval(navigation_item.options) 
      output[:options] = options if options.is_a?(Hash)
    rescue
      logger.debug "Invalid navigation item options: #{navigation_item.options}"
    end  
    
    return output
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ecm_cms_navigation-0.0.13 app/helpers/ecm/cms_navigation_helper.rb
ecm_cms_navigation-0.0.12 app/helpers/ecm/cms_navigation_helper.rb
ecm_cms_navigation-0.0.11 app/helpers/ecm/cms_navigation_helper.rb
ecm_cms_navigation-0.0.10 app/helpers/ecm/cms_navigation_helper.rb
ecm_cms_navigation-0.0.9 app/helpers/ecm/cms_navigation_helper.rb