Class: Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Asset
- Includes:
- Sprockets::Helpers::IsolatedHelper, Sprockets::Helpers::RailsHelper
- Defined in:
- lib/forge/app/models/asset.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dimensions(style = :original) ⇒ Object
- #icon_path ⇒ Object
- #is_image? ⇒ Boolean
- #list_title ⇒ Object
- #swfupload_file!(data, filename) ⇒ Object
Class Method Details
.for_drawer(params) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/forge/app/models/asset.rb', line 32 def self.for_drawer(params) unless params[:q].blank? assets = where("assets.title LIKE ? OR tags.name = ?", "%#{params[:q]}%", params[:q]).includes(:taggings => :tag) else case params[:filter] when "images" assets = where("attachment_content_type LIKE ?", "%image%") when "documents" assets = where("attachment_content_type NOT LIKE ?", "%image%") else assets = self end end assets.limit(20).offset(params[:offset] || 0) end |
Instance Method Details
#dimensions(style = :original) ⇒ Object
28 29 30 |
# File 'lib/forge/app/models/asset.rb', line 28 def dimensions(style = :original) Paperclip::Geometry.from_file(self..to_file(style)).to_s.split('x') end |
#icon_path ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/forge/app/models/asset.rb', line 48 def icon_path case when /image/ .url(:thumbnail) when /audio/ asset_path "forge/asset-icons/audio.jpg" when /excel/ asset_path "forge/asset-icons/spreadsheet.jpg" when /pdf/ asset_path "forge/asset-icons/pdf.jpg" else asset_path "forge/asset-icons/misc.jpg" end end |
#is_image? ⇒ Boolean
24 25 26 |
# File 'lib/forge/app/models/asset.rb', line 24 def is_image? self. =~ /image/ end |
#list_title ⇒ Object
20 21 22 |
# File 'lib/forge/app/models/asset.rb', line 20 def list_title self.title.size > 16 ? self.title[0..15].strip + '...' : self.title end |
#swfupload_file!(data, filename) ⇒ Object
14 15 16 17 18 |
# File 'lib/forge/app/models/asset.rb', line 14 def swfupload_file!(data, filename) data.content_type = MIME::Types.type_for(data.original_filename).to_s self. = data self.title = filename end |