Module: Thumbo
- Defined in:
- lib/thumbo.rb,
lib/thumbo/proxy.rb,
lib/thumbo/version.rb,
lib/thumbo/storages/mogilefs.rb,
lib/thumbo/storages/filesystem.rb,
lib/thumbo/exceptions/file_not_found.rb
Defined Under Namespace
Modules: ClassMethod Classes: FileNotFound, Filesystem, Mogilefs, Proxy
Constant Summary collapse
- VERSION =
'0.5.0'
Class Method Summary collapse
Instance Method Summary collapse
- #create_thumbos(after_scale = lambda{}) ⇒ Object
-
#thumbo_filename(thumbo) ⇒ Object
same as thumbnail.filename, for writing.
- #thumbo_mime_type ⇒ Object
- #thumbos ⇒ Object
Class Method Details
.calculate_dimension(limit, width, height) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/thumbo.rb', line 10 def self.calculate_dimension limit, width, height long, short = width >= height ? [width, height] : [height, width] if long <= limit # stay on [width, height] elsif width == height # square [limit, limit] else # detect which is longer # assume width is longer new_width, new_height = limit, short * (limit.to_f / long) # swap if height is longer new_width, new_height = new_height, new_width if long == height [new_width, new_height] end end |
.included(model) ⇒ Object
6 7 8 |
# File 'lib/thumbo.rb', line 6 def self.included model model.extend(Thumbo::ClassMethod) end |
Instance Method Details
#create_thumbos(after_scale = lambda{}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/thumbo.rb', line 65 def create_thumbos after_scale = lambda{} # scale thumbnails self.class.thumbo_common.merge(self.class.thumbo_square).each_key{ |title| after_scale[ thumbos[title].create ] } # the last one don't scale at all, but call hook too after_scale[ thumbos[:original] ] self end |
#thumbo_filename(thumbo) ⇒ Object
same as thumbnail.filename, for writing
57 58 59 |
# File 'lib/thumbo.rb', line 57 def thumbo_filename thumbo "#{object_id}_#{thumbo.title}.#{thumbo.fileext}" end |
#thumbo_mime_type ⇒ Object
61 62 63 |
# File 'lib/thumbo.rb', line 61 def thumbo_mime_type thumbos[:original].mime_type end |
#thumbos ⇒ Object
52 53 54 |
# File 'lib/thumbo.rb', line 52 def thumbos @thumbos ||= init_thumbos end |