Module: AssetsHelper

Defined in:
app/helpers/assets_helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_grid_item(asset) ⇒ Object



8
9
10
11
12
# File 'app/helpers/assets_helper.rb', line 8

def asset_grid_item(asset)
  asset_icon(asset, 120) +
  (:span, "ID: #{asset.id}", :class => 'id') +
  (:span, asset.to_s, :class => 'caption')
end

#asset_icon(asset, size = 30) ⇒ Object



14
15
16
# File 'app/helpers/assets_helper.rb', line 14

def asset_icon(asset, size=30)
  asset.image? ? square_thumb(asset, size) : text_icon(asset, size)
end

#asset_listing(asset) ⇒ Object



3
4
5
6
# File 'app/helpers/assets_helper.rb', line 3

def asset_listing(asset)
  asset_icon(asset) +
  (:span, asset.to_s, :class=>'title')
end

#audio_player(asset) ⇒ Object



53
54
55
# File 'app/helpers/assets_helper.rb', line 53

def audio_player(asset)
  %Q{<audio src="#{asset.upload.url}" type="#{asset.upload.mime_type}" controls="controls">}
end

#display(asset) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/assets_helper.rb', line 37

def display(asset)
  if @asset.image?
     :div, image_tag(@asset), :class => "image frame #{@asset.format}"
  elsif @asset.audio?
    audio_player(@asset)
  elsif @asset.video?
    video_player(@asset)
  elsif @asset.format == :pdf
     :iframe, '', :src => @asset.upload.url, :class => "pdf frame"
  end
end

#image_tag(*args) ⇒ Object



28
29
30
31
32
33
34
35
# File 'app/helpers/assets_helper.rb', line 28

def image_tag(*args)
  image = args.first
  if image && image.respond_to?(:upload)
    super image.upload.url, :width => image.upload.width, :height => image.upload.height
  else
    super(*args)
  end
end


57
58
59
# File 'app/helpers/assets_helper.rb', line 57

def link_to_remove(asset)
  link_to 'Remove', remove_admin_asset_path(asset), :class => 'action remove', :title => 'Remove Asset'
end

#list_view?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/helpers/assets_helper.rb', line 61

def list_view?
  params[:view] == 'list'
end

#square_thumb(image, size = 30) ⇒ Object



23
24
25
26
# File 'app/helpers/assets_helper.rb', line 23

def square_thumb(image, size=30)
  src = image.upload.thumb("#{size}x#{size}#").url
  image_tag(src, :width=>size, :height => size, :class => "thumbnail #{image.format}")
end

#text_icon(asset, size = 30) ⇒ Object



18
19
20
21
# File 'app/helpers/assets_helper.rb', line 18

def text_icon(asset, size=30)
  css = "width:#{size}px;height:#{size}px;line-height:#{size}px"
  (:span, asset.format, :class => "icon #{asset.format}", :style => css)
end

#video_player(asset) ⇒ Object



49
50
51
# File 'app/helpers/assets_helper.rb', line 49

def video_player(asset)
  %Q{<video src="#{asset.upload.url}" type="#{asset.upload.mime_type}" controls="controls">}
end

#view_toggleObject



65
66
67
68
# File 'app/helpers/assets_helper.rb', line 65

def view_toggle
  other = list_view? ? 'grid' : 'list'
  link_to "Switch to #{other} view", admin_assets_path(:view => other)
end