Class: Alchemy::Attachment
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- Alchemy::Attachment
- Includes:
- ContentTouching, Filetypes, NameConversions, Taggable
- Defined in:
- app/models/alchemy/attachment.rb
Constant Summary
Constants included from Filetypes
Filetypes::ARCHIVE_FILE_TYPES, Filetypes::AUDIO_FILE_TYPES, Filetypes::EXCEL_FILE_TYPES, Filetypes::IMAGE_FILE_TYPES, Filetypes::TEXT_FILE_TYPES, Filetypes::VCARD_FILE_TYPES, Filetypes::VIDEO_FILE_TYPES
Class Method Summary collapse
- .allowed_filetypes ⇒ Object
- .file_types_for_select ⇒ Object
- .searchable_alchemy_resource_attributes ⇒ Object
Instance Method Summary collapse
-
#extension ⇒ Object
(also: #suffix)
File format suffix.
-
#icon_css_class ⇒ Object
Returns a css class name for kind of file.
-
#restricted? ⇒ Boolean
Checks if the attachment is restricted, because it is attached on restricted pages only.
-
#to_jq_upload ⇒ Object
Instance methods.
-
#urlname ⇒ Object
An url save filename without format suffix.
Methods included from ContentTouching
Methods included from Taggable
Methods included from NameConversions
#convert_to_humanized_name, #convert_to_urlname
Methods inherited from BaseRecord
Class Method Details
.allowed_filetypes ⇒ Object
44 45 46 |
# File 'app/models/alchemy/attachment.rb', line 44 def allowed_filetypes Config.get(:uploader).fetch('allowed_filetypes', {}).fetch('alchemy/attachments', []) end |
.file_types_for_select ⇒ Object
48 49 50 51 52 53 |
# File 'app/models/alchemy/attachment.rb', line 48 def file_types_for_select file_types = Alchemy::Attachment.pluck(:file_mime_type).uniq.map do |type| [Alchemy.t(type, scope: 'mime_types'), type] end file_types.sort_by(&:first) end |
.searchable_alchemy_resource_attributes ⇒ Object
40 41 42 |
# File 'app/models/alchemy/attachment.rb', line 40 def searchable_alchemy_resource_attributes %w(name file_name) end |
Instance Method Details
#extension ⇒ Object Also known as: suffix
File format suffix
89 90 91 |
# File 'app/models/alchemy/attachment.rb', line 89 def extension file_name.split(".").last end |
#icon_css_class ⇒ Object
Returns a css class name for kind of file
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/alchemy/attachment.rb', line 96 def icon_css_class case file_mime_type when "application/pdf" then "file-pdf" when "application/msword" then "file-word" when *TEXT_FILE_TYPES then "file-alt" when *EXCEL_FILE_TYPES then "file-excel" when *VCARD_FILE_TYPES then "address-card" when *ARCHIVE_FILE_TYPES then "file-archive" when *AUDIO_FILE_TYPES then "file-audio" when *IMAGE_FILE_TYPES then "file-image" when *VIDEO_FILE_TYPES then "file-video" else "file" end end |
#restricted? ⇒ Boolean
Checks if the attachment is restricted, because it is attached on restricted pages only
84 85 86 |
# File 'app/models/alchemy/attachment.rb', line 84 def restricted? pages.any? && pages.not_restricted.blank? end |
#to_jq_upload ⇒ Object
Instance methods
70 71 72 73 74 75 76 |
# File 'app/models/alchemy/attachment.rb', line 70 def to_jq_upload { "name" => read_attribute(:file_name), "size" => read_attribute(:file_size), 'error' => errors[:file].join } end |
#urlname ⇒ Object
An url save filename without format suffix
79 80 81 |
# File 'app/models/alchemy/attachment.rb', line 79 def urlname CGI.escape(file_name.gsub(/\.#{extension}$/, '').tr('.', ' ')) end |