Class: SimpleNavigation::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/simple_navigation/configuration.rb

Overview

Responsible for evaluating and handling the config/navigation.rb file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Sets the config’s default-settings



40
41
42
43
44
45
# File 'lib/simple_navigation/configuration.rb', line 40

def initialize
  @renderer = SimpleNavigation::Renderer::List
  @selected_class = 'selected'
  @render_all_levels = false
  @autogenerate_item_ids = true
end

Instance Attribute Details

#autogenerate_item_idsObject

Returns the value of attribute autogenerate_item_ids.



12
13
14
# File 'lib/simple_navigation/configuration.rb', line 12

def autogenerate_item_ids
  @autogenerate_item_ids
end

#primary_navigationObject (readonly)

Returns the value of attribute primary_navigation.



13
14
15
# File 'lib/simple_navigation/configuration.rb', line 13

def primary_navigation
  @primary_navigation
end

#render_all_levelsObject

Returns the value of attribute render_all_levels.



11
12
13
# File 'lib/simple_navigation/configuration.rb', line 11

def render_all_levels
  @render_all_levels
end

#rendererObject

Returns the value of attribute renderer.



9
10
11
# File 'lib/simple_navigation/configuration.rb', line 9

def renderer
  @renderer
end

#selected_classObject

Returns the value of attribute selected_class.



10
11
12
# File 'lib/simple_navigation/configuration.rb', line 10

def selected_class
  @selected_class
end

Class Method Details

.eval_config(context, navigation_context = :default) ⇒ Object

Evals the config_file for the given navigation_context inside the specified context (usually a controller or view)



18
19
20
21
# File 'lib/simple_navigation/configuration.rb', line 18

def eval_config(context, navigation_context = :default)
  context.instance_eval(SimpleNavigation.config_files[navigation_context])
  SimpleNavigation.controller = extract_controller_from context
end

.extract_controller_from(context) ⇒ Object

Extracts a controller from the context.



29
30
31
32
33
34
35
# File 'lib/simple_navigation/configuration.rb', line 29

def extract_controller_from(context)
  if context.respond_to? :controller
    context.controller
  else
    context
  end
end

.run(&block) ⇒ Object

Starts processing the configuration



24
25
26
# File 'lib/simple_navigation/configuration.rb', line 24

def run(&block)
  block.call Configuration.instance
end

Instance Method Details

#items(&block) ⇒ Object

Yields an SimpleNavigation::ItemContainer for adding navigation items



48
49
50
51
# File 'lib/simple_navigation/configuration.rb', line 48

def items(&block)
  @primary_navigation = ItemContainer.new
  block.call @primary_navigation
end

#loaded?Boolean

Returns true if the config_file has already been evaluated.

Returns:

  • (Boolean)


54
55
56
# File 'lib/simple_navigation/configuration.rb', line 54

def loaded?
  !@primary_navigation.nil?
end