Module: EffectiveAssetsHelper

Defined in:
app/helpers/effective_assets_helper.rb

Instance Method Summary collapse

Instance Method Details

#_effective_asset_image_url(asset, version = nil) ⇒ Object



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

def _effective_asset_image_url(asset, version = 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?
    asset.url
  elsif asset.image?
    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.png')
  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
# 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

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

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


21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/effective_assets_helper.rb', line 21

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

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

#effective_asset_title(asset) ⇒ Object



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

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

#effective_asset_video_tag(asset) ⇒ Object



32
33
34
# File 'app/helpers/effective_assets_helper.rb', line 32

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