Sha256: b322296fffd6d013fce18f62457c8f49fd1e6cc7c02bae24ef119bbd03e22f2f
Contents?: true
Size: 1.52 KB
Versions: 9
Compression:
Stored size: 1.52 KB
Contents
module Locomotive module Dragonfly def self.resize_url(source, resize_string) if file = self.fetch_file(source) file.thumb(resize_string).url else Locomotive.log :error, "Unable to resize on the fly: #{source.inspect}" return end end def self.thumbnail_pdf(source, resize_string) if file = self.fetch_file(source) file.thumb(resize_string, format: 'png', frame: 0).encode('png').url else Locomotive.log :error, "Unable to convert the pdf: #{source.inspect}" return end end def self.fetch_file(source) file = nil if source.is_a?(String) || source.is_a?(Hash) # simple string or theme asset source = source['url'] if source.is_a?(Hash) clean_source!(source) if source =~ /^http/ file = self.app.fetch_url(source) else file = self.app.fetch_file(File.join('public', source)) end 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 end file end def self.app ::Dragonfly.app end protected def self.clean_source!(source) # remove the leading / trailing whitespaces source.strip! # remove the query part (usually, timestamp) if local file source.sub!(/(\?.*)$/, '') unless source =~ /^http/ end end end
Version data entries
9 entries across 9 versions & 1 rubygems