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 ##
|
2010-06-02 14:31:01 +00:00
|
|
|
include Models::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
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
%w{image stylesheet javascript pdf video audio}.each do |type|
|
|
|
|
define_method("#{type}?") do
|
|
|
|
self.content_type == 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
|
|
|
|
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
|