2010-06-01 00:06:46 +00:00
|
|
|
class Asset
|
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
include Mongoid::Document
|
2010-06-08 00:45:49 +00:00
|
|
|
include Mongoid::Timestamps
|
2010-05-12 00:16:39 +00:00
|
|
|
|
2010-06-02 14:31:01 +00:00
|
|
|
## Extensions ##
|
|
|
|
include Models::Extensions::Asset::Vignette
|
2010-06-08 00:45:49 +00:00
|
|
|
include CustomFields::ProxyClassEnabler
|
2010-06-02 14:31:01 +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
|
|
|
|
|
|
|
|
## associations ##
|
|
|
|
embedded_in :collection, :class_name => 'AssetCollection', :inverse_of => :assets
|
|
|
|
|
|
|
|
## validations ##
|
|
|
|
validates_presence_of :name, :source
|
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
## behaviours ##
|
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
## methods ##
|
|
|
|
|
|
|
|
%w{image stylesheet javascript pdf video audio}.each do |type|
|
|
|
|
define_method("#{type}?") do
|
|
|
|
self.content_type == type
|
|
|
|
end
|
|
|
|
end
|
2010-05-30 23:57:33 +00:00
|
|
|
|
|
|
|
def to_liquid
|
|
|
|
{ :url => self.source.url }.merge(self.attributes)
|
|
|
|
end
|
2010-05-17 20:46:41 +00:00
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
end
|