Class: Lapillus::Component
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, model = nil, property = nil) ⇒ Component
constructor
A new instance of Component.
- #on_render ⇒ Object
- #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…
-
#render_component ⇒ Object
this method is meant for AJAX.
-
#response_page=(page) ⇒ Object
TODO: this method is only tested indirectly.
-
#session ⇒ Object
TODO: this method is only tested indirectly.
- #value ⇒ Object
- #visible? ⇒ Boolean
- #webpage ⇒ Object
Constructor Details
#initialize(id, model = nil, property = nil) ⇒ Component
Returns a new instance of Component.
6 7 8 9 10 11 12 |
# File 'lib/lapillus/base.rb', line 6 def initialize(id, model=nil, property=nil) @identifier = id @model = model @property = property @behaviours = {} @visible = true end |
Instance Attribute Details
#behaviours ⇒ Object (readonly)
Returns the value of attribute behaviours.
4 5 6 |
# File 'lib/lapillus/base.rb', line 4 def behaviours @behaviours end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/lapillus/base.rb', line 4 def identifier @identifier end |
#model ⇒ Object
TODO: make model defensive!
14 15 16 17 18 19 20 |
# File 'lib/lapillus/base.rb', line 14 def model if @model.kind_of?(Symbol) parent.send(@model) else @model end end |
#property ⇒ Object (readonly)
Returns the value of attribute property.
4 5 6 |
# File 'lib/lapillus/base.rb', line 4 def property @property end |
#visible=(value) ⇒ Object (writeonly)
Sets the attribute visible
5 6 7 |
# File 'lib/lapillus/base.rb', line 5 def visible=(value) @visible = value end |
Instance Method Details
#add_behaviour(behaviour) ⇒ Object
77 78 79 80 |
# File 'lib/lapillus/base.rb', line 77 def add_behaviour(behaviour) behaviour.parent=self @behaviours[behaviour.class] = behaviour end |
#behaviour(behaviour_class) ⇒ Object
86 87 88 |
# File 'lib/lapillus/base.rb', line 86 def behaviour(behaviour_class) return @behaviours[behaviour_class] end |
#has_behaviour?(behaviour_class) ⇒ Boolean
82 83 84 |
# File 'lib/lapillus/base.rb', line 82 def has_behaviour?(behaviour_class) return behaviour(behaviour_class) end |
#has_model? ⇒ Boolean
40 41 42 |
# File 'lib/lapillus/base.rb', line 40 def has_model? !@model.nil? end |
#has_parent? ⇒ Boolean
TODO: test parent, hierarchy, path, page
45 46 47 |
# File 'lib/lapillus/base.rb', line 45 def has_parent? !@parent.nil? end |
#on_render ⇒ Object
33 34 |
# File 'lib/lapillus/base.rb', line 33 def on_render end |
#parent ⇒ Object
21 22 23 24 |
# File 'lib/lapillus/base.rb', line 21 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…
51 52 53 54 55 56 57 58 59 |
# File 'lib/lapillus/base.rb', line 51 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 |
#render_component ⇒ Object
this method is meant for AJAX
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/lapillus/base.rb', line 91 def render_component doc = REXML::Document.new webpage.default_htmlfile result_dom = webpage.render_container(doc.root) element = REXML::XPath.first( result_dom, "//*[@id=\"#{path}\"]" ) if element == nil = "Identifier "+identifier+" not found! in "+doc.to_s raise end to_send = element.children.inject("") {|result, child| child.write(result) } # puts "DEBUG: "+to_send return to_send end |
#response_page=(page) ⇒ Object
TODO: this method is only tested indirectly
72 73 74 75 |
# File 'lib/lapillus/base.rb', line 72 def response_page= page request_cycle = RequestCycle.get() request_cycle.response_page = page end |
#session ⇒ Object
TODO: this method is only tested indirectly
66 67 68 69 |
# File 'lib/lapillus/base.rb', line 66 def session request_cycle = RequestCycle.get() return request_cycle.session end |
#value ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/lapillus/base.rb', line 25 def value if property.nil? model else model.send(property) end end |
#visible? ⇒ Boolean
36 37 38 |
# File 'lib/lapillus/base.rb', line 36 def visible? @visible end |
#webpage ⇒ Object
61 62 63 |
# File 'lib/lapillus/base.rb', line 61 def webpage hierarchy.first end |