Module: Navtastic
- Defined in:
- lib/navtastic.rb,
lib/navtastic/item.rb,
lib/navtastic/menu.rb,
lib/navtastic/railtie.rb,
lib/navtastic/version.rb,
lib/navtastic/renderer.rb,
lib/navtastic/configuration.rb,
lib/navtastic/renderer/bulma.rb,
lib/navtastic/renderer/simple.rb,
lib/navtastic/renderer/bootstrap4.rb,
lib/navtastic/renderer/foundation6.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ViewHelpers Classes: Configuration, Item, Menu, Railtie, Renderer
Constant Summary collapse
- VERSION =
'0.2.0'.freeze
Class Method Summary collapse
-
.all_menus ⇒ Array
A list of all defined menus.
-
.configuration ⇒ Navtastic::Configuration
Current configuration.
-
.configure {|current| ... } ⇒ Object
Modify Navtastic's current configuration.
-
.define(name) {|menu, params| ... } ⇒ Object
Define a new menu to be rendered later.
-
.render(name, current_url, params = {}) ⇒ Renderer
Render a stored menu.
-
.reset_configuration ⇒ Object
This will reset the configuration back to defaults.
Class Method Details
.all_menus ⇒ Array
A list of all defined menus
74 75 76 |
# File 'lib/navtastic.rb', line 74 def self. .keys end |
.configuration ⇒ Navtastic::Configuration
Returns current configuration.
89 90 91 |
# File 'lib/navtastic/configuration.rb', line 89 def self.configuration @configuration ||= Configuration.new end |
.configure {|current| ... } ⇒ Object
Modify Navtastic's current configuration
106 107 108 |
# File 'lib/navtastic/configuration.rb', line 106 def self.configure yield configuration end |
.define(name) {|menu, params| ... } ⇒ Object
Define a new menu to be rendered later
32 33 34 35 36 37 |
# File 'lib/navtastic.rb', line 32 def self.define(name, &block) raise ArgumentError, "no block given" unless block_given? name = name.to_sym if name.is_a? String [name] = block end |
.render(name, current_url, params = {}) ⇒ Renderer
Render a stored menu
The params parameter is passed along to the block in define.
If params contains a :renderer key, it's removed from the hash and
passed to the renderer instead. Look at the renderer documentation to see
which options are supported.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/navtastic.rb', line 55 def self.render(name, current_url, params = {}) name = name.to_sym if name.is_a? String block = [name] raise KeyError, "menu not defined: #{name.inspect}" if block.nil? # Merge renderer options globally with those passed at runtime = configuration..dup .merge!(params.delete(:renderer) || {}) = Menu.new block.call(, params) .current_url = current_url Navtastic.configuration.current_renderer.render(, ) end |
.reset_configuration ⇒ Object
This will reset the configuration back to defaults
94 95 96 |
# File 'lib/navtastic/configuration.rb', line 94 def self.reset_configuration @configuration = nil end |