Class: RedmineCrm::Liquid::AttachmentDrop

Inherits:
Liquid::Drop
  • Object
show all
Defined in:
lib/redmine_crm/liquid/drops/attachment_drop.rb

Instance Method Summary collapse

Constructor Details

#initialize(attachment) ⇒ AttachmentDrop

Returns a new instance of AttachmentDrop.



21
22
23
# File 'lib/redmine_crm/liquid/drops/attachment_drop.rb', line 21

def initialize(attachment)
  @attachment = attachment
end

Instance Method Details

#authorObject



35
36
37
# File 'lib/redmine_crm/liquid/drops/attachment_drop.rb', line 35

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


31
32
33
# File 'lib/redmine_crm/liquid/drops/attachment_drop.rb', line 31

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

#readObject



39
40
41
42
43
44
# File 'lib/redmine_crm/liquid/drops/attachment_drop.rb', line 39

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

#url(options = {}) ⇒ Object



25
26
27
28
29
# File 'lib/redmine_crm/liquid/drops/attachment_drop.rb', line 25

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