Sha256: 6c0370db130b18b43f01ce4f959986bda57c9dd41984337c62415e3e419ebb00

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

class Skyline::ImageRef < Skyline::InlineRef
  
  # 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
  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
    
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skylinecms-3.0.7 app/models/skyline/image_ref.rb