Sha256: 805ac7a01c4973622784ebfa5ca3ded9da960d00e6c7adad96f6df50aff79bda

Contents?: true

Size: 1.51 KB

Versions: 10

Compression:

Stored size: 1.51 KB

Contents

module Tenon
  module AssetHelper
    def asset_icon(asset)
      if asset.attachment.exists?(:thumbnail)
        image = image_tag(asset.attachment.url(:thumbnail))
      else
        image = image_tag(default_asset_thumbnail(asset))
      end
      asset_icon_link(asset, image)
    end

    def asset_icon_link(asset, icon)
      if asset.is_image?
        link_to(icon, [:crop, asset], crop_options(asset))
      else
        link_to(icon, asset.attachment.url, target: '_')
      end
    end

    def asset_tile(asset)
      if asset.attachment.exists?(:tile)
        image = image_tag(asset.attachment.url(:tile))
      else
        image = image_tag(default_asset_thumbnail(asset))
      end
      asset_tile_link(asset, image)
    end

    def asset_tile_link(asset, icon)
      if asset.is_image?
        link_to(icon, [:crop, asset], crop_options(asset))
      else
        link_to(icon, asset.attachment.url, target: '_')
      end
    end

    def default_asset_thumbnail(asset)
      if asset && asset.attachment_content_type.match('video')
        'tenon/thumb-video.png'
      else
        'tenon/thumb-doc.png'
      end
    end

    private
      def crop_options(asset)
        {
          class: 'asset-crop',
          data: {
            'asset-id' => asset.id,
            'post-crop-handler' => 'Tenon.features.AssetListPostCropHandler'
          }
        }
      end

      def default_options
        {
          'data-modal-remote' => true,
          'data-modal-title' => 'Edit Asset'
        }
      end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tenon-2.1.0 app/helpers/tenon/asset_helper.rb
tenon-2.0.8 app/helpers/tenon/asset_helper.rb
tenon-2.0.7 app/helpers/tenon/asset_helper.rb
tenon-2.0.6 app/helpers/tenon/asset_helper.rb
tenon-2.0.5 app/helpers/tenon/asset_helper.rb
tenon-2.0.4 app/helpers/tenon/asset_helper.rb
tenon-2.0.3 app/helpers/tenon/asset_helper.rb
tenon-2.0.2 app/helpers/tenon/asset_helper.rb
tenon-2.0.1 app/helpers/tenon/asset_helper.rb
tenon-2.0.0 app/helpers/tenon/asset_helper.rb