# File lib/simple_navigation.rb, line 120 def primary_navigation config.primary_navigation end
module SimpleNavigation
A plugin for generating a simple navigation. See README for resources on usage instructions.
Constants
- VERSION
Public Class Methods
Returns the active item container for the specified level. Valid levels are
-
:all - in this case the
primary_navigation
is returned. -
:leaves - the ‘deepest’ active item_container will be returned
-
a specific level - the active item_container for the specified level will be returned
-
a range of levels - the active item_container for the range’s minimum will be returned
Returns nil if there is no active item_container for the specified level.
# File lib/simple_navigation.rb, line 134 def active_item_container_for(level) case level when :all then primary_navigation when :leaves then primary_navigation.active_leaf_container when Integer then primary_navigation.active_item_container_for(level) when Range then primary_navigation.active_item_container_for(level.min) else fail ArgumentError, "Invalid navigation level: #{level}" end end
Returns the singleton instance of the SimpleNavigation::Configuration
# File lib/simple_navigation.rb, line 114 def config SimpleNavigation::Configuration.instance end
Resets the list of config_file_paths to the specified path
# File lib/simple_navigation.rb, line 99 def config_file_path=(path) self.config_file_paths = [path] end
# File lib/simple_navigation.rb, line 94 def default_config_file_path File.join(root, 'config') end
Returns the current framework in which the plugin is running.
# File lib/simple_navigation.rb, line 68 def framework return :rails if defined?(Rails) return :padrino if defined?(Padrino) return :sinatra if defined?(Sinatra) return :nanoc if defined?(Nanoc3) fail 'simple_navigation currently only works for Rails, Sinatra and ' \ 'Padrino apps' end
Creates a new adapter instance based on the context in which render_navigation has been called.
# File lib/simple_navigation.rb, line 90 def init_adapter_from(context) self.adapter = adapter_class.new(context) end
Loads the adapter for the current framework
# File lib/simple_navigation.rb, line 78 def load_adapter self.adapter_class = case framework when :rails then SimpleNavigation::Adapters::Rails when :sinatra then SimpleNavigation::Adapters::Sinatra when :padrino then SimpleNavigation::Adapters::Padrino when :nanoc then SimpleNavigation::Adapters::Nanoc end end
Reads the config_file
for the specified navigation_context and stores it for later evaluation.
# File lib/simple_navigation.rb, line 105 def load_config(navigation_context = :default) if environment == 'production' update_config(navigation_context) else update_config!(navigation_context) end end
Registers a renderer.
Example¶ ↑
To register your own renderer:
SimpleNavigation.register_renderer my_renderer: My::RendererClass
Then in the view you can call:
render_navigation(renderer: :my_renderer)
# File lib/simple_navigation.rb, line 155 def register_renderer(renderer_hash) registered_renderers.merge!(renderer_hash) end
Sets the root path and current environment as specified. Also sets the default config_file_path.
# File lib/simple_navigation.rb, line 61 def set_env(root, environment) self.root = root self.environment = environment config_file_paths << default_config_file_path end
Private Class Methods
# File lib/simple_navigation.rb, line 161 def config_file(navigation_context) ConfigFileFinder.new(config_file_paths).find(navigation_context) end
# File lib/simple_navigation.rb, line 165 def read_config(navigation_context) File.read config_file(navigation_context) end
# File lib/simple_navigation.rb, line 169 def update_config(navigation_context) config_files[navigation_context] ||= read_config(navigation_context) end
# File lib/simple_navigation.rb, line 173 def update_config!(navigation_context) config_files[navigation_context] = read_config(navigation_context) end