Class: Lapillus::Container

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

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?, #on_render, #parent, #path, #render_component, #response_page=, #session, #value, #visible?, #webpage

Constructor Details

#initialize(id, model = nil, property = nil) ⇒ Container

Returns a new instance of Container.



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/lapillus/base.rb', line 161

def initialize(id, model=nil, property=nil)
  super(id, model, property)
  @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.



138
139
140
# File 'lib/lapillus/base.rb', line 138

def components
  @components
end

Class Method Details

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



139
140
141
142
143
144
145
# File 'lib/lapillus/base.rb', line 139

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



73
74
75
76
77
78
# File 'lib/lapillus/form_components.rb', line 73

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[:model]||"", options[:property]) }
end

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



100
101
102
103
104
105
# File 'lib/lapillus/components.rb', line 100

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[:model], options[:root_url]) }
end

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



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

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[:model], options[:property]) }
end

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



109
110
111
112
113
114
115
116
# File 'lib/lapillus/containers.rb', line 109

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[:model], options[:property]) }
  internal_add_block(id, block)
end

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



190
191
192
# File 'lib/lapillus/containers.rb', line 190

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

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



85
86
87
# File 'lib/lapillus/form_components.rb', line 85

def Container.password_textfield(id, model="", options={})
  internal_add_component(id) { PasswordTextField.new(id, model, options[:property]) }
end

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



63
64
65
66
67
68
# File 'lib/lapillus/form_components.rb', line 63

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[:model]||"", options[:property]) }
end

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



50
51
52
53
54
55
# File 'lib/lapillus/form_components.rb', line 50

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[:model]||"", options[:property]) }
end

Instance Method Details

#[](path) ⇒ Object

deprecated



181
182
183
184
185
186
187
188
189
190
# File 'lib/lapillus/base.rb', line 181

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



175
176
177
178
# File 'lib/lapillus/base.rb', line 175

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

#component(identifier) ⇒ Object

deprecated



193
194
195
196
197
198
199
# File 'lib/lapillus/base.rb', line 193

def component(identifier)
  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?



202
203
204
# File 'lib/lapillus/base.rb', line 202

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

#render_container(container) ⇒ Object



206
207
208
209
210
211
212
# File 'lib/lapillus/base.rb', line 206

def render_container(container)
  new_element = REXML::Element.new(container)      
  render_children(container, new_element)
  render_to_element(new_element) 
  render_behaviours(new_element)
  return new_element
end