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?, #parent, #path, #response_page=, #session, #value, #webpage

Methods inherited from RenderableComponent

#on_render, #render_behaviours, #render_children, #render_component, #render_container, #visible?

Constructor Details

#initialize(id, options = {}) ⇒ Image

Returns a new instance of Image.



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

def initialize(id, options={})
  super(id, options)
  root_url = options[:root_url]
  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.



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

def root_url
  @root_url
end

Instance Method Details

#render_to_element(element) ⇒ Object



95
96
97
98
99
# File 'lib/lapillus/components.rb', line 95

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