Sha256: 845859d1f5eaf39169ee8d5750fd8367fba6699e206e769be5ccfadb7812824b

Contents?: true

Size: 1.2 KB

Versions: 23

Compression:

Stored size: 1.2 KB

Contents

module Tenon
  class AssetDecorator < ApplicationDecorator
    def icon
      h.asset_icon(object)
    end

    def tile
      h.asset_tile(object)
    end

    def human_size
      h.number_to_human_size(object.attachment_file_size)
    end

    def display_name
      name = object.title.blank? ? object.attachment_file_name : object.title
      h.truncate(name, length: 50)
    end

    def crop_link
      h.action_link(
        'Crop',
        [:crop, object],
        'crop',
        class: 'asset-crop',
        data: {
          'asset-id' => object.id,
          'post-crop-handler' => 'Tenon.features.AssetListPostCropHandler'
        }
      ) if object.attachment_content_type.include?('image') || object.attachment_content_type.include?('video')
    end

    def edit_link(opts = {})
      defaults = {
        'data-modal-remote' => true,
        'data-modal-title' => 'Edit Asset'
      }
      super(opts.merge(defaults))
    end

    def download_link
      h.action_link('Download', object.attachment.url, 'download', target: '_')
    end

    def style_urls
      styles = object.attachment.styles.map do |key, style|
        [key, object.attachment.url(key)]
      end
      Hash[styles]
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
tenon-1.1.4 app/decorators/tenon/asset_decorator.rb
tenon-1.1.3 app/decorators/tenon/asset_decorator.rb
tenon-1.1.2 app/decorators/tenon/asset_decorator.rb
tenon-1.1.1 app/decorators/tenon/asset_decorator.rb
tenon-1.0.76 app/decorators/tenon/asset_decorator.rb
tenon-1.0.75 app/decorators/tenon/asset_decorator.rb
tenon-1.0.74 app/decorators/tenon/asset_decorator.rb
tenon-1.0.73 app/decorators/tenon/asset_decorator.rb
tenon-1.0.72 app/decorators/tenon/asset_decorator.rb
tenon-1.0.71 app/decorators/tenon/asset_decorator.rb
tenon-1.0.70 app/decorators/tenon/asset_decorator.rb
tenon-1.0.69 app/decorators/tenon/asset_decorator.rb
tenon-1.0.68 app/decorators/tenon/asset_decorator.rb
tenon-1.0.67 app/decorators/tenon/asset_decorator.rb
tenon-1.0.66 app/decorators/tenon/asset_decorator.rb
tenon-1.0.65 app/decorators/tenon/asset_decorator.rb
tenon-1.0.64 app/decorators/tenon/asset_decorator.rb
tenon-1.0.63 app/decorators/tenon/asset_decorator.rb
tenon-1.0.62 app/decorators/tenon/asset_decorator.rb
tenon-1.0.61 app/decorators/tenon/asset_decorator.rb