Class: Lapillus::Component
- Inherits:
-
RenderableComponent
- Object
- RenderableComponent
- Lapillus::Component
- Defined in:
- lib/lapillus/base.rb
Direct Known Subclasses
Behaviour, Container, FormComponent, Image, Label, MultiLineLabel, MultiView
Instance Attribute Summary collapse
-
#behaviours ⇒ Object
readonly
Returns the value of attribute behaviours.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#model ⇒ Object
TODO: make model defensive!.
-
#property ⇒ Object
readonly
Returns the value of attribute property.
-
#visible ⇒ Object
writeonly
Sets the attribute visible.
Instance Method Summary collapse
- #add_behaviour(behaviour) ⇒ Object
- #behaviour(behaviour_class) ⇒ Object
- #has_behaviour?(behaviour_class) ⇒ Boolean
- #has_model? ⇒ Boolean
-
#has_parent? ⇒ Boolean
TODO: test parent, hierarchy, path, page.
-
#initialize(id, options = {}) ⇒ Component
constructor
A new instance of Component.
- #parent ⇒ Object
-
#path ⇒ Object
TODO: add test for path that starts with a panel instead of an Webpage or Form NOTE: its not only panel…
-
#response_page=(page) ⇒ Object
TODO: this method is only tested indirectly.
-
#session ⇒ Object
TODO: this method is only tested indirectly.
- #value ⇒ Object
- #webpage ⇒ Object
Methods inherited from RenderableComponent
#on_render, #render_behaviours, #render_children, #render_component, #render_container, #render_to_element, #visible?
Constructor Details
#initialize(id, options = {}) ⇒ Component
Returns a new instance of Component.
66 67 68 69 70 71 72 73 74 |
# File 'lib/lapillus/base.rb', line 66 def initialize(id, ={}) super() raise "FATAL: use a symbol as identifier! #{id.class}: #{id}" if id!=""&&!id.kind_of?(Symbol) raise "FATAL: use named parameters! #{options.class}" if !.kind_of?(Hash) @identifier = id @model = [:model] @property = [:property] @visible = [:visible]||true end |
Instance Attribute Details
#behaviours ⇒ Object (readonly)
Returns the value of attribute behaviours.
64 65 66 |
# File 'lib/lapillus/base.rb', line 64 def behaviours @behaviours end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
64 65 66 |
# File 'lib/lapillus/base.rb', line 64 def identifier @identifier end |
#model ⇒ Object
TODO: make model defensive!
76 77 78 79 80 81 82 |
# File 'lib/lapillus/base.rb', line 76 def model if @model.kind_of?(Symbol) parent.send(@model) else @model end end |
#property ⇒ Object (readonly)
Returns the value of attribute property.
64 65 66 |
# File 'lib/lapillus/base.rb', line 64 def property @property end |
#visible=(value) ⇒ Object (writeonly)
Sets the attribute visible
65 66 67 |
# File 'lib/lapillus/base.rb', line 65 def visible=(value) @visible = value end |
Instance Method Details
#add_behaviour(behaviour) ⇒ Object
132 133 134 135 |
# File 'lib/lapillus/base.rb', line 132 def add_behaviour(behaviour) behaviour.parent=self @behaviours[behaviour.class] = behaviour end |
#behaviour(behaviour_class) ⇒ Object
141 142 143 |
# File 'lib/lapillus/base.rb', line 141 def behaviour(behaviour_class) return @behaviours[behaviour_class] end |
#has_behaviour?(behaviour_class) ⇒ Boolean
137 138 139 |
# File 'lib/lapillus/base.rb', line 137 def has_behaviour?(behaviour_class) return behaviour(behaviour_class) end |
#has_model? ⇒ Boolean
95 96 97 |
# File 'lib/lapillus/base.rb', line 95 def has_model? !@model.nil? end |
#has_parent? ⇒ Boolean
TODO: test parent, hierarchy, path, page
100 101 102 |
# File 'lib/lapillus/base.rb', line 100 def has_parent? !@parent.nil? end |
#parent ⇒ Object
83 84 85 86 |
# File 'lib/lapillus/base.rb', line 83 def parent raise "parent not set!" if @parent.nil? @parent end |
#path ⇒ Object
TODO: add test for path that starts with a panel instead of an Webpage or Form NOTE: its not only panel… only webpage and form we do not want to see…
106 107 108 109 110 111 112 113 114 |
# File 'lib/lapillus/base.rb', line 106 def path hier = hierarchy if hier[0].kind_of?(Panel) start = 0 else start = 1 end hier[start..-1].collect {|component| component.identifier}.join(".") end |
#response_page=(page) ⇒ Object
TODO: this method is only tested indirectly
127 128 129 130 |
# File 'lib/lapillus/base.rb', line 127 def response_page= page request_cycle = RequestCycle.get() request_cycle.response_page = page end |
#session ⇒ Object
TODO: this method is only tested indirectly
121 122 123 124 |
# File 'lib/lapillus/base.rb', line 121 def session request_cycle = RequestCycle.get() return request_cycle.session end |
#value ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/lapillus/base.rb', line 87 def value if property.nil? model else model.send(property) end end |
#webpage ⇒ Object
116 117 118 |
# File 'lib/lapillus/base.rb', line 116 def webpage hierarchy.first end |