Sha256: b5f9ffc1b957c6563fe10b48ffcc51733b4e497720385179bf860fa3a3230fe5

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

module Admin

  module PreviewHelper

    def typus_preview(item, attribute)

      return unless item.send(attribute).exists?

      file_preview_is_image = (item.send("#{attribute}_content_type") =~ /^image\/.+/)

      unless file_preview_is_image
        file = File.basename(item.send(attribute).path(:original))
        link = link_to(file, :action => 'view', :id => item)
        return link
      end

      has_file_preview = item.send(attribute).styles.member?(Typus.file_preview)
      has_file_thumbnail = item.send(attribute).styles.member?(Typus.file_thumbnail)

      href = if has_file_preview && file_preview_is_image
               url = item.send(attribute).url(Typus.file_preview)
               # FIXME: This has changed on Rails3.
               # ActionController::Base.relative_url_root + url
             else
               item.send(attribute)
             end

      content = if has_file_thumbnail && file_preview_is_image
                  image_tag item.send(attribute).url(Typus.file_thumbnail)
                else
                  item.send(attribute)
                end

      render "admin/helpers/preview",
             :attribute => attribute,
             :content => content,
             :file_preview_is_image => file_preview_is_image,
             :has_file_preview => has_file_preview,
             :href => href,
             :item => item

    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
typus-3.0.2 app/helpers/admin/preview_helper.rb
typus-3.0.1 app/helpers/admin/preview_helper.rb
typus-3.0.0 app/helpers/admin/preview_helper.rb
typus-1.0.0.pre13 app/helpers/admin/preview_helper.rb
typus-1.0.0.pre12 app/helpers/admin/preview_helper.rb
typus-1.0.0.pre11 app/helpers/admin/preview_helper.rb
typus-1.0.0.pre10 app/helpers/admin/preview_helper.rb
typus-1.0.0.pre9 app/helpers/admin/preview_helper.rb