Class: Lapillus::Container

Inherits:
Component show all
Defined in:
lib/lapillus/base.rb,
lib/lapillus/containers.rb,
lib/lapillus/containers.rb
more...

Instance Attribute Summary collapse

Attributes inherited from Component

#behaviours, #identifier, #model, #property, #visible

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

#add_behaviour, #behaviour, #has_behaviour?, #has_model?, #has_parent?, #parent, #path, #response_page=, #session, #value, #webpage

Methods inherited from RenderableComponent

#on_render, #render_behaviours, #render_component, #render_container, #render_to_element, #visible?

Constructor Details

#initialize(id, options = {}) ⇒ Container

Returns a new instance of Container.

[View source]

190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/lapillus/base.rb', line 190

def initialize(id, options={})
  super(id, options)
  @components = []
  classes_to_process.each {|clazz| 
    clazz.stored_components.each {|stored_component|
      #TODO model symbol stuff
      new_component = stored_component.block.call
      new_component.parent = self #NOTE: I could do this in the constructor!
      components << new_component
    }
  }
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.


167
168
169
# File 'lib/lapillus/base.rb', line 167

def components
  @components
end

Class Method Details

.add_component(id, clazz, model = nil) ⇒ Object

[View source]

168
169
170
171
172
173
174
# File 'lib/lapillus/base.rb', line 168

def self.add_component(id, clazz, model=nil)
  if model.nil?
    internal_add_component(id) { clazz.new(id) }
  else
    internal_add_component(id) { clazz.new(id, model) }
  end
end

.fileuploadfield(id, options = {}) ⇒ Object

[View source]

77
78
79
80
81
82
# File 'lib/lapillus/form_components.rb', line 77

def Container.fileuploadfield(id, options={})
  options.keys.each {|key|
    raise "Unknown key: #{key}" if key!=:model and key!=:property  
  }
  internal_add_component(id) { FileUploadField.new(id, options) }
end

.image(id, options = {}) ⇒ Object

[View source]

102
103
104
105
106
107
# File 'lib/lapillus/components.rb', line 102

def Container.image(id, options={})
  options.keys.each {|key|
    raise "Unknown key: #{key}" if key!=:model and key!=:root_url  
  }
  internal_add_component(id) { Image.new(id, options) }
end

.label(id, options = {}) ⇒ Object

[View source]

23
24
25
26
27
28
# File 'lib/lapillus/components.rb', line 23

def Container.label(id, options={})
  options.keys.each {|key|
    raise "Unknown key: #{key}" if key!=:model and key!=:property  
  }
  internal_add_component(id) { Label.new(id, options) }
end

.listview(id, options = {}, &block) ⇒ Object

[View source]

105
106
107
108
109
110
111
112
# File 'lib/lapillus/containers.rb', line 105

def self.listview(id, options={}, &block)
  options.keys.each {|key|
    raise "Unknown key: #{key}" if key!=:model and key!=:property  
  }
  raise "no block supplied!" if !block_given?
  internal_add_component(id) { ListView.new(id, options) }
  internal_add_block(id, block)
end

.panel(id, clazz, model = nil, options = {}) ⇒ Object

[View source]

181
182
183
# File 'lib/lapillus/containers.rb', line 181

def self.panel(id, clazz, model=nil, options={})
  add_component(id, clazz, model) 
end

.password_textfield(id, options = {}) ⇒ Object

[View source]

89
90
91
# File 'lib/lapillus/form_components.rb', line 89

def Container.password_textfield(id, options={})
  internal_add_component(id) { PasswordTextField.new(id, options) }
end

.textarea(id, options = {}) ⇒ Object

[View source]

67
68
69
70
71
72
# File 'lib/lapillus/form_components.rb', line 67

def Container.textarea(id, options={})
  options.keys.each {|key|
    raise "Unknown key: #{key}" if key!=:model and key!=:property  
  }
  internal_add_component(id) { TextArea.new(id, options) }
end

.textfield(id, options = {}) ⇒ Object

[View source]

54
55
56
57
58
59
# File 'lib/lapillus/form_components.rb', line 54

def Container.textfield(id, options={})
  options.keys.each {|key|
    raise "Unknown key: #{key}" if key!=:model and key!=:property  
  }
  internal_add_component(id) { TextField.new(id, options)}
end

Instance Method Details

#[](path) ⇒ Object

deprecated

[View source]

210
211
212
213
214
215
216
217
218
219
# File 'lib/lapillus/base.rb', line 210

def [](path)
  pathparts = path.split('.')
  result = nil
  container = self
  pathparts.each {|pathpart| 
    result = container.component(pathpart)
    container = result
  }
  return result
end

#add(component) ⇒ Object

deprecated

[View source]

204
205
206
207
# File 'lib/lapillus/base.rb', line 204

def add(component)
  @components.push(component)
  component.parent = self
end

#component(identifier) ⇒ Object

deprecated

[View source]

222
223
224
225
226
227
228
229
# File 'lib/lapillus/base.rb', line 222

def component(identifier)
  identifier = identifier.intern if identifier.kind_of?(String)
  result = components.find{|component|
    component.identifier.eql?(identifier)
  }
  raise "Component #{identifier} does not exist in container #{self.path}!\n" if result.nil?
  return result
end

#post(values) ⇒ Object

NOTE: is this really the responsibility of container?

[View source]

232
233
234
# File 'lib/lapillus/base.rb', line 232

def post(values) 
  components.each {|component| component.post(values)} 
end

#render_children(visitor, element) ⇒ Object

TODO: duplicate with NullComponent.render_children!

[View source]

238
239
240
241
242
243
244
245
# File 'lib/lapillus/base.rb', line 238

def render_children(visitor, element)
  visitor.current_container = self #NOTE: Added!
  element.children.each do |child|
    #        puts child.class
    child.accept(visitor)
  end
  visitor.current_container = self.parent #NOTE: Added!
end