Class: Navbar::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/navbar/configurator.rb

Constant Summary collapse

DEFAULT_SCOPE =
:default

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) {|@configuration| ... } ⇒ Configurator

Returns a new instance of Configurator.

Yields:

  • (@configuration)


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

#tabsObject (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, options = {})
  scope = options.fetch(:scope, DEFAULT_SCOPE)
  active = options.fetch(:active, nil)
  css = [options.fetch(:class, nil)]
  css << (active.is_a?(String) ? active : "active") if active
  bar(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)
  bar(scope).is_a?(Array) and bar(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