Class: Shirka::Controller

Inherits:
Object
  • Object
show all
Includes:
Eventalk
Defined in:
lib/shirka/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Eventalk

#add_watcher, #fire, #forward, #watch, #watchers

Constructor Details

#initialize(app, parent = nil, data = nil) ⇒ Controller

Returns a new instance of Controller.



11
12
13
14
15
16
17
18
# File 'lib/shirka/controller.rb', line 11

def initialize(app, parent=nil, data=nil)    
  @app = app
  @parent = parent
  @components = Components.new
  @data = data
  watch @app
  init data
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/shirka/controller.rb', line 7

def app
  @app
end

#componentsObject (readonly)

Returns the value of attribute components.



6
7
8
# File 'lib/shirka/controller.rb', line 6

def components
  @components
end

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/shirka/controller.rb', line 9

def data
  @data
end

#parentObject

Returns the value of attribute parent.



8
9
10
# File 'lib/shirka/controller.rb', line 8

def parent
  @parent
end

#viewObject



28
29
30
# File 'lib/shirka/controller.rb', line 28

def view
  @view ||= view_class.new self
end

Instance Method Details

#add_component(component, slot = nil) ⇒ Object



43
44
45
46
47
48
# File 'lib/shirka/controller.rb', line 43

def add_component(component, slot=nil)
  component.parent = self
  @components.add slot, component
  component.on_component_adding  
  view.on_view_adding component.view, slot     
end

#add_item(text = '', controller_class = nil) ⇒ Object



37
38
39
40
41
# File 'lib/shirka/controller.rb', line 37

def add_item(text='', controller_class=nil)
  controller_class ||= item_controller_class
  comp = controller_class.new app, self, text
  add_component comp
end

#init(data) ⇒ Object



20
21
# File 'lib/shirka/controller.rb', line 20

def init(data)
end

#item_controller_classObject



32
33
34
35
# File 'lib/shirka/controller.rb', line 32

def item_controller_class
  name = self.class.to_s.sub(/Controller$/, 'ItemController')
  Object.const_get name rescue ::Shirka::Controller
end

#on_component_added(data = nil) ⇒ Object



53
54
# File 'lib/shirka/controller.rb', line 53

def on_component_added(data=nil)
end

#on_component_adding(data = nil) ⇒ Object



50
51
# File 'lib/shirka/controller.rb', line 50

def on_component_adding(data=nil)
end

#view_classObject



23
24
25
26
# File 'lib/shirka/controller.rb', line 23

def view_class
  name = self.class.to_s.sub(/Controller$/, 'View')
  Object.const_get name rescue ::Shirka::View
end