Class: Lapillus::Component

Inherits:
Object show all
Defined in:
lib/lapillus/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#behavioursObject (readonly)

Returns the value of attribute behaviours.



4
5
6
# File 'lib/lapillus/base.rb', line 4

def behaviours
  @behaviours
end

#identifierObject (readonly)

Returns the value of attribute identifier.



4
5
6
# File 'lib/lapillus/base.rb', line 4

def identifier
  @identifier
end

#modelObject

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

#propertyObject (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

Parameters:

  • value

    the value to set the attribute visible to.



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

Returns:

  • (Boolean)


82
83
84
# File 'lib/lapillus/base.rb', line 82

def has_behaviour?(behaviour_class)
  return behaviour(behaviour_class)
end

#has_model?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


45
46
47
# File 'lib/lapillus/base.rb', line 45

def has_parent?
  !@parent.nil?
end

#on_renderObject



33
34
# File 'lib/lapillus/base.rb', line 33

def on_render
end

#parentObject



21
22
23
24
# File 'lib/lapillus/base.rb', line 21

def parent
  raise "parent not set!" if @parent.nil?
  @parent
end

#pathObject

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_componentObject

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 
    message = "Identifier "+identifier+" not found! in "+doc.to_s
    raise message
  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

#sessionObject

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

#valueObject



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

Returns:

  • (Boolean)


36
37
38
# File 'lib/lapillus/base.rb', line 36

def visible?
  @visible
end

#webpageObject



61
62
63
# File 'lib/lapillus/base.rb', line 61

def webpage
  hierarchy.first
end