Class: Lapillus::Image

Inherits:
Component show all
Defined in:
lib/lapillus/components.rb

Overview

TODO: root_url could be extracted from application object but the question is how can an image object easily get the application object?

Instance Attribute Summary collapse

Attributes inherited from Component

#behaviours, #identifier, #model, #property, #visible

Instance Method Summary collapse

Methods inherited from Component

#add_behaviour, #behaviour, #has_behaviour?, #has_model?, #has_parent?, #on_render, #parent, #path, #render_component, #response_page=, #session, #value, #visible?, #webpage

Constructor Details

#initialize(id, model, root_url) ⇒ Image

Returns a new instance of Image.



87
88
89
90
91
# File 'lib/lapillus/components.rb', line 87

def initialize(id, model, root_url)
  super(id, model)
  raise "root_url is not set!" if root_url.nil?
  @root_url = root_url
end

Instance Attribute Details

#root_urlObject (readonly)

Returns the value of attribute root_url.



85
86
87
# File 'lib/lapillus/components.rb', line 85

def root_url
  @root_url
end

Instance Method Details

#render_to_element(element) ⇒ Object



93
94
95
96
97
# File 'lib/lapillus/components.rb', line 93

def render_to_element(element)
  url = "/images/#{value}"
  url = root_url + url  if root_url != "/"
  element.add_attribute("src", url)
end