Class: Modular::Configuration

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#layoutsObject (readonly)

Returns the value of attribute layouts.



7
8
9
# File 'lib/modular/configuration.rb', line 7

def layouts
  @layouts
end

Class Method Details

.configObject



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

def self.config
  self.instance
end

.configure(&block) ⇒ Object



13
14
15
16
17
# File 'lib/modular/configuration.rb', line 13

def self.configure(&block)
  instance = self.instance
  instance.instance_eval &block if block_given?
  instance
end

Instance Method Details

#layout(id) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/modular/configuration.rb', line 19

def layout(id)
  if layouts.has_key?(id)
    layouts[id]
  else
    raise "Layout '#{id}' not found"
  end      
end

#register_layout(layout, mod = :container, params = {}, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/modular/configuration.rb', line 27

def register_layout(layout, mod = :container, params = {}, &block)
  @layouts ||= Hash.new.with_indifferent_access
  
  if mod.is_a? Components::Base
    @layouts[layout.to_s] = mod
  else
    root_layout = Modular.create mod, params
    root_layout.instance_eval &block if block_given?
    @layouts[layout.to_s] = root_layout
  end
end