engine/app/models/asset.rb

40 lines
780 B
Ruby
Raw Normal View History

class Asset
2010-05-12 00:16:39 +00:00
include Mongoid::Document
include Mongoid::Timestamps
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-05-12 00:16:39 +00:00
## associations ##
2011-06-17 21:32:54 +00:00
referenced_in :site
2010-05-12 00:16:39 +00:00
## validations ##
2011-06-17 21:32:54 +00:00
validates_presence_of :source
## behaviours ##
2010-05-12 00:16:39 +00:00
## methods ##
%w{image stylesheet javascript pdf media}.each do |type|
2010-05-12 00:16:39 +00:00
define_method("#{type}?") do
self.content_type.to_s == type
end
2010-05-12 00:16:39 +00:00
end
def extname
return nil unless self.source?
File.extname(self.source_filename).gsub(/^\./, '')
end
def to_liquid
Locomotive::Liquid::Drops::Asset.new(self)
end
end