Module: PushType::AssetsHelper

Includes:
MediaUrlHelper
Included in:
PushType::Admin::AssetsController
Defined in:
app/helpers/push_type/assets_helper.rb

Instance Method Summary collapse

Instance Method Details



31
32
33
34
35
36
37
# File 'app/helpers/push_type/assets_helper.rb', line 31

def asset_back_link(asset)
  if asset.trashed?
    push_type_admin.trash_assets_path
  else
    push_type_admin.assets_path
  end
end

#asset_hash(asset) ⇒ Object



10
11
12
13
14
15
16
17
# File 'app/helpers/push_type/assets_helper.rb', line 10

def asset_hash(asset)
  return nil if asset.nil?
  hash = [ :id, :file_name, :file_size, :mime_type, :created_at, :new_record?, :image?, :description_or_file_name ].inject({}) do |h, att|
    h.update att => asset.send(att)
  end
  hash.update url: media_path(asset), preview_thumb_url: asset_preview_thumb_url(asset) if asset.persisted?
  hash
end

#asset_icon(asset) ⇒ Object



27
28
29
# File 'app/helpers/push_type/assets_helper.rb', line 27

def asset_icon(asset)
  "push_type/icons-assets.svg##{ asset.kind }"
end

#asset_preview_thumb_url(asset) ⇒ Object



19
20
21
22
23
24
25
# File 'app/helpers/push_type/assets_helper.rb', line 19

def asset_preview_thumb_url(asset)
  if asset.image? && !asset.svg?
    media_path(asset, style: :push_type_thumb)
  else
    image_path(asset_icon(asset))
  end
end

#assets_array(assets) ⇒ Object



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

def assets_array(assets)
  assets.map { |a| asset_hash(a) }
end