thumbkit 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/thumbkit/adapters/carrierwave.rb +11 -1
- data/lib/thumbkit/processor.rb +14 -12
- data/lib/thumbkit/version.rb +1 -1
- data/lib/thumbkit.rb +4 -0
- data/spec/thumbkit_spec.rb +7 -0
- metadata +3 -3
@@ -3,7 +3,7 @@
|
|
3
3
|
# class MyUploader < CarrierWave::Uploader::Base
|
4
4
|
# include Thumbkit::Adapters::CarrierWave
|
5
5
|
#
|
6
|
-
# version :thumbnail do
|
6
|
+
# version :thumbnail, :if => :valid_for_thumbkit? do
|
7
7
|
# # See [Configuration](#configuration) below for more about options.
|
8
8
|
# process thumbkit: [200, 200, { colors: { foreground: '#cccccc' } }]
|
9
9
|
#
|
@@ -28,9 +28,19 @@ module Thumbkit::Adapters::CarrierWave
|
|
28
28
|
@file = CarrierWave::SanitizedFile.new(result)
|
29
29
|
end
|
30
30
|
|
31
|
+
def valid_for_thumbkit?(file)
|
32
|
+
p "valid_for_thumbkit?", file, current_path
|
33
|
+
!! Thumbkit.new(file.path)
|
34
|
+
rescue ArgumentError
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
31
38
|
# Given a filename, return the filename that Thumbkit would generate.
|
32
39
|
# This should not do any processing.
|
33
40
|
def thumbkit_filename(for_file)
|
34
41
|
File.basename(Thumbkit.new(for_file).processor_instance.outfile)
|
42
|
+
rescue ArgumentError
|
43
|
+
# TODO: Handle this case better
|
44
|
+
nil
|
35
45
|
end
|
36
46
|
end
|
data/lib/thumbkit/processor.rb
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
class Thumbkit::Processor
|
2
|
-
autoload :Text,
|
3
|
-
autoload :Audio,
|
4
|
-
autoload :Image,
|
2
|
+
autoload :Text, 'thumbkit/processor/text'
|
3
|
+
autoload :Audio, 'thumbkit/processor/audio'
|
4
|
+
autoload :Image, 'thumbkit/processor/image'
|
5
5
|
autoload :Collection, 'thumbkit/processor/collection'
|
6
6
|
|
7
7
|
def self.processors
|
8
8
|
@processors ||= {
|
9
|
-
'png'
|
10
|
-
'jpg'
|
11
|
-
'
|
12
|
-
'
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
9
|
+
'png' => 'Image',
|
10
|
+
'jpg' => 'Image',
|
11
|
+
'jpeg' => 'Image',
|
12
|
+
'gif' => 'Image',
|
13
|
+
'txt' => 'Text',
|
14
|
+
'md' => 'Text',
|
15
|
+
'rb' => 'Text',
|
16
|
+
'mp3' => 'Audio',
|
17
|
+
'wav' => 'Audio',
|
18
|
+
'm4a' => 'Audio',
|
17
19
|
}
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.processor_for(extension)
|
21
|
-
if (class_name = self.processors[extension])
|
23
|
+
if (class_name = self.processors[extension.downcase])
|
22
24
|
self.const_get(class_name)
|
23
25
|
end
|
24
26
|
end
|
data/lib/thumbkit/version.rb
CHANGED
data/lib/thumbkit.rb
CHANGED
data/spec/thumbkit_spec.rb
CHANGED
@@ -25,6 +25,13 @@ describe Thumbkit do
|
|
25
25
|
|
26
26
|
its(:processor) { should == Thumbkit::Processor::Collection }
|
27
27
|
end
|
28
|
+
|
29
|
+
context 'with an unknown extension' do
|
30
|
+
subject { Thumbkit.new 'this_extension.no_exist_i_promise' }
|
31
|
+
it 'raises an ArgumentError' do
|
32
|
+
expect { subject }.to raise_error(ArgumentError)
|
33
|
+
end
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
describe Thumbkit, '.defaults' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thumbkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Thumbkit makes thumbnails!
|
15
15
|
email:
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.8.
|
73
|
+
rubygems_version: 1.8.24
|
74
74
|
signing_key:
|
75
75
|
specification_version: 3
|
76
76
|
summary: Thumbkit makes thumbnails from a variety of media types.
|