Module: Fleximage::Helper

Defined in:
lib/fleximage/helper.rb

Instance Method Summary collapse

Instance Method Details

#embedded_image_tag(model, options = {}) ⇒ Object

Creates an image tag that links directly to image data. Recommended for displays of a temporary upload that is not saved to a record in the databse yet.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fleximage/helper.rb', line 6

def embedded_image_tag(model, options = {})
  model.load_image
  format  = options[:format] || :jpg
  mime    = Mime::Type.lookup_by_extension(format.to_s).to_s
  image   = model.output_image(:format => format)
  data    = Base64.encode64(image)
  
  options = { :alt => model.class.to_s }.merge(options)
  
  result = image_tag("data:#{mime};base64,#{data}", options)
  result.gsub(%r{src=".*/images/data:}, 'src="data:')
  
rescue Fleximage::Model::MasterImageNotFound => e
  nil
end

Creates a link that opens an image for editing in Aviary.

Options:

  • image_url: url to the master image used by Aviary for editing. Defauls to url_for(:action => 'aviary_image', :id => model, :only_path => false)

  • post_url: url where Aviary will post the updated image. Defauls to url_for(:action => 'aviary_image_update', :id => model, :only_path => false)

All other options are passed directly to the @link_to@ helper.



30
31
32
33
34
35
36
37
38
# File 'lib/fleximage/helper.rb', line 30

def link_to_edit_in_aviary(text, model, options = {})
  key       = aviary_image_hash(model)
  image_url = options.delete(:image_url)        || url_for(:action => 'aviary_image',        :id => model, :only_path => false, :key => key)
  post_url  = options.delete(:image_update_url) || url_for(:action => 'aviary_image_update', :id => model, :only_path => false, :key => key)
  api_key   = Fleximage::AviaryController.api_key
  url       = "http://aviary.com/flash/aviary/index.aspx?tid=1&phoenix&apil=#{api_key}&loadurl=#{CGI.escape image_url}&posturl=#{CGI.escape post_url}"
  
  link_to text, url, { :target => 'aviary' }.merge(options)
end