Class: Glia::Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/glia/layout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(area, handles, options = {}) ⇒ Layout

Returns a new instance of Layout.



11
12
13
14
15
16
17
18
19
# File 'lib/glia/layout.rb', line 11

def initialize(area, handles, options = {})
  @area = area
  @themes = options[:theme_inheritance] || [:default]
  @update = UpdateRegistry.merge_themes(area, )
  @cells = {}
  @handles = handles
  @data = @update.merge(@handles)
  @view_factory = options[:view_factory] unless options[:view_factory].nil?
end

Instance Attribute Details

#cellsObject (readonly)

Returns the value of attribute cells.



5
6
7
# File 'lib/glia/layout.rb', line 5

def cells
  @cells
end

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/glia/layout.rb', line 5

def data
  @data
end

#handlesObject (readonly)

Returns the value of attribute handles.



5
6
7
# File 'lib/glia/layout.rb', line 5

def handles
  @handles
end

#themesObject (readonly)

Returns the value of attribute themes.



5
6
7
# File 'lib/glia/layout.rb', line 5

def themes
  @themes
end

#updateObject (readonly)

Returns the value of attribute update.



5
6
7
# File 'lib/glia/layout.rb', line 5

def update
  @update
end

#view_factoryObject



39
40
41
# File 'lib/glia/layout.rb', line 39

def view_factory
  @view_factory ||= ViewFactory.new
end

Instance Method Details

#cell(name, *args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/glia/layout.rb', line 21

def cell(name, *args)
  if @cells[name].nil?
    definition = @data[name]
    raise Errors::MissingCellError, "Cell #{name} is missing from layout #{@area}" if definition.nil?
    code = definition.delete(:class)
    actions = definition.delete(:actions)
    children = definition.delete(:children)
    namespace = definition.delete(:view_namespace) || Object
    @cells[name] = view_factory.build(code, namespace, definition, actions, *args)
    unless @cells[name].respond_to?(:child_definitions=)
      raise Errors::InvalidCellError, @cells[name].class.name+' is not a valid cell. Include Glia::Cell.'
    end
    @cells[name].child_definitions = children
    @cells[name].layout = self
  end
  @cells[name]
end