retina_rails 1.0.4 → 2.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -3
- data/.travis.yml +16 -4
- data/README.md +57 -29
- data/UPGRADING +7 -0
- data/UPGRADING.md +60 -0
- data/lib/retina_rails.rb +11 -7
- data/lib/retina_rails/extensions.rb +16 -0
- data/lib/retina_rails/extensions/carrierwave.rb +25 -0
- data/lib/retina_rails/extensions/paperclip.rb +23 -0
- data/lib/retina_rails/helpers.rb +42 -12
- data/lib/retina_rails/processors.rb +14 -0
- data/lib/retina_rails/processors/carrierwave.rb +49 -0
- data/lib/retina_rails/processors/paperclip.rb +30 -0
- data/lib/retina_rails/strategies.rb +6 -7
- data/lib/retina_rails/strategies/carrierwave.rb +56 -50
- data/lib/retina_rails/strategies/paperclip.rb +53 -55
- data/lib/retina_rails/version.rb +1 -1
- data/retina_rails.gemspec +11 -4
- data/spec/fixtures/db/retina_rails.sqlite3 +0 -0
- data/spec/helpers_spec.rb +87 -13
- data/spec/spec_helper.rb +10 -4
- data/spec/strategies/carrierwave_spec.rb +117 -154
- data/spec/strategies/paperclip_spec.rb +77 -104
- data/spec/support/carrierwave.rb +15 -0
- data/spec/support/file_string_io.rb +2 -0
- data/spec/support/paperclip.rb +9 -0
- data/spec/support/rails.rb +0 -11
- data/spec/support/schema.rb +8 -2
- metadata +53 -52
- data/lib/retina_rails/deprecation/carrierwave.rb +0 -23
- data/lib/retina_rails/deprecation/paperclip.rb +0 -23
- data/lib/retina_rails/exception.rb +0 -15
- data/spec/deprecation/carrierwave_spec.rb +0 -13
- data/spec/deprecation/paperclip_spec.rb +0 -14
- data/spec/fixtures/images/avatar.with.dots.jpeg +0 -0
- data/spec/fixtures/manifest.yml +0 -10
- data/vendor/assets/javascripts/retina.js +0 -113
Binary file
|
data/spec/helpers_spec.rb
CHANGED
@@ -1,35 +1,109 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
class Image
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def url(version)
|
6
|
+
'/some_image.png'
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class Upload
|
12
|
+
|
13
|
+
attr_accessor :avatar
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
self.avatar = Image.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def retina_dimensions
|
20
|
+
{
|
21
|
+
:avatar => {
|
22
|
+
:small => {
|
23
|
+
:width => 40,
|
24
|
+
:height => 30
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
9
28
|
end
|
10
29
|
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ActionView::Helpers::AssetTagHelper, :type => :helper do
|
33
|
+
|
11
34
|
subject { helper }
|
12
35
|
|
13
|
-
describe
|
36
|
+
describe '#retina_image_tag' do
|
37
|
+
|
38
|
+
context 'with dimensions present' do
|
39
|
+
|
40
|
+
it 'should set correct width and height' do
|
41
|
+
image = helper.retina_image_tag(Upload.new, :avatar, :small)
|
42
|
+
|
43
|
+
image.should include('width="40"')
|
44
|
+
image.should include('height="30"')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should be able to add a class' do
|
48
|
+
image = helper.retina_image_tag(Upload.new, :avatar, :small, :class => 'foo')
|
49
|
+
image.should include('class="foo"')
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'without dimensions present' do
|
55
|
+
|
56
|
+
before(:each) { Upload.any_instance.stub(:retina_dimensions).and_return(nil) }
|
14
57
|
|
15
|
-
|
58
|
+
it 'should set correct width and height' do
|
59
|
+
image = helper.retina_image_tag(Upload.new, :avatar, :small, :default => { :width => 25, :height => 40 })
|
16
60
|
|
17
|
-
|
61
|
+
image.should include('width="25"')
|
62
|
+
image.should include('height="40"')
|
18
63
|
|
19
|
-
|
64
|
+
image = helper.retina_image_tag(Upload.new, :avatar, :small, :default => [25, 40])
|
20
65
|
|
21
|
-
|
66
|
+
image.should include('width="25"')
|
67
|
+
image.should include('height="40"')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should set no height and width if no defaults present' do
|
71
|
+
image = helper.retina_image_tag(Upload.new, :avatar, :small)
|
72
|
+
|
73
|
+
image.should_not include('width')
|
74
|
+
image.should_not include('height')
|
75
|
+
end
|
22
76
|
|
23
|
-
|
77
|
+
it 'should be able to add a class' do
|
78
|
+
image = helper.retina_image_tag(Upload.new, :avatar, :small, :default => { :width => 25, :height => 40 }, :class => 'foo')
|
24
79
|
|
80
|
+
image.should include('class="foo"')
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should strip default attributes' do
|
84
|
+
image = helper.retina_image_tag(Upload.new, :avatar, :small, :default => { :width => 25, :height => 40 })
|
85
|
+
|
86
|
+
image.should_not include('default')
|
25
87
|
end
|
26
88
|
|
27
89
|
end
|
28
90
|
|
29
|
-
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#image_tag' do
|
94
|
+
|
95
|
+
it 'should show a deprecation warning when used with retina option' do
|
96
|
+
ActiveSupport::Deprecation.should_receive(:warn)
|
97
|
+
.with("`image_tag('image.png', :retina => true)` is deprecated use `retina_image_tag` instead")
|
98
|
+
|
99
|
+
image_tag('image.png', :retina => true)
|
100
|
+
end
|
30
101
|
|
31
|
-
|
102
|
+
it 'should not show a deprecation warning when used without retina option' do
|
103
|
+
ActiveSupport::Deprecation.should_not_receive(:warn)
|
104
|
+
.with("`image_tag('image.png', :retina => true)` is deprecated use `retina_image_tag` instead")
|
32
105
|
|
106
|
+
image_tag('image.png')
|
33
107
|
end
|
34
108
|
|
35
109
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -25,20 +25,26 @@ ActiveRecord::Base.establish_connection(
|
|
25
25
|
:database => File.dirname(__FILE__) + "/fixtures/db/retina_rails.sqlite3"
|
26
26
|
)
|
27
27
|
|
28
|
-
## Load support files
|
29
|
-
|
30
|
-
Dir["spec/support/**/*.rb"].each { |f| load f }
|
31
|
-
|
32
28
|
## Load rspec rails after initializing rails app
|
33
29
|
|
30
|
+
load 'spec/support/rails.rb'
|
31
|
+
load 'spec/support/schema.rb'
|
34
32
|
require 'rspec/rails'
|
35
33
|
|
36
34
|
## Load retina_rails
|
37
35
|
|
38
36
|
require 'retina_rails'
|
39
37
|
|
38
|
+
RetinaRails::Extensions.include_extensions
|
39
|
+
RetinaRails::Processors.include_processors
|
40
40
|
RetinaRails::Strategies.include_strategies
|
41
41
|
|
42
|
+
## Load support files
|
43
|
+
|
44
|
+
load 'spec/support/carrierwave.rb'
|
45
|
+
load 'spec/support/paperclip.rb'
|
46
|
+
load 'spec/support/file_string_io.rb'
|
47
|
+
|
42
48
|
RSpec.configure do |config|
|
43
49
|
config.fixture_path = "#{File.dirname(__FILE__)}/fixtures"
|
44
50
|
end
|
@@ -1,207 +1,170 @@
|
|
1
|
-
require 'stringio'
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
|
-
class AnonymousUploader < CarrierWave::Uploader::Base
|
5
|
-
|
6
|
-
include CarrierWave::RMagick
|
7
|
-
|
8
|
-
retina!
|
9
|
-
|
10
|
-
version :small do
|
11
|
-
process :resize_to_fill => [30, 30]
|
12
|
-
process :quality => 60
|
13
|
-
process :retina_quality => 20
|
14
|
-
end
|
15
|
-
|
16
|
-
version :small_without_quality do
|
17
|
-
process :resize_to_fill => [30, 30]
|
18
|
-
end
|
19
|
-
|
20
|
-
version :small_without_dimensions do
|
21
|
-
process :desaturate
|
22
|
-
end
|
23
|
-
|
24
|
-
version :small_multiple_processors do
|
25
|
-
process :resize_to_fill => [30, 30]
|
26
|
-
process :desaturate
|
27
|
-
end
|
28
|
-
|
29
|
-
version :small_without_retina, :retina => false do
|
30
|
-
process :quality => 60
|
31
|
-
end
|
32
|
-
|
33
|
-
version :small_custom_processor, :retina => false do
|
34
|
-
process :resize_to_fill_with_gravity => [100, 100, 'North', :jpg, 75]
|
35
|
-
end
|
36
|
-
|
37
|
-
version :small_custom_processor_retina, :retina => false do
|
38
|
-
process :resize_to_fill_with_gravity => [200, 200, 'North', :jpg, 40]
|
39
|
-
end
|
40
|
-
|
41
|
-
version :small_with_failing_conditional, :if => ->(img, opts) { false } do
|
42
|
-
process :resize_to_fill => [30, 30]
|
43
|
-
end
|
44
|
-
|
45
|
-
def desaturate
|
46
|
-
manipulate! do |img|
|
47
|
-
img = img.quantize 256, Magick::GRAYColorspace
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def resize_to_fill_with_gravity(width, height, gravity, format, quality); end
|
52
|
-
|
53
|
-
def quality(percentage)
|
54
|
-
manipulate! do |img|
|
55
|
-
img.write(current_path) { self.quality = percentage } unless img.quality == percentage
|
56
|
-
img = yield(img) if block_given?
|
57
|
-
img
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
version :small_without_processor
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
class CarrierWaveUpload
|
66
|
-
|
67
|
-
extend CarrierWave::Mount
|
68
|
-
|
69
|
-
attr_accessor :avatar
|
70
|
-
attr_accessor :id
|
71
|
-
|
72
|
-
mount_uploader :avatar, AnonymousUploader
|
73
|
-
|
74
|
-
def initialize
|
75
|
-
self.id = 999
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
3
|
describe RetinaRails::Strategies::CarrierWave do
|
81
4
|
|
82
5
|
include CarrierWave::Test::Matchers
|
83
6
|
|
84
|
-
|
85
|
-
|
86
|
-
|
7
|
+
##
|
8
|
+
# Store image so we can run tests against it
|
9
|
+
#
|
10
|
+
def upload!
|
87
11
|
AnonymousUploader.enable_processing = true
|
88
12
|
@uploader = AnonymousUploader.new(CarrierWaveUpload.new, :avatar)
|
89
13
|
@uploader.store!(File.open("#{fixture_path}/images/avatar.jpeg"))
|
90
14
|
end
|
91
15
|
|
92
|
-
|
16
|
+
##
|
17
|
+
# Remove image after testing
|
18
|
+
#
|
19
|
+
after(:each) do
|
93
20
|
AnonymousUploader.enable_processing = false
|
94
21
|
@uploader.remove!
|
22
|
+
AnonymousUploader.versions[:small][:uploader].processors = [] ## Reset processors
|
95
23
|
end
|
96
24
|
|
25
|
+
##
|
26
|
+
# Actual tests
|
27
|
+
#
|
97
28
|
context 'with dimensions processor' do
|
98
29
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
context 'with quality processor' do
|
112
|
-
|
113
|
-
it { Magick::Image.read(@uploader.small.current_path).first.quality.should == 60 }
|
114
|
-
|
115
|
-
it { Magick::Image.read(@uploader.small_retina.current_path).first.quality.should == 20 }
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'without quality processor' do
|
120
|
-
|
121
|
-
it { Magick::Image.read(@uploader.small_without_quality.current_path).first.quality.should == 84 }
|
122
|
-
|
123
|
-
it { Magick::Image.read(@uploader.small_without_quality_retina.current_path).first.quality.should == 40 }
|
30
|
+
##
|
31
|
+
# Setup Anonymous uploader with a resize processor
|
32
|
+
#
|
33
|
+
before(:each) do
|
34
|
+
AnonymousUploader.class_eval do
|
35
|
+
version :small do
|
36
|
+
process :resize_to_fill => [30, 40]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
upload!
|
40
|
+
end
|
124
41
|
|
125
|
-
|
42
|
+
it 'should double the height and width of an image' do
|
43
|
+
@uploader.small.should have_dimensions(60, 80)
|
44
|
+
end
|
126
45
|
|
127
|
-
|
46
|
+
it 'should store original width and height attributes for version' do
|
47
|
+
@uploader.model.retina_dimensions[:avatar][:small].should == { :width => 30, :height => 40 }
|
48
|
+
end
|
128
49
|
|
129
|
-
|
50
|
+
it "should set quality to it's default 60%" do
|
51
|
+
quality = Magick::Image.read(@uploader.small.current_path).first.quality
|
52
|
+
quality.should == 60
|
53
|
+
end
|
130
54
|
|
131
55
|
end
|
132
56
|
|
133
|
-
context '
|
134
|
-
|
135
|
-
its(:versions) { should include :small_multiple_processors_retina }
|
57
|
+
context 'override quality' do
|
136
58
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
59
|
+
##
|
60
|
+
# Setup Anonymous uploader with a resize processor and override quality
|
61
|
+
#
|
62
|
+
before(:each) do
|
63
|
+
AnonymousUploader.class_eval do
|
64
|
+
version :small do
|
65
|
+
process :resize_to_fill => [30, 40]
|
66
|
+
process :retina_quality => 80
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
146
70
|
|
147
|
-
|
71
|
+
it "should override quality" do
|
72
|
+
upload!
|
73
|
+
quality = Magick::Image.read(@uploader.small.current_path).first.quality
|
74
|
+
quality.should == 80
|
75
|
+
end
|
148
76
|
|
149
|
-
|
77
|
+
it 'should receive quality processor once' do
|
78
|
+
AnonymousUploader.any_instance.should_receive(:retina_quality).once
|
150
79
|
|
151
|
-
|
152
|
-
|
80
|
+
upload!
|
81
|
+
end
|
153
82
|
|
154
83
|
end
|
155
84
|
|
156
|
-
context '
|
85
|
+
context 'multiple processors' do
|
157
86
|
|
158
|
-
|
159
|
-
|
87
|
+
##
|
88
|
+
# Setup Anonymous uploader with a custom processor
|
89
|
+
#
|
90
|
+
before(:each) do
|
91
|
+
AnonymousUploader.class_eval do
|
92
|
+
version :small do
|
93
|
+
process :resize_to_fill => [30, 40]
|
94
|
+
process :desaturate
|
95
|
+
end
|
160
96
|
|
161
|
-
|
97
|
+
def desaturate
|
98
|
+
manipulate! do |img|
|
99
|
+
img = img.quantize 256, Magick::GRAYColorspace
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
162
103
|
|
163
|
-
|
104
|
+
upload!
|
105
|
+
end
|
164
106
|
|
165
|
-
|
166
|
-
|
167
|
-
@uploader = AnonymousUploader.new(CarrierWaveUpload.new, :avatar)
|
168
|
-
@uploader.store!(File.open("#{fixture_path}/images/avatar.with.dots.jpeg"))
|
107
|
+
it 'should double the height and width of an image' do
|
108
|
+
@uploader.small.should have_dimensions(60, 80)
|
169
109
|
end
|
170
110
|
|
171
|
-
it
|
172
|
-
|
111
|
+
it 'should store original width and height attributes for version' do
|
112
|
+
@uploader.model.retina_dimensions[:avatar][:small].should == { :width => 30, :height => 40 }
|
113
|
+
end
|
173
114
|
|
174
115
|
end
|
175
116
|
|
176
|
-
context '
|
117
|
+
context 'with custom resize processor' do
|
177
118
|
|
178
|
-
|
119
|
+
##
|
120
|
+
# Setup Anonymous uploader with a custom resize processor
|
121
|
+
#
|
122
|
+
before(:each) do
|
123
|
+
AnonymousUploader.class_eval do
|
124
|
+
version :small, :retina => false do
|
125
|
+
process :custom_resize => [200, 200]
|
126
|
+
process :store_retina_dimensions
|
127
|
+
end
|
179
128
|
|
180
|
-
|
129
|
+
def custom_resize(width, height)
|
130
|
+
manipulate! do |img|
|
131
|
+
img.resize_to_fill!(width, height)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
181
135
|
|
182
|
-
|
183
|
-
|
184
|
-
its(:versions) { should_not include :small_custom_processor_retina_retina }
|
136
|
+
upload!
|
137
|
+
end
|
185
138
|
|
186
|
-
it
|
139
|
+
it 'should double the height and width of an image' do
|
140
|
+
@uploader.small.should have_dimensions(200, 200)
|
141
|
+
end
|
187
142
|
|
188
|
-
it
|
189
|
-
|
143
|
+
it 'should store original width and height attributes for version' do
|
144
|
+
@uploader.model.retina_dimensions[:avatar][:small].should == { :width => 100, :height => 100 }
|
145
|
+
end
|
190
146
|
|
191
147
|
end
|
192
148
|
|
193
|
-
context '
|
149
|
+
context 'with failing conditional version' do
|
194
150
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
151
|
+
##
|
152
|
+
# Setup Anonymous uploader with a failing condition
|
153
|
+
#
|
154
|
+
before(:each) do
|
155
|
+
AnonymousUploader.class_eval do
|
156
|
+
version :small_conditional, :if => ->(img, opts) { false } do
|
157
|
+
process :resize_to_fill => [30, 30]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
upload!
|
200
162
|
end
|
201
163
|
|
202
|
-
it
|
203
|
-
|
204
|
-
|
164
|
+
it 'should not create a version' do
|
165
|
+
@uploader.version_exists?(:small_conditional).should be_false
|
166
|
+
@uploader.small_conditional.current_path.should_not be_present
|
167
|
+
end
|
205
168
|
|
206
169
|
end
|
207
170
|
|