2011-10-30 23:02:41 +00:00
|
|
|
module Locomotive
|
2011-11-19 14:47:56 +00:00
|
|
|
class ContentAsset
|
2011-10-30 23:02:41 +00:00
|
|
|
|
2011-11-10 21:41:20 +00:00
|
|
|
include ::Mongoid::Document
|
|
|
|
include ::Mongoid::Timestamps
|
2011-10-30 23:02:41 +00:00
|
|
|
|
|
|
|
## extensions ##
|
|
|
|
include Extensions::Asset::Types
|
|
|
|
include Extensions::Asset::Vignette
|
|
|
|
|
|
|
|
## fields ##
|
|
|
|
field :content_type, :type => String
|
|
|
|
field :width, :type => Integer
|
|
|
|
field :height, :type => Integer
|
|
|
|
field :size, :type => Integer
|
|
|
|
field :position, :type => Integer, :default => 0
|
2011-11-19 14:47:56 +00:00
|
|
|
mount_uploader :source, ContentAssetUploader, :mount_on => :source_filename
|
2011-10-30 23:02:41 +00:00
|
|
|
|
|
|
|
## associations ##
|
2011-12-16 12:02:10 +00:00
|
|
|
belongs_to :site, :class_name => 'Locomotive::Site'
|
2011-10-30 23:02:41 +00:00
|
|
|
|
|
|
|
## validations ##
|
|
|
|
validates_presence_of :source
|
|
|
|
|
|
|
|
## behaviours ##
|
|
|
|
|
|
|
|
## methods ##
|
|
|
|
|
|
|
|
alias :name :source_filename
|
|
|
|
|
|
|
|
def extname
|
|
|
|
return nil unless self.source?
|
|
|
|
File.extname(self.source_filename).gsub(/^\./, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_liquid
|
|
|
|
{ :url => self.source.url }.merge(self.attributes).stringify_keys
|
|
|
|
end
|
|
|
|
|
2011-11-19 14:47:56 +00:00
|
|
|
def as_json(options = {})
|
|
|
|
Locomotive::ContentAssetPresenter.new(self).as_json
|
|
|
|
end
|
|
|
|
|
2011-10-30 23:02:41 +00:00
|
|
|
end
|
|
|
|
end
|