Class: Navbar::Configurator
- Inherits:
-
Object
- Object
- Navbar::Configurator
- Defined in:
- lib/navbar/configurator.rb
Constant Summary collapse
- DEFAULT_SCOPE =
:default
Instance Attribute Summary collapse
-
#tabs ⇒ Object
readonly
Returns the value of attribute tabs.
Instance Method Summary collapse
-
#initialize(*args) {|@configuration| ... } ⇒ Configurator
constructor
A new instance of Configurator.
- #register(name, options = {}) ⇒ Object
- #size(scope = DEFAULT_SCOPE) ⇒ Object
- #tab(name, scope = DEFAULT_SCOPE) ⇒ Object
Constructor Details
#initialize(*args) {|@configuration| ... } ⇒ Configurator
Returns a new instance of Configurator.
10 11 12 13 14 15 |
# File 'lib/navbar/configurator.rb', line 10 def initialize(*args, &block) @configuration = OpenStruct.new @tabs = OpenStruct.new(DEFAULT_SCOPE => []) yield(@configuration) if block_given? end |
Instance Attribute Details
#tabs ⇒ Object (readonly)
Returns the value of attribute tabs.
8 9 10 |
# File 'lib/navbar/configurator.rb', line 8 def tabs @tabs end |
Instance Method Details
#register(name, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/navbar/configurator.rb', line 17 def register(name, = {}) scope = .fetch(:scope, DEFAULT_SCOPE) active = .fetch(:active, nil) css = [.fetch(:class, nil)] css << (active.is_a?(String) ? active : "active") if active (scope) << OpenStruct.new({ name: name, html_class: css.compact.flatten.join(" "), "active?" => active }) end |
#size(scope = DEFAULT_SCOPE) ⇒ Object
33 34 35 |
# File 'lib/navbar/configurator.rb', line 33 def size(scope = DEFAULT_SCOPE) (scope).is_a?(Array) and (scope).size end |
#tab(name, scope = DEFAULT_SCOPE) ⇒ Object
29 30 31 |
# File 'lib/navbar/configurator.rb', line 29 def tab(name, scope = DEFAULT_SCOPE) tabs.send(scope) && tabs.send(scope).find{ |item| item.name == name } end |