retina_rails 1.0.1 → 1.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b0fc5851886964ca14ff8e7b9ca46b4f7ead87d
4
+ data.tar.gz: be70cf1c874eabd21b0f7e2500a477bab7ba6ac1
5
+ SHA512:
6
+ metadata.gz: 0fea47157ea0f8a9daecff22bb7651ff346ddc3d56f4d3a8712800cd1b084f5bdac0bcd08f75187305699c4cbde76e3830ecafb26a7bb7de39e4cab910e02fbd
7
+ data.tar.gz: ae1f12e6c38db9b5859b25c8519dd9f547060ecd2e0887d38314120d4021765aeddd5db8dcbc93295c07fc82694e9dbaf2d525697d2fb107fddd1e00a9ad8a48
@@ -2,4 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - 2.0.0
5
6
  - ruby-head
data/README.md CHANGED
@@ -79,8 +79,8 @@ class ExampleUploader < ActiveRecord::Base
79
79
  :original => ["800x800", :jpg],
80
80
  :big => ["125x125#", :jpg]
81
81
  },
82
- :retina => true
83
- # :retina => { :quality => 25 }
82
+ :retina => true # Or
83
+ :retina => { :quality => 25 } # Optional
84
84
 
85
85
  end
86
86
  ```
@@ -95,21 +95,29 @@ image_tag('image.png', :retina => true)
95
95
 
96
96
  Voila! Now you're using Retina Rails.
97
97
 
98
+ Supported Ruby Versions
99
+ ------------
100
+
101
+ This library aims to support and is tested against[travis] the following Ruby
102
+ implementations:
103
+
104
+ * Ruby 1.9.2
105
+ * Ruby 1.9.3
106
+ * Ruby 2.0.0
107
+
98
108
  Credits
99
109
  ------------
100
110
 
101
111
  Retina Rails uses retinajs (https://github.com/imulus/retinajs)
102
112
 
103
- Note on Patches/Pull Requests
113
+ Contributing
104
114
  ------------
105
115
 
106
- * Fork the project.
107
- * Make your feature addition or bug fix.
108
- * Add tests for it. This is important so I don't break it in a
109
- future version unintentionally.
110
- * Commit, do not mess with rakefile, version, or history.
111
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
112
- * Send me a pull request. Bonus points for topic branches.
116
+ 1. Fork it
117
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
118
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
119
+ 4. Push to the branch (`git push origin my-new-feature`)
120
+ 5. Create new Pull Request
113
121
 
114
122
  Copyright
115
123
  ------------
@@ -76,7 +76,12 @@ module RetinaRails
76
76
  ## Set the correct filename for storage according to the convention (append @2x to filename)
77
77
  def full_filename(for_file)
78
78
  super.tap do |file_name|
79
- file_name.sub!(/(.*)\./, '\1@2x.').gsub!('retina_', '') if version_name.to_s.include?('retina')
79
+ if version_name.to_s.include?('retina')
80
+ has_extension = file_name.scan(/(jpg|jpeg|png|gif|bmp)/).any?
81
+
82
+ regex = has_extension ? /(.*)\./ : /.*/
83
+ file_name.sub!(regex, '\1@2x.').gsub!('retina_', '')
84
+ end
80
85
  end
81
86
  end
82
87
 
@@ -1,3 +1,3 @@
1
1
  module RetinaRails
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -27,5 +27,6 @@ Gem::Specification.new do |gem|
27
27
  gem.add_development_dependency 'sqlite3'
28
28
  gem.add_development_dependency 'coveralls'
29
29
 
30
- gem.add_dependency 'rails', '>= 3.0'
30
+
31
+ gem.add_dependency 'rails', '>= 3.2.0', '< 4.0.0'
31
32
  end
@@ -1,3 +1,4 @@
1
+ require 'stringio'
1
2
  require 'spec_helper'
2
3
 
3
4
  class AnonymousUploader < CarrierWave::Uploader::Base
@@ -178,4 +179,19 @@ describe RetinaRails::Strategies::CarrierWave do
178
179
 
179
180
  end
180
181
 
182
+ context 'file without extension name' do
183
+
184
+ before do
185
+ AnonymousUploader.enable_processing = true
186
+ @uploader = AnonymousUploader.new(CarrierWaveUpload.new, :avatar)
187
+ stream = FileStringIO.new('avatar', File.read("#{fixture_path}/images/avatar.jpeg"))
188
+ @uploader.store!(stream)
189
+ end
190
+
191
+ it { File.basename(@uploader.small.current_path, 'jpeg').should include 'small_'}
192
+ it { File.basename(@uploader.small_retina.current_path, 'jpeg').should include '@2x'}
193
+ it { File.basename(@uploader.small_retina.current_path, 'jpeg').should_not include 'retina_'}
194
+
195
+ end
196
+
181
197
  end
@@ -72,6 +72,16 @@ describe RetinaRails::Strategies::Paperclip do
72
72
 
73
73
  end
74
74
 
75
+ context 'file without extension name' do
76
+
77
+ let!(:stream) { FileStringIO.new('avatar', File.read("#{fixture_path}/images/avatar.jpeg")) }
78
+ subject { PaperclipUpload.create(:avatar => stream) }
79
+
80
+ it { subject.avatar.url(:big).should == "#{ROOT}/paperclip_uploads/#{subject.id}/avatar_big.jpg" }
81
+ it { subject.avatar.url(:big_retina).should == "#{ROOT}/paperclip_uploads/#{subject.id}/avatar_big@2x.jpg" }
82
+
83
+ end
84
+
75
85
  context 'with retina quality' do
76
86
 
77
87
  subject { PaperclipUpload.create(:avatar => File.open("#{fixture_path}/images/avatar.jpeg")) }
@@ -90,7 +100,7 @@ describe RetinaRails::Strategies::Paperclip do
90
100
 
91
101
  end
92
102
 
93
- describe :optimze_path do
103
+ describe :optimize_path do
94
104
 
95
105
  subject { RetinaRails::Strategies::Paperclip::Uploader::Extensions }
96
106
 
@@ -0,0 +1,12 @@
1
+ class FileStringIO < StringIO
2
+ attr_accessor :filepath
3
+
4
+ def initialize(*args)
5
+ super(*args[1..-1])
6
+ @filepath = args[0]
7
+ end
8
+
9
+ def original_filename
10
+ File.basename(@filepath)
11
+ end
12
+ end
@@ -6,7 +6,7 @@ module RetinaRailsTest
6
6
  class Application < Rails::Application
7
7
  config.active_support.deprecation = :log
8
8
 
9
- config.assets.manifest = Rails.public_path.gsub('public', 'spec/fixtures')
9
+ config.assets.manifest = Rails.root.join("spec/fixtures")
10
10
 
11
11
  ## Asset config
12
12
 
@@ -16,6 +16,12 @@ module RetinaRailsTest
16
16
  config.assets.compress = true
17
17
  config.assets.compile = false
18
18
  config.assets.digest = true
19
+
20
+ if Rails::VERSION::STRING >= "4.0.0"
21
+ config.secret_token = 'existing secret token'
22
+ config.secret_key_base = 'new secret key base'
23
+ end
24
+
19
25
  end
20
26
  end
21
27
  RetinaRailsTest::Application.initialize!
@@ -1,31 +1,24 @@
1
- (function() {
2
-
1
+ (function () {
3
2
  var root = (typeof exports == 'undefined' ? window : exports);
4
-
5
3
  var config = {
6
4
  // Ensure Content-Type is an image before trying to load @2x image
7
5
  // https://github.com/imulus/retinajs/pull/45)
8
6
  check_mime_type: true
9
7
  };
10
-
11
-
12
-
13
8
  root.Retina = Retina;
14
9
 
15
10
  function Retina() {}
16
-
17
- Retina.configure = function(options) {
11
+ Retina.configure = function (options) {
18
12
  if (options == null) options = {};
19
13
  for (var prop in options) config[prop] = options[prop];
20
14
  };
21
-
22
- Retina.init = function(context) {
15
+ Retina.init = function (context) {
23
16
  if (context == null) context = root;
24
-
25
17
  var existing_onload = context.onload || new Function;
26
-
27
- context.onload = function() {
28
- var images = document.getElementsByTagName("img"), retinaImages = [], i, image;
18
+ context.onload = function () {
19
+ var images = document.getElementsByTagName("img"),
20
+ retinaImages = [],
21
+ i, image;
29
22
  for (i = 0; i < images.length; i++) {
30
23
  image = images[i];
31
24
  retinaImages.push(new RetinaImage(image));
@@ -33,23 +26,17 @@
33
26
  existing_onload();
34
27
  }
35
28
  };
36
-
37
- Retina.isRetina = function(){
29
+ Retina.isRetina = function () {
38
30
  var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
39
- (min--moz-device-pixel-ratio: 1.5),\
40
- (-o-min-device-pixel-ratio: 3/2),\
41
- (min-resolution: 1.5dppx)";
42
-
31
+ (min--moz-device-pixel-ratio: 1.5),\
32
+ (-o-min-device-pixel-ratio: 3/2),\
33
+ (min-resolution: 1.5dppx)";
43
34
  if (root.devicePixelRatio > 1)
44
35
  return true;
45
-
46
36
  if (root.matchMedia && root.matchMedia(mediaQuery).matches)
47
37
  return true;
48
-
49
38
  return false;
50
39
  };
51
-
52
-
53
40
  root.RetinaImagePath = RetinaImagePath;
54
41
 
55
42
  function RetinaImagePath(path, at_2x_path) {
@@ -58,33 +45,26 @@
58
45
  this.at_2x_path = at_2x_path;
59
46
  this.perform_check = false;
60
47
  } else {
61
- this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
48
+ this.at_2x_path = path.replace(/\.\w+$/, function (match) {
49
+ return "@2x" + match;
50
+ });
62
51
  this.perform_check = true;
63
52
  }
64
53
  }
65
-
66
54
  RetinaImagePath.confirmed_paths = [];
67
-
68
- RetinaImagePath.prototype.is_external = function() {
69
- return !!(this.path.match(/^https?\:/i) && !this.path.match('//' + document.domain) )
70
- }
71
-
72
- RetinaImagePath.prototype.check_2x_variant = function(callback) {
55
+ RetinaImagePath.prototype.check_2x_variant = function (callback) {
73
56
  var http, that = this;
74
- if (this.is_external()) {
75
- return callback(false);
76
- } else if (!this.perform_check && typeof this.at_2x_path !== "undefined" && this.at_2x_path !== null) {
57
+ if (!this.perform_check && typeof this.at_2x_path !== "undefined" && this.at_2x_path !== null) {
77
58
  return callback(true);
78
59
  } else if (this.at_2x_path in RetinaImagePath.confirmed_paths) {
79
60
  return callback(true);
80
61
  } else {
81
62
  http = new XMLHttpRequest;
82
63
  http.open('HEAD', this.at_2x_path);
83
- http.onreadystatechange = function() {
64
+ http.onreadystatechange = function () {
84
65
  if (http.readyState != 4) {
85
66
  return callback(false);
86
67
  }
87
-
88
68
  if (http.status >= 200 && http.status <= 399) {
89
69
  if (config.check_mime_type) {
90
70
  var type = http.getResponseHeader('Content-Type');
@@ -92,7 +72,6 @@
92
72
  return callback(false);
93
73
  }
94
74
  }
95
-
96
75
  RetinaImagePath.confirmed_paths.push(that.at_2x_path);
97
76
  return callback(true);
98
77
  } else {
@@ -103,25 +82,21 @@
103
82
  }
104
83
  }
105
84
 
106
-
107
-
108
85
  function RetinaImage(el) {
109
86
  this.el = el;
110
87
  this.path = new RetinaImagePath(this.el.getAttribute('src'), this.el.getAttribute('data-at2x'));
111
88
  var that = this;
112
- this.path.check_2x_variant(function(hasVariant) {
89
+ this.path.check_2x_variant(function (hasVariant) {
113
90
  if (hasVariant) that.swap();
114
91
  });
115
92
  }
116
-
117
93
  root.RetinaImage = RetinaImage;
118
-
119
- RetinaImage.prototype.swap = function(path) {
94
+ RetinaImage.prototype.swap = function (path) {
120
95
  if (typeof path == 'undefined') path = this.path.at_2x_path;
121
-
122
96
  var that = this;
97
+
123
98
  function load() {
124
- if (! that.el.complete) {
99
+ if (!that.el.complete) {
125
100
  setTimeout(load, 5);
126
101
  } else {
127
102
  that.el.setAttribute('width', that.el.offsetWidth);
@@ -132,12 +107,7 @@
132
107
  }
133
108
  load();
134
109
  }
135
-
136
-
137
-
138
-
139
110
  if (Retina.isRetina()) {
140
111
  Retina.init(root);
141
112
  }
142
-
143
- })();
113
+ })();
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retina_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Johan van Zonneveld
@@ -10,60 +9,53 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-06-10 00:00:00.000000000 Z
12
+ date: 2013-11-11 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: bundler
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: 1.0.0
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: 1.0.0
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rake
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: rspec
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '2.3'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '2.3'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: rspec-rails
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
60
  - - ~>
69
61
  - !ruby/object:Gem::Version
@@ -71,7 +63,6 @@ dependencies:
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
67
  - - ~>
77
68
  - !ruby/object:Gem::Version
@@ -79,99 +70,93 @@ dependencies:
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: carrierwave
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: paperclip
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
- - - ! '>='
88
+ - - '>='
101
89
  - !ruby/object:Gem::Version
102
90
  version: '0'
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
- - - ! '>='
95
+ - - '>='
109
96
  - !ruby/object:Gem::Version
110
97
  version: '0'
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: rmagick
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
- - - ! '>='
102
+ - - '>='
117
103
  - !ruby/object:Gem::Version
118
104
  version: '0'
119
105
  type: :development
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
- - - ! '>='
109
+ - - '>='
125
110
  - !ruby/object:Gem::Version
126
111
  version: '0'
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: sqlite3
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
- - - ! '>='
116
+ - - '>='
133
117
  - !ruby/object:Gem::Version
134
118
  version: '0'
135
119
  type: :development
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
- - - ! '>='
123
+ - - '>='
141
124
  - !ruby/object:Gem::Version
142
125
  version: '0'
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: coveralls
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
129
  requirements:
148
- - - ! '>='
130
+ - - '>='
149
131
  - !ruby/object:Gem::Version
150
132
  version: '0'
151
133
  type: :development
152
134
  prerelease: false
153
135
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
136
  requirements:
156
- - - ! '>='
137
+ - - '>='
157
138
  - !ruby/object:Gem::Version
158
139
  version: '0'
159
140
  - !ruby/object:Gem::Dependency
160
141
  name: rails
161
142
  requirement: !ruby/object:Gem::Requirement
162
- none: false
163
143
  requirements:
164
- - - ! '>='
144
+ - - '>='
165
145
  - !ruby/object:Gem::Version
166
- version: '3.0'
146
+ version: 3.2.0
147
+ - - <
148
+ - !ruby/object:Gem::Version
149
+ version: 4.0.0
167
150
  type: :runtime
168
151
  prerelease: false
169
152
  version_requirements: !ruby/object:Gem::Requirement
170
- none: false
171
153
  requirements:
172
- - - ! '>='
154
+ - - '>='
155
+ - !ruby/object:Gem::Version
156
+ version: 3.2.0
157
+ - - <
173
158
  - !ruby/object:Gem::Version
174
- version: '3.0'
159
+ version: 4.0.0
175
160
  description: Retina Rails automatically generates retina versions of your uploaded
176
161
  images (CarrierWave or Paperclip). It detects if a visitor has a retina display
177
162
  and if so it displays the @2x version
@@ -208,32 +193,32 @@ files:
208
193
  - spec/spec_helper.rb
209
194
  - spec/strategies/carrierwave_spec.rb
210
195
  - spec/strategies/paperclip_spec.rb
196
+ - spec/support/file_string_io.rb
211
197
  - spec/support/rails.rb
212
198
  - spec/support/schema.rb
213
199
  - vendor/assets/javascripts/retina.js
214
200
  homepage: https://github.com/jhnvz/retina_rails.git
215
201
  licenses: []
202
+ metadata: {}
216
203
  post_install_message:
217
204
  rdoc_options: []
218
205
  require_paths:
219
206
  - lib
220
207
  required_ruby_version: !ruby/object:Gem::Requirement
221
- none: false
222
208
  requirements:
223
- - - ! '>='
209
+ - - '>='
224
210
  - !ruby/object:Gem::Version
225
211
  version: '0'
226
212
  required_rubygems_version: !ruby/object:Gem::Requirement
227
- none: false
228
213
  requirements:
229
- - - ! '>='
214
+ - - '>='
230
215
  - !ruby/object:Gem::Version
231
216
  version: '0'
232
217
  requirements: []
233
218
  rubyforge_project:
234
- rubygems_version: 1.8.24
219
+ rubygems_version: 2.1.5
235
220
  signing_key:
236
- specification_version: 3
221
+ specification_version: 4
237
222
  summary: Makes your live easier optimizing for retina displays
238
223
  test_files:
239
224
  - spec/deprecation/carrierwave_spec.rb
@@ -246,5 +231,6 @@ test_files:
246
231
  - spec/spec_helper.rb
247
232
  - spec/strategies/carrierwave_spec.rb
248
233
  - spec/strategies/paperclip_spec.rb
234
+ - spec/support/file_string_io.rb
249
235
  - spec/support/rails.rb
250
236
  - spec/support/schema.rb