Module: Locomotive::Dragonfly
- Defined in:
- lib/locomotive/dragonfly.rb,
lib/locomotive/dragonfly/processors/smart_thumb.rb
Defined Under Namespace
Modules: Processors
Class Method Summary collapse
- .app ⇒ Object
- .fetch_file(source) ⇒ Object
- .resize_url(source, resize_string, timestamp = nil) ⇒ Object
- .thumbnail_pdf(source, resize_string, timestamp = nil) ⇒ Object
Class Method Details
.app ⇒ Object
51 52 53 |
# File 'lib/locomotive/dragonfly.rb', line 51 def self.app ::Dragonfly.app(:engine) end |
.fetch_file(source) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/locomotive/dragonfly.rb', line 26 def self.fetch_file(source) file = nil if source.is_a?(String) || source.is_a?(Hash) # simple string or drop source = source['url'] if source.is_a?(Hash) source = 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.path.first == '/' file = self.app.fetch_file(source.path) else file = self.app.fetch_url(source.url) end end file end |
.resize_url(source, resize_string, timestamp = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/locomotive/dragonfly.rb', line 6 def self.resize_url(source, resize_string, = nil) if file = self.fetch_file(source) url = file.thumb(resize_string).url ? url + "?#{}" : url else Locomotive.log :error, "Unable to resize on the fly: #{source.inspect}" return end end |
.thumbnail_pdf(source, resize_string, timestamp = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/locomotive/dragonfly.rb', line 16 def self.thumbnail_pdf(source, resize_string, = nil) if file = self.fetch_file(source) url = file.thumb(resize_string, format: 'png', frame: 0).encode('png').url ? url + "?#{}" : url else Locomotive.log :error, "Unable to convert the pdf: #{source.inspect}" return end end |