Class: Lapillus::Container
- Inherits:
-
Component
- Object
- RenderableComponent
- Component
- Lapillus::Container
- Defined in:
- lib/lapillus/base.rb,
lib/lapillus/containers.rb,
lib/lapillus/containers.rb more...
Direct Known Subclasses
AjaxLink, BookmarkablePageLink, Form, Fragment, ListItem, ListView, Pager, Panel, RemotePanel, Webpage
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
Attributes inherited from Component
#behaviours, #identifier, #model, #property, #visible
Class Method Summary collapse
- .add_component(id, clazz, model = nil) ⇒ Object
- .fileuploadfield(id, options = {}) ⇒ Object
- .image(id, options = {}) ⇒ Object
- .label(id, options = {}) ⇒ Object
- .listview(id, options = {}, &block) ⇒ Object
- .panel(id, clazz, model = nil, options = {}) ⇒ Object
- .password_textfield(id, options = {}) ⇒ Object
- .textarea(id, options = {}) ⇒ Object
- .textfield(id, options = {}) ⇒ Object
Instance Method Summary collapse
-
#[](path) ⇒ Object
deprecated.
-
#add(component) ⇒ Object
deprecated.
-
#component(identifier) ⇒ Object
deprecated.
-
#initialize(id, options = {}) ⇒ Container
constructor
A new instance of Container.
-
#post(values) ⇒ Object
NOTE: is this really the responsibility of container?.
-
#render_children(visitor, element) ⇒ Object
TODO: duplicate with NullComponent.render_children!.
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
permalink #initialize(id, options = {}) ⇒ Container
Returns a new instance of Container.
190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/lapillus/base.rb', line 190 def initialize(id, ={}) super(id, ) @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
Class Method Details
permalink .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 |
permalink .fileuploadfield(id, options = {}) ⇒ Object
[View source]
77 78 79 80 81 82 |
# File 'lib/lapillus/form_components.rb', line 77 def Container.fileuploadfield(id, ={}) .keys.each {|key| raise "Unknown key: #{key}" if key!=:model and key!=:property } internal_add_component(id) { FileUploadField.new(id, ) } end |
permalink .image(id, options = {}) ⇒ Object
[View source]
102 103 104 105 106 107 |
# File 'lib/lapillus/components.rb', line 102 def Container.image(id, ={}) .keys.each {|key| raise "Unknown key: #{key}" if key!=:model and key!=:root_url } internal_add_component(id) { Image.new(id, ) } end |
permalink .label(id, options = {}) ⇒ Object
[View source]
23 24 25 26 27 28 |
# File 'lib/lapillus/components.rb', line 23 def Container.label(id, ={}) .keys.each {|key| raise "Unknown key: #{key}" if key!=:model and key!=:property } internal_add_component(id) { Label.new(id, ) } end |
permalink .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, ={}, &block) .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, ) } internal_add_block(id, block) end |
permalink .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, ={}) add_component(id, clazz, model) end |
permalink .password_textfield(id, options = {}) ⇒ Object
[View source]
89 90 91 |
# File 'lib/lapillus/form_components.rb', line 89 def Container.password_textfield(id, ={}) internal_add_component(id) { PasswordTextField.new(id, ) } end |
Instance Method Details
permalink #[](path) ⇒ Object
deprecated
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 |
permalink #add(component) ⇒ Object
deprecated
204 205 206 207 |
# File 'lib/lapillus/base.rb', line 204 def add(component) @components.push(component) component.parent = self end |
permalink #component(identifier) ⇒ Object
deprecated
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 |
permalink #post(values) ⇒ Object
NOTE: is this really the responsibility of container?
232 233 234 |
# File 'lib/lapillus/base.rb', line 232 def post(values) components.each {|component| component.post(values)} end |
permalink #render_children(visitor, element) ⇒ Object
TODO: duplicate with NullComponent.render_children!
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 |