Class: OrangeAsset

Inherits:
Orange::Carton show all
Defined in:
lib/orange-more/assets/cartons/asset_carton.rb

Instance Method Summary collapse

Methods inherited from Orange::Carton

asset

Instance Method Details

#file?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/orange-more/assets/cartons/asset_carton.rb', line 35

def file?
  !(pdf? || image?)
end

#file_pathObject



15
16
17
18
19
20
21
# File 'lib/orange-more/assets/cartons/asset_carton.rb', line 15

def file_path
  if(s3_bucket)
    "http://s3.amazonaws.com/#{s3_bucket}/#{path}"
  else
    File.join('', 'assets', 'uploaded', path)
  end
end

#image?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/orange-more/assets/cartons/asset_carton.rb', line 32

def image?
  mime_type =~ /^image/
end

#pdf?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/orange-more/assets/cartons/asset_carton.rb', line 29

def pdf?
  mime_type =~ /^application\/pdf/
end

#to_asset_tag(alt = "") ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/orange-more/assets/cartons/asset_carton.rb', line 39

def to_asset_tag(alt = "")
  alt = alt.blank? ? caption : alt
  alt = alt.blank? ? name : alt
  case mime_type
  when /^image/
    "<img src='#{file_path}' border='0' alt='#{alt}' />"
  when /^application\/pdf/
    "<span class='pdf_link'><a href='#{file_path}'>#{alt}</a></span>"
  else
    "<span class='file_link'><a href='#{file_path}'>#{alt}</a></span>"
  end
end

#to_sObject



23
24
25
26
27
# File 'lib/orange-more/assets/cartons/asset_carton.rb', line 23

def to_s
  <<-DOC
  {"id": #{self.id}, "name": "#{self.name}", "caption": "#{self.caption}", "html": "#{self.to_asset_tag}"}
  DOC
end