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
|
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
## extensions ##
|
|
|
|
include Extensions::Asset::Types
|
|
|
|
include Extensions::Asset::Vignette
|
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
## fields ##
|
|
|
|
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 ##
|
2011-06-17 21:32:54 +00:00
|
|
|
referenced_in :site
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-12 00:16:39 +00:00
|
|
|
## validations ##
|
2011-06-17 21:32:54 +00:00
|
|
|
validates_presence_of :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-03-05 22:27:26 +00:00
|
|
|
def extname
|
|
|
|
return nil unless self.source?
|
|
|
|
File.extname(self.source_filename).gsub(/^\./, '')
|
|
|
|
end
|
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def to_liquid
|
2011-06-21 00:39:59 +00:00
|
|
|
{ :url => self.source.url }.merge(self.attributes).stringify_keys
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|