Sha256: 5014f427cadb99296808d1ab574726e0827cc98f1f1cf949f167ab43ac5b16c9

Contents?: true

Size: 1.51 KB

Versions: 23

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

23 entries across 23 versions & 1 rubygems

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