codeplant / simple-navigation

A ruby gem for creating navigations (with multiple levels) for your Rails, Sinatra or Padrino applications. Render your navigation as html list, link list or breadcrumbs.
http://simple-navigation-demo.codeplant.ch/
MIT License
885 stars 136 forks source link

Have all config in the navigation.rb and then create all menus on the fly? #176

Closed jmuheim closed 9 years ago

jmuheim commented 9 years ago

I have the following menu:

= render_navigation expand_all: true, renderer: :bootstrap do |navigation|
  -  navigation.dom_class = 'nav'
  -  navigation.dom_id = 'jump_links'

  - unless current_page?(root_path)
    -  navigation.item :jump_to_home_page, t('layouts.jump_links.home_page'), root_path, link_options: {accesskey: 0}

  -  navigation.item :jump_to_navigation, t('layouts.jump_links.navigation'), '#navigation'
  -  navigation.item :jump_to_content, t('layouts.jump_links.content'), '#main'

My config/navigation.rb file looks like this:

SimpleNavigation::Configuration.run do |navigation|
end

I'd like to move all the settings to the config file, as I want to generate many menus with exactly the same options, but different items. So I want to move the following stuff to the config file:

Is this possible? I couldn't manage to do it.

jmuheim commented 9 years ago

So I managed to set the renderer for all generated menus like so in config/navigation.rb:

  navigation.renderer = SimpleNavigation::Renderer::Bootstrap
simonc commented 9 years ago

Hi @jmuheim,

You can set the dom_class and dom_id options in the config file but the expand_all is specific to the renderer. One solution could be to create a renderer that inherits from SimpleNavigation::Renderer::Bootstrap and defaults the expand_all option to true

andi commented 9 years ago

@jmuheim Not sure what exactly you are trying to achieve, but maybe you the option to render different contexts with different config files would help? See https://github.com/codeplant/simple-navigation/wiki/FAQ#user-content-wiki-q10