Module: AssetsHelper

Defined in:
app/helpers/assets_helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_listing(asset) ⇒ Object



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

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

#audio_player(asset) ⇒ Object



46
47
48
# File 'app/helpers/assets_helper.rb', line 46

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

#display(asset) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/assets_helper.rb', line 30

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

#icon(asset, size = 30) ⇒ Object



7
8
9
# File 'app/helpers/assets_helper.rb', line 7

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

#image_tag(*args) ⇒ Object



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

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


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

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)


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

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

#square_thumb(image, size = 30) ⇒ Object



16
17
18
19
# File 'app/helpers/assets_helper.rb', line 16

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



11
12
13
14
# File 'app/helpers/assets_helper.rb', line 11

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



42
43
44
# File 'app/helpers/assets_helper.rb', line 42

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

#view_toggleObject



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

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