Returns the ItemContainer that contains the items for the primary navigation
A plugin for generating a simple navigation. See README for resources on usage instructions.
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 122 def active_item_container_for(level) case level when :all self.primary_navigation when :leaves self.primary_navigation.active_leaf_container when Integer self.primary_navigation.active_item_container_for(level) when Range self.primary_navigation.active_item_container_for(level.min) else raise ArgumentError, "Invalid navigation level: #{level}" end end
Returns the singleton instance of the SimpleNavigation::Configuration
# File lib/simple_navigation.rb, line 106 def config SimpleNavigation::Configuration.instance end
Returns the path to the config file for the given navigation context or nil if no matching config file can be found. If multiple config_paths are set, it returns the first matching path.
# File lib/simple_navigation.rb, line 80 def config_file(navigation_context = :default) config_file_paths.collect { |path| File.join(path, config_file_name(navigation_context)) }.detect {|full_path| File.exists?(full_path)} end
Returns true if the config_file for specified context does exist.
# File lib/simple_navigation.rb, line 74 def config_file?(navigation_context = :default) !!config_file(navigation_context) end
Returns the name of the config file for the given navigation_context
# File lib/simple_navigation.rb, line 85 def config_file_name(navigation_context = :default) prefix = navigation_context == :default ? '' : "#{navigation_context.to_s.underscore}_" "#{prefix}navigation.rb" end
Resets the list of config_file_paths to the specified path
# File lib/simple_navigation.rb, line 91 def config_file_path=(path) self.config_file_paths = [path] end
# File lib/simple_navigation.rb, line 69 def default_config_file_path File.join(SimpleNavigation.root, 'config') end
Returns the current framework in which the plugin is running.
# File lib/simple_navigation.rb, line 45 def framework return :rails if defined?(Rails) return :padrino if defined?(Padrino) return :sinatra if defined?(Sinatra) raise '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 65 def init_adapter_from(context) self.adapter = self.adapter_class.new(context) end
Loads the adapter for the current framework
# File lib/simple_navigation.rb, line 53 def load_adapter self.adapter_class = case framework when :rails SimpleNavigation::Adapters::Rails when :sinatra SimpleNavigation::Adapters::Sinatra when :padrino SimpleNavigation::Adapters::Padrino end end
Reads the config_file for the specified navigation_context and stores it for later evaluation.
# File lib/simple_navigation.rb, line 96 def load_config(navigation_context = :default) raise "Config file '#{config_file_name(navigation_context)}' not found in path(s) #{config_file_paths.join(', ')}!" unless config_file?(navigation_context) if self.environment == 'production' self.config_files[navigation_context] ||= IO.read(config_file(navigation_context)) else self.config_files[navigation_context] = IO.read(config_file(navigation_context)) end end
Registers a renderer.
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 147 def register_renderer(renderer_hash) self.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 38 def set_env(root, environment) self.root = root self.environment = environment self.config_file_paths << SimpleNavigation.default_config_file_path end
Generated with the Darkfish Rdoc Generator 2.