Class: Lapillus::Component

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  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 !options.kind_of?(Hash)
  @identifier = id
  @model = options[:model]
  @property = options[:property]
  @visible = options[:visible]||true
end

Instance Attribute Details

#behavioursObject (readonly)

Returns the value of attribute behaviours.



64
65
66
# File 'lib/lapillus/base.rb', line 64

def behaviours
  @behaviours
end

#identifierObject (readonly)

Returns the value of attribute identifier.



64
65
66
# File 'lib/lapillus/base.rb', line 64

def identifier
  @identifier
end

#modelObject

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

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

Parameters:

  • value

    the value to set the attribute visible to.



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

Returns:

  • (Boolean)


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

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

#has_model?Boolean

Returns:

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

Returns:

  • (Boolean)


100
101
102
# File 'lib/lapillus/base.rb', line 100

def has_parent?
  !@parent.nil?
end

#parentObject



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

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…



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

#sessionObject

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

#valueObject



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

#webpageObject



116
117
118
# File 'lib/lapillus/base.rb', line 116

def webpage
  hierarchy.first
end