2011-11-16 00:39:16 +00:00
|
|
|
module Locomotive
|
|
|
|
class ThemeAssetPresenter < BasePresenter
|
|
|
|
|
2012-02-28 10:25:51 +00:00
|
|
|
delegate :content_type, :folder, :plain_text, :to => :source
|
2011-12-07 01:09:13 +00:00
|
|
|
|
2011-11-16 00:39:16 +00:00
|
|
|
def local_path
|
|
|
|
self.source.local_path(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
|
|
|
self.source.source.url
|
|
|
|
end
|
|
|
|
|
|
|
|
def size
|
|
|
|
number_to_human_size(self.source.size)
|
|
|
|
end
|
|
|
|
|
2011-12-07 01:09:13 +00:00
|
|
|
def dimensions
|
|
|
|
self.source.image? ? "#{self.source.width}px x #{self.source.height}px" : nil
|
|
|
|
end
|
|
|
|
|
2011-11-16 00:39:16 +00:00
|
|
|
def updated_at
|
|
|
|
I18n.l(self.source.updated_at, :format => :short)
|
|
|
|
end
|
|
|
|
|
2012-03-01 10:07:22 +00:00
|
|
|
def can_be_deleted
|
|
|
|
self.ability.try(:can?, :destroy, self.source)
|
|
|
|
end
|
|
|
|
|
2011-11-21 01:27:05 +00:00
|
|
|
def included_methods
|
2012-03-01 10:07:22 +00:00
|
|
|
default_list = %w(content_type folder local_path url size dimensions can_be_deleted updated_at)
|
2012-02-28 10:25:51 +00:00
|
|
|
default_list += %w(plain_text) if plain_text?
|
|
|
|
super + default_list
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def plain_text?
|
|
|
|
# FIXME: self.options contains all the options passed by the responder
|
|
|
|
self.options[:template] == 'update' && self.source.errors.empty? && self.source.stylesheet_or_javascript?
|
2011-11-16 00:39:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|