Module: EffectiveAssetsHelper

Defined in:
app/helpers/effective_assets_helper.rb

Instance Method Summary collapse

Instance Method Details

#_effective_asset_image_url(asset, version = nil, public_url = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/effective_assets_helper.rb', line 47

def _effective_asset_image_url(asset, version = nil, public_url = nil)
  # asset_url and image_url will work in Rails4

  return image_path('mime-types/file.png') if !asset.content_type.present? or asset.content_type == 'unknown'

  if asset.icon?
    (public_url ? asset.public_url : asset.url)
  elsif asset.image?
    (public_url ? asset.public_url(version) : asset.url(version))
  elsif asset.audio?
    image_path('mime-types/mp3.png')
  elsif asset.video?
    image_path('mime-types/video.png')
  elsif asset.content_type.include? 'msword'
    image_path('mime-types/word.jpg')
  elsif asset.content_type.include? 'excel'
    image_path('mime-types/excel.jpg')
  elsif asset.content_type.include? 'application/pdf'
    image_path('mime-types/pdf.png')
  elsif asset.content_type.include? 'application/zip'
    image_path('mime-types/zip.png')
  else
    image_path('mime-types/file.png')
  end
end

#effective_asset_image_tag(asset, version = nil, options = {}) ⇒ Object

Generates an image tag based on the particular asset



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/effective_assets_helper.rb', line 3

def effective_asset_image_tag(asset, version = nil, options = {})
  if asset.image? == false
    opts = {}
  elsif version.present? and asset.versions_info[version].present?
    opts = { :height => asset.versions_info[version][:height], :width => asset.versions_info[version][:width] }
  elsif version.present? and asset.data.respond_to?(:versions_info) and asset.data.versions_info[version].present?
    opts = { :height => asset.data.versions_info[version][:height], :width => asset.data.versions_info[version][:width] }
  elsif asset.height.present? and asset.width.present?
    opts = { :height => asset.height, :width => asset.width }
  else
    opts = {}
  end

  public_url = options.delete(:public) || options.delete(:public_url)

  opts = opts.merge({:alt => asset.title || asset.file_name}).merge(options)

  (:img, nil, opts.merge(:src => _effective_asset_image_url(asset, version, public_url))).gsub('"', "'").html_safe
end


23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/effective_assets_helper.rb', line 23

def effective_asset_link_to(asset, version = nil, options = {})
  options_title = options.delete(:title)
  public_url = options.delete(:public) || options.delete(:public_url)
  link_title = options_title || asset.title || asset.file_name || "Asset ##{asset.id}"

  if asset.image?
    link_to(link_title, _effective_asset_image_url(asset, version, public_url), options)
  else
    link_to(link_title, (public_url ? asset.public_url : asset.url), options)
  end.gsub('"', "'").html_safe # we need all ' quotes or it breaks Insert as functionality
end

#effective_asset_title(asset) ⇒ Object



39
40
41
42
43
44
45
# File 'app/helpers/effective_assets_helper.rb', line 39

def effective_asset_title(asset)
  [
    asset.title,
    "Size: #{number_to_human_size(asset.data_size)}",
    "Content Type: #{asset.content_type}"
  ].compact.join("\n")
end

#effective_asset_video_tag(asset, version = nil, options = {}) ⇒ Object



35
36
37
# File 'app/helpers/effective_assets_helper.rb', line 35

def effective_asset_video_tag(asset, version = nil, options = {})
  render(:partial => 'effective/assets/video', :locals => { :asset => asset }).gsub('"', "'").html_safe # we need all ' quotes or it breaks Insert as functionality
end