Module: SimpleNavigation

Extended by:
Forwardable
Defined in:
lib/simple_navigation.rb,
lib/simple_navigation/item.rb,
lib/simple_navigation/helpers.rb,
lib/simple_navigation/railtie.rb,
lib/simple_navigation/version.rb,
lib/simple_navigation/adapters.rb,
lib/simple_navigation/renderer.rb,
lib/simple_navigation/config_file.rb,
lib/simple_navigation/item_adapter.rb,
lib/simple_navigation/adapters/base.rb,
lib/simple_navigation/configuration.rb,
lib/simple_navigation/renderer/base.rb,
lib/simple_navigation/renderer/json.rb,
lib/simple_navigation/renderer/list.rb,
lib/simple_navigation/renderer/text.rb,
lib/simple_navigation/adapters/nanoc.rb,
lib/simple_navigation/adapters/rails.rb,
lib/simple_navigation/item_container.rb,
lib/simple_navigation/items_provider.rb,
lib/simple_navigation/renderer/links.rb,
lib/simple_navigation/adapters/padrino.rb,
lib/simple_navigation/adapters/sinatra.rb,
lib/simple_navigation/config_file_finder.rb,
lib/simple_navigation/renderer/breadcrumbs.rb

Overview

A plugin for generating a simple navigation. See README for resources on usage instructions.

Defined Under Namespace

Modules: Adapters, Helpers, Renderer Classes: ConfigFile, ConfigFileFinder, Configuration, Item, ItemAdapter, ItemContainer, ItemsProvider, Railtie

Constant Summary collapse

VERSION =
'4.4.0'

Class Method Summary collapse

Class Method Details

.active_item_container_for(level) ⇒ Object

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.



134
135
136
137
138
139
140
141
142
143
# 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

.configObject

Returns the singleton instance of the SimpleNavigation::Configuration



114
115
116
# File 'lib/simple_navigation.rb', line 114

def config
  SimpleNavigation::Configuration.instance
end

.config_file_path=(path) ⇒ Object

Resets the list of config_file_paths to the specified path



99
100
101
# File 'lib/simple_navigation.rb', line 99

def config_file_path=(path)
  self.config_file_paths = [path]
end

.default_config_file_pathObject



94
95
96
# File 'lib/simple_navigation.rb', line 94

def default_config_file_path
  File.join(root, 'config')
end

.frameworkObject

Returns the current framework in which the plugin is running.



68
69
70
71
72
73
74
75
# 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

.init_adapter_from(context) ⇒ Object

Creates a new adapter instance based on the context in which render_navigation has been called.



90
91
92
# File 'lib/simple_navigation.rb', line 90

def init_adapter_from(context)
  self.adapter = adapter_class.new(context)
end

.load_adapterObject

Loads the adapter for the current framework



78
79
80
81
82
83
84
85
86
# 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

.load_config(navigation_context = :default) ⇒ Object

Reads the config_file for the specified navigation_context and stores it for later evaluation.



105
106
107
108
109
110
111
# 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

.primary_navigationObject

Returns the ItemContainer that contains the items for the primary navigation



120
121
122
# File 'lib/simple_navigation.rb', line 120

def primary_navigation
  config.primary_navigation
end

.register_renderer(renderer_hash) ⇒ Object

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)


155
156
157
# File 'lib/simple_navigation.rb', line 155

def register_renderer(renderer_hash)
  registered_renderers.merge!(renderer_hash)
end

.set_env(root, environment) ⇒ Object

Sets the root path and current environment as specified. Also sets the default config_file_path.



61
62
63
64
65
# 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