retina_rails 1.0.0 → 1.0.1
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/lib/retina_rails/helpers.rb +2 -1
- data/lib/retina_rails/strategies/paperclip.rb +3 -2
- data/lib/retina_rails/version.rb +1 -1
- data/spec/fixtures/db/retina_rails.sqlite3 +0 -0
- data/spec/helpers_spec.rb +12 -0
- data/spec/strategies/paperclip_spec.rb +22 -2
- data/spec/support/schema.rb +1 -0
- metadata +3 -3
data/lib/retina_rails/helpers.rb
CHANGED
@@ -6,7 +6,8 @@ module ActionView
|
|
6
6
|
retina = options.delete(:retina)
|
7
7
|
|
8
8
|
if retina
|
9
|
-
retina_source = source.
|
9
|
+
retina_source = source.to_s
|
10
|
+
retina_source = retina_source.split('.')
|
10
11
|
filename = retina_source.slice!(-2)
|
11
12
|
retina_source = retina_source.insert(-2, "#{filename}@2x").join('.')
|
12
13
|
|
@@ -59,14 +59,15 @@ module RetinaRails
|
|
59
59
|
## Iterate over styles and set optimzed dimensions
|
60
60
|
styles.each_pair do |key, value|
|
61
61
|
|
62
|
-
dimensions = value[0]
|
62
|
+
dimensions = value.kind_of?(Array) ? value[0] : value
|
63
63
|
|
64
64
|
width = dimensions.scan(/\d+/)[0].to_i * 2
|
65
65
|
height = dimensions.scan(/\d+/)[1].to_i * 2
|
66
66
|
|
67
67
|
processor = dimensions.scan(/#|</).first
|
68
68
|
|
69
|
-
|
69
|
+
new_dimensions = "#{width}x#{height}#{processor}"
|
70
|
+
retina_styles["#{key}_retina".to_sym] = value.kind_of?(Array) ? [new_dimensions, value[1]] : new_dimensions
|
70
71
|
|
71
72
|
## Set quality convert option
|
72
73
|
convert_option = convert_options[key] if convert_options
|
data/lib/retina_rails/version.rb
CHANGED
Binary file
|
data/spec/helpers_spec.rb
CHANGED
@@ -2,6 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActionView::Helpers::AssetTagHelper, :type => :helper do
|
4
4
|
|
5
|
+
class SomeWrapperClassForUrl
|
6
|
+
def to_s
|
7
|
+
'image.png'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
subject { helper }
|
6
12
|
|
7
13
|
describe :image_tag do
|
@@ -12,6 +18,12 @@ describe ActionView::Helpers::AssetTagHelper, :type => :helper do
|
|
12
18
|
|
13
19
|
it { subject.image_tag('image.some.png', :retina => true).should == '<img alt="Image.some" data-at2x="/assets/image.some@2x-0842b16379ded9ddcc299912621f76bc.png" src="/assets/image.some-e8de7f87c2b9d08490575267a4c9eddc.png" />' }
|
14
20
|
|
21
|
+
context 'with class' do
|
22
|
+
|
23
|
+
it { subject.image_tag(SomeWrapperClassForUrl.new, :retina => true).should == '<img alt="Image" data-at2x="/assets/image@2x-0842b16379ded9ddcc299912621f76bc.png" src="/assets/image-e8de7f87c2b9d08490575267a4c9eddc.png" />' }
|
24
|
+
|
25
|
+
end
|
26
|
+
|
15
27
|
end
|
16
28
|
|
17
29
|
context 'without retina' do
|
@@ -24,6 +24,14 @@ class PaperclipUpload < ActiveRecord::Base
|
|
24
24
|
:path => "#{ROOT}/:class/:id/:basename_:style.:extension",
|
25
25
|
:url => "#{ROOT}/:class/:id/:basename_:style.:extension"
|
26
26
|
|
27
|
+
has_attached_file :avatar_string_styles,
|
28
|
+
:styles => {
|
29
|
+
:original => "800x800",
|
30
|
+
:big => "125x125#"
|
31
|
+
},
|
32
|
+
:retina => true,
|
33
|
+
:path => "#{ROOT}/:class/:id/:basename_:style.:extension",
|
34
|
+
:url => "#{ROOT}/:class/:id/:basename_:style.:extension"
|
27
35
|
end
|
28
36
|
|
29
37
|
describe RetinaRails::Strategies::Paperclip do
|
@@ -44,14 +52,26 @@ describe RetinaRails::Strategies::Paperclip do
|
|
44
52
|
|
45
53
|
subject { PaperclipUpload.create(:avatar => File.open("#{fixture_path}/images/avatar.jpeg")) }
|
46
54
|
|
47
|
-
it { subject.avatar.url(:big).should == "#{ROOT}/paperclip_uploads/
|
48
|
-
it { subject.avatar.url(:big_retina).should == "#{ROOT}/paperclip_uploads/
|
55
|
+
it { subject.avatar.url(:big).should == "#{ROOT}/paperclip_uploads/#{subject.id}/avatar_big.jpg" }
|
56
|
+
it { subject.avatar.url(:big_retina).should == "#{ROOT}/paperclip_uploads/#{subject.id}/avatar_big@2x.jpg" }
|
49
57
|
|
50
58
|
it { Paperclip::Geometry.from_file(subject.avatar.url(:big)).to_s.should == '125x125' }
|
51
59
|
it { Paperclip::Geometry.from_file(subject.avatar.url(:big_retina)).to_s.should == '250x250' }
|
52
60
|
|
53
61
|
end
|
54
62
|
|
63
|
+
context 'uploads with string styles' do
|
64
|
+
|
65
|
+
subject { PaperclipUpload.create(:avatar_string_styles => File.open("#{fixture_path}/images/avatar.jpeg")) }
|
66
|
+
|
67
|
+
it { subject.avatar_string_styles.url(:big).should == "#{ROOT}/paperclip_uploads/#{subject.id}/avatar_big.jpeg" }
|
68
|
+
it { subject.avatar_string_styles.url(:big_retina).should == "#{ROOT}/paperclip_uploads/#{subject.id}/avatar_big@2x.jpeg" }
|
69
|
+
|
70
|
+
it { Paperclip::Geometry.from_file(subject.avatar_string_styles.url(:big)).to_s.should == '125x125' }
|
71
|
+
it { Paperclip::Geometry.from_file(subject.avatar_string_styles.url(:big_retina)).to_s.should == '250x250' }
|
72
|
+
|
73
|
+
end
|
74
|
+
|
55
75
|
context 'with retina quality' do
|
56
76
|
|
57
77
|
subject { PaperclipUpload.create(:avatar => File.open("#{fixture_path}/images/avatar.jpeg")) }
|
data/spec/support/schema.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retina_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-06-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -231,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
231
|
version: '0'
|
232
232
|
requirements: []
|
233
233
|
rubyforge_project:
|
234
|
-
rubygems_version: 1.8.
|
234
|
+
rubygems_version: 1.8.24
|
235
235
|
signing_key:
|
236
236
|
specification_version: 3
|
237
237
|
summary: Makes your live easier optimizing for retina displays
|