Sha256: b92ed4f2ca04da3bf26b59dd298e005aefc5b6f3c4d756a1b7d0f0bbb1ea35ff

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

module RedmineCrm
  module Liquid
    class AttachmentDrop < ::Liquid::Drop
      delegate :id,
               :filename,
               :title,
               :description,
               :filesize,
               :content_type,
               :digest,
               :downloads,
               :created_on,
               :token,
               :visible?,
               :image?,
               :thumbnailable?,
               :is_text?,
               :readable?,
               to: :@attachment

      def initialize(attachment)
        @attachment = attachment
      end

      def url(options = {})
        Rails.application.routes.url_helpers.download_named_attachment_url(@attachment, { filename: filename,
                                                                                          host: Setting.host_name,
                                                                                          protocol: Setting.protocol }.merge(options))
      end

      def link
        link_to((@attachment.description.blank? ? @attachment.filename : @attachment.description), url)
      end

      def author
        @author ||= UserDrop.new @attachment.author
      end

      def read
        @content ||= if @attachment.is_text? && @attachment.filesize <= Setting.file_max_size_displayed.to_i.kilobyte
                       File.new(@attachment.diskfile, "rb").read
                     end
        @content
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redmine_crm-0.0.63 lib/redmine_crm/liquid/drops/attachment_drop.rb
redmine_crm-0.0.62 lib/redmine_crm/liquid/drops/attachment_drop.rb
redmine_crm-0.0.61 lib/redmine_crm/liquid/drops/attachment_drop.rb
redmine_crm-0.0.60 lib/redmine_crm/liquid/drops/attachment_drop.rb