2011-06-20 19:05:12 +00:00
|
|
|
module Locomotive
|
|
|
|
module Dragonfly
|
|
|
|
|
|
|
|
def self.resize_url(source, resize_string)
|
|
|
|
file = nil
|
|
|
|
|
2011-06-21 00:39:59 +00:00
|
|
|
if source.is_a?(String) || source.is_a?(Hash) # simple string or theme asset
|
|
|
|
source = source['url'] if source.is_a?(Hash)
|
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
if source =~ /^http/
|
|
|
|
file = self.app.fetch_url(source)
|
|
|
|
else
|
|
|
|
file = self.app.fetch_file(File.join('public', source))
|
|
|
|
end
|
2011-06-21 00:39:59 +00:00
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
elsif source.respond_to?(:url) # carrierwave uploader
|
|
|
|
if source.file.respond_to?(:url)
|
|
|
|
file = self.app.fetch_url(source.url) # amazon s3, cloud files, ...etc
|
|
|
|
else
|
|
|
|
file = self.app.fetch_file(source.path)
|
|
|
|
end
|
2011-06-21 00:39:59 +00:00
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
else
|
2011-07-26 19:20:03 +00:00
|
|
|
Locomotive.log :error, "Unable to resize on the fly: #{source.inspect}"
|
2011-06-20 19:05:12 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
file.process(:thumb, resize_string).url
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.app
|
|
|
|
::Dragonfly[:images]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|