carrierwave-imagesorcery 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/.travis.yml +17 -0
- data/Gemfile.lock +43 -0
- data/README.md +3 -0
- data/carrierwave-imagesorcery.gemspec +3 -1
- data/lib/carrierwave-imagesorcery/image_sorcery.rb +10 -0
- data/lib/carrierwave-imagesorcery/version.rb +1 -1
- data/spec/lib/carrierwave-imagesorcery/image_sorcery_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -5
- metadata +41 -9
- data/spec/lib/carrierwave-imagesorcery/image_sorcery.rb +0 -111
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
carrierwave-imagesorcery (0.0.3)
|
5
|
+
carrierwave
|
6
|
+
image_sorcery
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (3.2.9)
|
12
|
+
activesupport (= 3.2.9)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
activesupport (3.2.9)
|
15
|
+
i18n (~> 0.6)
|
16
|
+
multi_json (~> 1.0)
|
17
|
+
builder (3.0.4)
|
18
|
+
carrierwave (0.7.1)
|
19
|
+
activemodel (>= 3.2.0)
|
20
|
+
activesupport (>= 3.2.0)
|
21
|
+
diff-lcs (1.1.3)
|
22
|
+
i18n (0.6.1)
|
23
|
+
image_sorcery (1.0.7)
|
24
|
+
multi_json (1.5.0)
|
25
|
+
rake (10.0.3)
|
26
|
+
rspec (2.12.0)
|
27
|
+
rspec-core (~> 2.12.0)
|
28
|
+
rspec-expectations (~> 2.12.0)
|
29
|
+
rspec-mocks (~> 2.12.0)
|
30
|
+
rspec-core (2.12.2)
|
31
|
+
rspec-expectations (2.12.1)
|
32
|
+
diff-lcs (~> 1.1.3)
|
33
|
+
rspec-mocks (2.12.1)
|
34
|
+
subexec (0.2.2)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
carrierwave-imagesorcery!
|
41
|
+
rake (~> 10.0.2)
|
42
|
+
rspec (~> 2.12.0)
|
43
|
+
subexec (~> 0.2.2)
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
Additional processing to use [ImageSorcery](https://github.com/EricR/image_sorcery) into [CarrierWave](https://github.com/jnicklas/carrierwave).
|
4
4
|
|
5
|
+
[](https://travis-ci.org/WaYdotNET/carrierwave-imagesorcery)
|
6
|
+
[](https://codeclimate.com/github/WaYdotNET/carrierwave-imagesorcery)
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
@@ -10,7 +10,9 @@ Gem::Specification.new do |gem|
|
|
10
10
|
|
11
11
|
gem.extra_rdoc_files = ["README.md"]
|
12
12
|
gem.rdoc_options = ["--main"]
|
13
|
-
gem.add_development_dependency
|
13
|
+
gem.add_development_dependency 'rspec', '~> 2.12.0'
|
14
|
+
gem.add_development_dependency 'rake','~> 10.0.2'
|
15
|
+
gem.add_development_dependency 'subexec', '~> 0.2.2'
|
14
16
|
|
15
17
|
gem.add_dependency 'carrierwave'
|
16
18
|
gem.add_dependency 'image_sorcery'
|
@@ -155,8 +155,18 @@ module CarrierWave
|
|
155
155
|
cache_stored_file! if !cached?
|
156
156
|
image = Sorcery.new current_path
|
157
157
|
image = yield(image)
|
158
|
+
|
159
|
+
replace_file(image.file) if !image.is_a?(Hash) && image.filename_changed?
|
160
|
+
|
161
|
+
image
|
158
162
|
rescue RuntimeError, StandardError => e
|
159
163
|
raise CarrierWave::ProcessingError , I18n.translate(:"errors.messages.imagesorcery_processing_error", :e => e)
|
160
164
|
end
|
165
|
+
|
166
|
+
private
|
167
|
+
|
168
|
+
def replace_file(file)
|
169
|
+
FileUtils.move Dir.glob(file).first, current_path
|
170
|
+
end
|
161
171
|
end
|
162
172
|
end
|
@@ -20,13 +20,13 @@ describe CarrierWave::ImageSorcery do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
after do
|
23
|
-
FileUtils.rm(file_path('landscape_copy.jpg'))
|
23
|
+
FileUtils.rm([file_path('landscape_copy.jpg'), file_path('landscape_copy.png')], :force => true)
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "#convert" do
|
27
27
|
it "should convert from one format to another" do
|
28
|
-
@instance.convert('
|
29
|
-
img = Sorcery.new
|
28
|
+
@instance.convert('png')
|
29
|
+
img = Sorcery.new @instance.current_path
|
30
30
|
img.identify.should =~ /PNG/
|
31
31
|
end
|
32
32
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'rubygems' unless defined? Gem
|
2
|
-
# require 'minitest' if RUBY_VERSION < "1.9"
|
3
|
-
|
4
2
|
# we need the actual library file
|
5
3
|
# require_relative '../lib/ms_translate'
|
6
4
|
# For Ruby < 1.9.3, use this instead of require_relative
|
@@ -8,13 +6,11 @@ require 'bundler/setup'
|
|
8
6
|
require 'carrierwave'
|
9
7
|
|
10
8
|
require(File.expand_path('../../lib/carrierwave-imagesorcery', __FILE__))
|
11
|
-
require 'minitest/autorun'
|
12
|
-
|
13
9
|
|
14
10
|
def file_path(*paths)
|
15
11
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', *paths))
|
16
12
|
end
|
17
13
|
|
18
14
|
def check_dimension(x, y)
|
19
|
-
{:x =>
|
15
|
+
{:x => x, :y => y}
|
20
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-imagesorcery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,56 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 2.12.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 2.12.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 10.0.2
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 10.0.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: subexec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.2.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.2
|
30
62
|
- !ruby/object:Gem::Dependency
|
31
63
|
name: carrierwave
|
32
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,7 +100,9 @@ extra_rdoc_files:
|
|
68
100
|
- README.md
|
69
101
|
files:
|
70
102
|
- .gitignore
|
103
|
+
- .travis.yml
|
71
104
|
- Gemfile
|
105
|
+
- Gemfile.lock
|
72
106
|
- LICENSE
|
73
107
|
- README.md
|
74
108
|
- Rakefile
|
@@ -77,7 +111,6 @@ files:
|
|
77
111
|
- lib/carrierwave-imagesorcery/image_sorcery.rb
|
78
112
|
- lib/carrierwave-imagesorcery/version.rb
|
79
113
|
- spec/fixtures/landscape.jpg
|
80
|
-
- spec/lib/carrierwave-imagesorcery/image_sorcery.rb
|
81
114
|
- spec/lib/carrierwave-imagesorcery/image_sorcery_spec.rb
|
82
115
|
- spec/spec_helper.rb
|
83
116
|
homepage: http://www.waydotnet.com
|
@@ -101,13 +134,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
134
|
version: '0'
|
102
135
|
requirements: []
|
103
136
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.8.
|
137
|
+
rubygems_version: 1.8.23
|
105
138
|
signing_key:
|
106
139
|
specification_version: 3
|
107
140
|
summary: ImageSorcery carrierwave processor
|
108
141
|
test_files:
|
109
142
|
- spec/fixtures/landscape.jpg
|
110
|
-
- spec/lib/carrierwave-imagesorcery/image_sorcery.rb
|
111
143
|
- spec/lib/carrierwave-imagesorcery/image_sorcery_spec.rb
|
112
144
|
- spec/spec_helper.rb
|
113
145
|
has_rdoc:
|
@@ -1,111 +0,0 @@
|
|
1
|
-
# # require_relative '../../spec_helper'
|
2
|
-
# # For Ruby < 1.9.3, use this instead of require_relative
|
3
|
-
require (File.expand_path('./../../../spec_helper', __FILE__))
|
4
|
-
|
5
|
-
describe CarrierWave::ImageSorcery do
|
6
|
-
|
7
|
-
before do
|
8
|
-
@klass = Class.new do
|
9
|
-
include CarrierWave::ImageSorcery
|
10
|
-
end
|
11
|
-
@instance = @klass.new
|
12
|
-
FileUtils.cp(file_path('landscape.jpg'), file_path('landscape_copy.jpg'))
|
13
|
-
@instance.stub(:current_path).and_return(file_path('landscape_copy.jpg'))
|
14
|
-
@instance.stub(:cached?).and_return true
|
15
|
-
end
|
16
|
-
|
17
|
-
after do
|
18
|
-
FileUtils.rm(file_path('landscape_copy.jpg'))
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#convert" do
|
22
|
-
it "should convert from one format to another" do
|
23
|
-
@instance.convert('foo.png')
|
24
|
-
# img = ::MiniMagick::Image.open(@instance.current_path)
|
25
|
-
img = Sorcery.new @istance.current_path
|
26
|
-
identify= img.identify
|
27
|
-
identify.should =~ /PNG/
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#resize_to_fill' do
|
32
|
-
it "should resize the image to exactly the given dimensions" do
|
33
|
-
@instance.resize_to_fill(200, 200)
|
34
|
-
@instance.should have_dimensions(200, 200)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should scale up the image if it smaller than the given dimensions" do
|
38
|
-
@instance.resize_to_fill(1000, 1000)
|
39
|
-
@instance.should have_dimensions(1000, 1000)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#resize_and_pad' do
|
44
|
-
it "should resize the image to exactly the given dimensions" do
|
45
|
-
@instance.resize_and_pad(200, 200)
|
46
|
-
@instance.should have_dimensions(200, 200)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should scale up the image if it smaller than the given dimensions" do
|
50
|
-
@instance.resize_and_pad(1000, 1000)
|
51
|
-
@instance.should have_dimensions(1000, 1000)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should pad with white" do
|
55
|
-
@instance.resize_and_pad(200, 200)
|
56
|
-
image = ::MiniMagick::Image.open(@instance.current_path)
|
57
|
-
x, y = 0, 0
|
58
|
-
color = image.run_command("convert", "#{image.escaped_path}[1x1+#{x}+#{y}]", "-depth 8", "txt:").split("\n")[1]
|
59
|
-
color.should include('#FFFFFF')
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#resize_to_fit' do
|
65
|
-
it "should resize the image to fit within the given dimensions" do
|
66
|
-
@instance.resize_to_fit(200, 200)
|
67
|
-
@instance.should have_dimensions(200, 150)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should scale up the image if it smaller than the given dimensions" do
|
71
|
-
@instance.resize_to_fit(1000, 1000)
|
72
|
-
@instance.should have_dimensions(1000, 750)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe '#resize_to_limit' do
|
77
|
-
it "should resize the image to fit within the given dimensions" do
|
78
|
-
@instance.resize_to_limit(200, 200)
|
79
|
-
@instance.should have_dimensions(200, 150)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should not scale up the image if it smaller than the given dimensions" do
|
83
|
-
@instance.resize_to_limit(1000, 1000)
|
84
|
-
@instance.should have_dimensions(640, 480)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "test errors" do
|
89
|
-
context "invalid image file" do
|
90
|
-
before do
|
91
|
-
File.open(@instance.current_path, 'w') do |f|
|
92
|
-
f.puts "bogus"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should fail to process a non image file" do
|
97
|
-
lambda {@instance.resize_to_limit(200, 200)}.should raise_exception(CarrierWave::ProcessingError, /^Failed to manipulate with MiniMagick, maybe it is not an image\? Original Error:/)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should use I18n" do
|
101
|
-
change_locale_and_store_translations(:nl, :errors => {
|
102
|
-
:messages => {
|
103
|
-
:mini_magick_processing_error => "Kon bestand niet met MiniMagick bewerken, misschien is het geen beeld bestand? MiniMagick foutmelding: %{e}"
|
104
|
-
}
|
105
|
-
}) do
|
106
|
-
lambda {@instance.resize_to_limit(200, 200)}.should raise_exception(CarrierWave::ProcessingError, /^Kon bestand niet met MiniMagick bewerken, misschien is het geen beeld bestand\? MiniMagick foutmelding:/)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|