2010-07-23 20:09:54 +00:00
|
|
|
class Asset
|
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
include Mongoid::Document
|
2010-07-23 20:09:54 +00:00
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
## Extensions ##
|
2011-04-01 00:34:19 +00:00
|
|
|
include Extensions::Asset::Vignette
|
2010-06-08 00:45:49 +00:00
|
|
|
include CustomFields::ProxyClassEnabler
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
## fields ##
|
|
|
|
field :name, :type => String
|
|
|
|
field :content_type, :type => String
|
|
|
|
field :width, :type => Integer
|
|
|
|
field :height, :type => Integer
|
|
|
|
field :size, :type => Integer
|
|
|
|
field :position, :type => Integer, :default => 0
|
|
|
|
mount_uploader :source, AssetUploader
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
## associations ##
|
|
|
|
embedded_in :collection, :class_name => 'AssetCollection', :inverse_of => :assets
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
## validations ##
|
|
|
|
validates_presence_of :name, :source
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
## behaviours ##
|
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
## methods ##
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-02-18 23:51:57 +00:00
|
|
|
%w{image stylesheet javascript pdf media}.each do |type|
|
2010-05-12 00:16:39 +00:00
|
|
|
define_method("#{type}?") do
|
2011-01-26 13:07:33 +00:00
|
|
|
self.content_type.to_s == type
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
2010-05-12 00:16:39 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-03-05 22:27:26 +00:00
|
|
|
def extname
|
|
|
|
return nil unless self.source?
|
|
|
|
File.extname(self.source_filename).gsub(/^\./, '')
|
|
|
|
end
|
|
|
|
|
2010-10-10 23:16:43 +00:00
|
|
|
def site_id # needed by the uploader of custom fields
|
|
|
|
self.collection.site_id
|
|
|
|
end
|
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def to_liquid
|
2010-09-28 22:08:11 +00:00
|
|
|
Locomotive::Liquid::Drops::Asset.new(self)
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|