class Navbar::Configurator

Constants

DEFAULT_SCOPE

Attributes

tabs[R]

Public Class Methods

new(*args) { |configuration| ... } click to toggle source
# 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

Public Instance Methods

register(name, options = {}) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

bar(scope) click to toggle source
# File lib/navbar/configurator.rb, line 39
def bar(scope)
  tabs.send(scope) or tabs.send("#{scope}=", [])
end