Class: Skyline::ImageRef

Inherits:
InlineRef show all
Defined in:
app/models/skyline/image_ref.rb

Instance Attribute Summary

Attributes inherited from InlineRef

#previous_referable

Instance Method Summary collapse

Methods inherited from InlineRef

convert, hash_refs_for_object, parse_html

Instance Method Details

#to_start_html(skyline_attr = false, options = {}) ⇒ Object

Render html for specified RefObject

Parameters

skyline_attr<Boolean>

boolean that sets if skyline attributes should be added to the html tag

Returns

html image tag



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/skyline/image_ref.rb', line 9

def to_start_html(skyline_attr = false,options={})
  options.reverse_merge! :nullify => false
  html_options = {}.merge(self.options)
  
  #TODO: get default image from options

  src = "broken.jpg"
  
  if self.referable_id.present? && image = self.referable_type.constantize.find_by_id(self.referable_id)
    if html_options["width"].blank? || html_options["height"].blank?
      dimen = image.dimension
      html_options.reverse_merge! dimen
    end
    src = image.url("#{html_options["width"]}x#{html_options["height"]}")
  end
  
  skyline_ref_id = options[:nullify] ? "" : self.id
  
  if skyline_attr
    skyline_prefix = "/skyline"
    html_options.update "skyline-ref-id" => skyline_ref_id, "skyline-referable-id" => self.referable_id, "skyline-referable-type" => self.referable_type
  end
  option_str = html_options.collect{|k,v| "#{k}=\"#{v}\""}.join(" ")
  
  html_str = "<img src=\"#{skyline_prefix}#{src}\" #{option_str} />"
end