retina_rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +76 -0
- data/Rakefile +5 -0
- data/lib/retina_rails.rb +13 -0
- data/lib/retina_rails/carrierwave.rb +50 -0
- data/lib/retina_rails/extensions.rb +26 -0
- data/lib/retina_rails/paperclip.rb +55 -0
- data/lib/retina_rails/version.rb +3 -0
- data/retina_rails.gemspec +29 -0
- data/spec/carrierwave_spec.rb +70 -0
- data/spec/extensions_spec.rb +38 -0
- data/spec/fixtures/db/retina_rails.sqlite3 +0 -0
- data/spec/fixtures/images/avatar.jpeg +0 -0
- data/spec/paperclip_spec.rb +43 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/schema.rb +9 -0
- data/vendor/assets/javascripts/retina.js +137 -0
- metadata +201 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Johan van Zonneveld
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
## Retina Rails [![Build Status](https://secure.travis-ci.org/jhnvz/retina_rails.png?branch=master)](http://travis-ci.org/jhnvz/retina_rails)
|
2
|
+
|
3
|
+
Makes your live easier optimizing for retina displays.
|
4
|
+
|
5
|
+
How it works
|
6
|
+
------------
|
7
|
+
|
8
|
+
Retina Rails automatically generates retina versions of your uploaded images (with CarrierWave or Paperclip). It detects with javascript if a visitor has a retina display and if so it displays the @2x version.
|
9
|
+
|
10
|
+
Note: It also works for images that live in assets/images
|
11
|
+
|
12
|
+
Installation
|
13
|
+
------------
|
14
|
+
|
15
|
+
1. Add `gem 'retina_rails'` to your Gemfile.
|
16
|
+
1. Run `bundle install`.
|
17
|
+
1. Add `//= require retina` to your Javascript manifest file (usually found at `app/assets/javascripts/application.js`).
|
18
|
+
|
19
|
+
CarrierWave
|
20
|
+
------------
|
21
|
+
|
22
|
+
Add `include RetinaRails::CarrierWave` to the bottom of your uploader
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class ExampleUploader < CarrierWave::Uploader::Base
|
26
|
+
|
27
|
+
version :small do
|
28
|
+
process :resize_to_fill => [30, 30]
|
29
|
+
end
|
30
|
+
|
31
|
+
include RetinaRails::CarrierWave
|
32
|
+
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Paperclip
|
37
|
+
------------
|
38
|
+
|
39
|
+
Add `include RetinaRails::Paperclip` to the bottom of your class
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class ExampleUploader < ActiveRecord::Base
|
43
|
+
|
44
|
+
has_attached_file :image,
|
45
|
+
:styles => {
|
46
|
+
:original => ["800x800", :jpg],
|
47
|
+
:big => ["125x125#", :jpg]
|
48
|
+
}
|
49
|
+
|
50
|
+
include RetinaRails::Paperclip
|
51
|
+
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Voila! Now you're using Retina Rails.
|
56
|
+
|
57
|
+
Credits
|
58
|
+
------------
|
59
|
+
|
60
|
+
Retina Rails uses retinajs (https://github.com/imulus/retinajs)
|
61
|
+
|
62
|
+
Note on Patches/Pull Requests
|
63
|
+
------------
|
64
|
+
|
65
|
+
* Fork the project.
|
66
|
+
* Make your feature addition or bug fix.
|
67
|
+
* Add tests for it. This is important so I don't break it in a
|
68
|
+
future version unintentionally.
|
69
|
+
* Commit, do not mess with rakefile, version, or history.
|
70
|
+
(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)
|
71
|
+
* Send me a pull request. Bonus points for topic branches.
|
72
|
+
|
73
|
+
Copyright
|
74
|
+
------------
|
75
|
+
|
76
|
+
Copyright (c) 2012 Johan van Zonneveld. See LICENSE for details.
|
data/Rakefile
ADDED
data/lib/retina_rails.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module RetinaRails
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
|
9
|
+
## Define retina version based on defined versions in the uploader class
|
10
|
+
versions.each do |v|
|
11
|
+
|
12
|
+
processor = nil
|
13
|
+
|
14
|
+
## Check if there's a resize processor to get the dimensions
|
15
|
+
v[1][:uploader].processors.each do |p|
|
16
|
+
processor = p if p[0].to_s.scan(/resize_to_fill|resize_to_limit|resize_to_fit|resize_and_pad/).any?
|
17
|
+
end
|
18
|
+
|
19
|
+
## Define a retina version if processor is present
|
20
|
+
if processor
|
21
|
+
|
22
|
+
options = processor[1].dup
|
23
|
+
|
24
|
+
width = options[0] * 2
|
25
|
+
height = options[1] * 2
|
26
|
+
|
27
|
+
2.times { options.delete_at(0) }
|
28
|
+
|
29
|
+
options.insert(0, height)
|
30
|
+
options.insert(0, width)
|
31
|
+
|
32
|
+
version "#{v[0]}_retina" do
|
33
|
+
process processor[0] => options
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
## Set the correct filename for storage according to the convention (append @2x to filename)
|
42
|
+
def full_filename(for_file)
|
43
|
+
super.tap do |file_name|
|
44
|
+
file_name.gsub!('.', '@2x.').gsub!('retina_', '') if version_name.to_s.include?('retina')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RetinaRails::Extensions
|
2
|
+
|
3
|
+
## Insert :retina interpolation in url or path
|
4
|
+
def self.optimize_path(path)
|
5
|
+
path.scan(':retina').empty? ? path.gsub(':filename', ':basename.:extensions').split('.').insert(-2, ':retina.').join : path
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.override_default_options
|
9
|
+
|
10
|
+
## Remove _retina from style so it doesn't end up in filename
|
11
|
+
Paperclip.interpolates :style do |attachment, style|
|
12
|
+
style.to_s.end_with?('_retina') ? style.to_s[0..-8] : style
|
13
|
+
end
|
14
|
+
|
15
|
+
## Replace :retina with @2x if style ends with _retina
|
16
|
+
Paperclip.interpolates :retina do |attachment, style|
|
17
|
+
style.to_s.end_with?('_retina') ? '@2x' : ''
|
18
|
+
end
|
19
|
+
|
20
|
+
## Make default url compatible with retina optimzer
|
21
|
+
url = Paperclip::Attachment.default_options[:url]
|
22
|
+
Paperclip::Attachment.default_options[:url] = optimize_path(url)
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module RetinaRails
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
|
9
|
+
## Override paperclip default options
|
10
|
+
RetinaRails::Extensions.override_default_options
|
11
|
+
|
12
|
+
## Iterate over each has_attached_file
|
13
|
+
attachment_definitions.each_pair do |key, value|
|
14
|
+
|
15
|
+
## Check for style definitions
|
16
|
+
styles = attachment_definitions[key][:styles]
|
17
|
+
|
18
|
+
if styles
|
19
|
+
|
20
|
+
retina_styles = {}
|
21
|
+
|
22
|
+
## Iterate over styles and set optimzed dimensions
|
23
|
+
styles.each_pair do |key, value|
|
24
|
+
|
25
|
+
dimensions = value[0]
|
26
|
+
|
27
|
+
width = dimensions.scan(/\d+/)[0].to_i * 2
|
28
|
+
height = dimensions.scan(/\d+/)[1].to_i * 2
|
29
|
+
|
30
|
+
processor = dimensions.scan(/#|</).first
|
31
|
+
|
32
|
+
retina_styles["#{key}_retina".to_sym] = ["#{width}x#{height}#{processor}", value[1]]
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
## Append new retina optimzed styles
|
37
|
+
value[:styles].merge!(retina_styles)
|
38
|
+
|
39
|
+
## Make path work with retina optimization
|
40
|
+
original_path = attachment_definitions[key][:path]
|
41
|
+
value[:path] = RetinaRails::Extensions.optimize_path(original_path) if original_path
|
42
|
+
|
43
|
+
## Make url work with retina optimization
|
44
|
+
original_url = attachment_definitions[key][:url]
|
45
|
+
value[:url] = RetinaRails::Extensions.optimize_path(original_url) if original_url
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'retina_rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "retina_rails"
|
8
|
+
gem.version = RetinaRails::VERSION
|
9
|
+
gem.authors = ["Johan van Zonneveld"]
|
10
|
+
gem.email = ["johan@vzonneveld.nl"]
|
11
|
+
gem.homepage = 'https://github.com/jhnvz/retina_rails.git'
|
12
|
+
gem.summary = %q{Makes your live easier optimizing for retina displays}
|
13
|
+
gem.description = %q{Retina Rails automatically generates retina versions of your uploaded images (with CarrierWave or Paperclip). It detects with javascript if a visitor has a retina display and if so it displays the @2x version}
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "bundler", ">= 1.0.0"
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "rspec", ">= 2.3"
|
23
|
+
gem.add_development_dependency 'carrierwave'
|
24
|
+
gem.add_development_dependency 'paperclip'
|
25
|
+
gem.add_development_dependency "sqlite3"
|
26
|
+
|
27
|
+
gem.add_dependency 'rails', '>= 3.0'
|
28
|
+
gem.add_dependency 'rmagick'
|
29
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class AnonymousUploader < CarrierWave::Uploader::Base
|
4
|
+
|
5
|
+
include CarrierWave::RMagick
|
6
|
+
|
7
|
+
version :small do
|
8
|
+
process :resize_to_fill => [30, 30]
|
9
|
+
end
|
10
|
+
|
11
|
+
version :small_without_processor
|
12
|
+
|
13
|
+
include RetinaRails::CarrierWave
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class CarrierWaveUpload
|
18
|
+
|
19
|
+
extend CarrierWave::Mount
|
20
|
+
|
21
|
+
attr_accessor :avatar
|
22
|
+
attr_accessor :id
|
23
|
+
|
24
|
+
mount_uploader :avatar, AnonymousUploader
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
self.id = 999
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe RetinaRails::CarrierWave do
|
33
|
+
|
34
|
+
include CarrierWave::Test::Matchers
|
35
|
+
|
36
|
+
subject { AnonymousUploader }
|
37
|
+
|
38
|
+
before do
|
39
|
+
AnonymousUploader.enable_processing = true
|
40
|
+
@uploader = AnonymousUploader.new(CarrierWaveUpload.new, :avatar)
|
41
|
+
@uploader.store!(File.open("#{File.dirname(__FILE__)}/fixtures/images/avatar.jpeg"))
|
42
|
+
end
|
43
|
+
|
44
|
+
after do
|
45
|
+
AnonymousUploader.enable_processing = false
|
46
|
+
@uploader.remove!
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with processor' do
|
50
|
+
|
51
|
+
its(:versions) { should include :small_retina }
|
52
|
+
|
53
|
+
it { @uploader.small.should have_dimensions(30, 30) }
|
54
|
+
it { @uploader.small_retina.should have_dimensions(60, 60) }
|
55
|
+
|
56
|
+
it { File.basename(@uploader.small.current_path, 'jpeg').should include 'small_'}
|
57
|
+
|
58
|
+
it { File.basename(@uploader.small_retina.current_path, 'jpeg').should include '@2x'}
|
59
|
+
it { File.basename(@uploader.small_retina.current_path, 'jpeg').should_not include 'retina_'}
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'without processor' do
|
64
|
+
|
65
|
+
its(:versions) { should include :small_without_processor }
|
66
|
+
its(:versions) { should_not include :small_without_processor_retina }
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
describe RetinaRails::Extensions do
|
2
|
+
|
3
|
+
describe :optimze_path do
|
4
|
+
|
5
|
+
subject { RetinaRails::Extensions }
|
6
|
+
|
7
|
+
it { subject.optimize_path('/:filename').should == '/:basename:retina.:extensions' }
|
8
|
+
|
9
|
+
it { subject.optimize_path('/:basename.:extensions').should == '/:basename:retina.:extensions' }
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe :override_default_options do
|
14
|
+
|
15
|
+
context 'Paperclip default' do
|
16
|
+
|
17
|
+
before { RetinaRails::Extensions.override_default_options }
|
18
|
+
|
19
|
+
it { Paperclip::Attachment.default_options[:url].should == '/system/:class/:attachment/:id_partition/:style/:basename:retina.:extensions' }
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'User defined paperclip default' do
|
24
|
+
|
25
|
+
before do
|
26
|
+
|
27
|
+
Paperclip::Attachment.default_options[:url] = '/:class/:attachment/:id/:style/:basename.:extensions'
|
28
|
+
RetinaRails::Extensions.override_default_options
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
it { Paperclip::Attachment.default_options[:url].should == '/:class/:attachment/:id/:style/:basename:retina.:extensions' }
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class PaperclipUpload < ActiveRecord::Base
|
4
|
+
|
5
|
+
has_attached_file :avatar,
|
6
|
+
:styles => {
|
7
|
+
:original => ["800x800", :jpg],
|
8
|
+
:big => ["125x125#", :jpg]
|
9
|
+
},
|
10
|
+
:path => "#{File.dirname(__FILE__)}/:class/:id/:basename_:style.:extension",
|
11
|
+
:url => "#{File.dirname(__FILE__)}/:class/:id/:basename_:style.:extension"
|
12
|
+
|
13
|
+
include RetinaRails::Paperclip
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe RetinaRails::Paperclip do
|
18
|
+
|
19
|
+
subject { PaperclipUpload }
|
20
|
+
|
21
|
+
context 'overriding options' do
|
22
|
+
|
23
|
+
it { subject.attachment_definitions[:avatar][:styles][:original_retina].should == ['1600x1600', :jpg] }
|
24
|
+
it { subject.attachment_definitions[:avatar][:styles][:big_retina].should == ['250x250#', :jpg] }
|
25
|
+
|
26
|
+
it { subject.attachment_definitions[:avatar][:path].should == "#{File.dirname(__FILE__)}/:class/:id/:basename_:style:retina.:extension" }
|
27
|
+
it { subject.attachment_definitions[:avatar][:url].should == "#{File.dirname(__FILE__)}/:class/:id/:basename_:style:retina.:extension" }
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'uploads' do
|
32
|
+
|
33
|
+
subject { PaperclipUpload.create(:avatar => File.open("#{File.dirname(__FILE__)}/fixtures/images/avatar.jpeg")) }
|
34
|
+
|
35
|
+
it { subject.avatar.url(:big).should == "#{File.dirname(__FILE__)}/paperclip_uploads/1/avatar_big.jpg" }
|
36
|
+
it { subject.avatar.url(:big_retina).should == "#{File.dirname(__FILE__)}/paperclip_uploads/2/avatar_big@2x.jpg" }
|
37
|
+
|
38
|
+
it { Paperclip::Geometry.from_file(subject.avatar.url(:big)).to_s.should == '125x125' }
|
39
|
+
it { Paperclip::Geometry.from_file(subject.avatar.url(:big_retina)).to_s.should == '250x250' }
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
require 'carrierwave'
|
5
|
+
|
6
|
+
|
7
|
+
require 'paperclip'
|
8
|
+
require "paperclip/railtie"
|
9
|
+
Paperclip::Railtie.insert
|
10
|
+
|
11
|
+
require 'retina_rails'
|
12
|
+
|
13
|
+
ActiveRecord::Base.establish_connection(
|
14
|
+
:adapter => "sqlite3",
|
15
|
+
:database => File.dirname(__FILE__) + "/fixtures/db/retina_rails.sqlite3"
|
16
|
+
)
|
17
|
+
|
18
|
+
load File.dirname(__FILE__) + '/support/schema.rb'
|
@@ -0,0 +1,137 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
var root = (typeof exports == 'undefined' ? window : exports);
|
4
|
+
|
5
|
+
var config = {
|
6
|
+
// Ensure Content-Type is an image before trying to load @2x image
|
7
|
+
// https://github.com/imulus/retinajs/pull/45)
|
8
|
+
check_mime_type: true
|
9
|
+
};
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
root.Retina = Retina;
|
14
|
+
|
15
|
+
function Retina() {}
|
16
|
+
|
17
|
+
Retina.configure = function(options) {
|
18
|
+
if (options == null) options = {};
|
19
|
+
for (var prop in options) config[prop] = options[prop];
|
20
|
+
};
|
21
|
+
|
22
|
+
Retina.init = function(context) {
|
23
|
+
if (context == null) context = root;
|
24
|
+
|
25
|
+
var existing_onload = context.onload || new Function;
|
26
|
+
|
27
|
+
context.onload = function() {
|
28
|
+
var images = document.getElementsByTagName("img"), retinaImages = [], i, image;
|
29
|
+
for (i = 0; i < images.length; i++) {
|
30
|
+
image = images[i];
|
31
|
+
if ($(image).attr('data-retina') != 'true') {
|
32
|
+
retinaImages.push(new RetinaImage(image));
|
33
|
+
}
|
34
|
+
}
|
35
|
+
existing_onload();
|
36
|
+
}
|
37
|
+
};
|
38
|
+
|
39
|
+
Retina.isRetina = function(){
|
40
|
+
var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
|
41
|
+
(min--moz-device-pixel-ratio: 1.5),\
|
42
|
+
(-o-min-device-pixel-ratio: 3/2),\
|
43
|
+
(min-resolution: 1.5dppx)";
|
44
|
+
|
45
|
+
if (root.devicePixelRatio > 1)
|
46
|
+
return true;
|
47
|
+
|
48
|
+
if (root.matchMedia && root.matchMedia(mediaQuery).matches)
|
49
|
+
return true;
|
50
|
+
|
51
|
+
return false;
|
52
|
+
};
|
53
|
+
|
54
|
+
|
55
|
+
root.RetinaImagePath = RetinaImagePath;
|
56
|
+
|
57
|
+
function RetinaImagePath(path) {
|
58
|
+
this.path = path;
|
59
|
+
this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
|
60
|
+
}
|
61
|
+
|
62
|
+
RetinaImagePath.confirmed_paths = [];
|
63
|
+
|
64
|
+
RetinaImagePath.prototype.is_external = function() {
|
65
|
+
return !!(this.path.match(/^https?\:/i) && !this.path.match('//' + document.domain) )
|
66
|
+
}
|
67
|
+
|
68
|
+
RetinaImagePath.prototype.check_2x_variant = function(callback) {
|
69
|
+
var http, that = this;
|
70
|
+
if (this.is_external()) {
|
71
|
+
return callback(false);
|
72
|
+
} else if (this.at_2x_path in RetinaImagePath.confirmed_paths) {
|
73
|
+
return callback(true);
|
74
|
+
} else {
|
75
|
+
http = new XMLHttpRequest;
|
76
|
+
http.open('HEAD', this.at_2x_path);
|
77
|
+
http.onreadystatechange = function() {
|
78
|
+
if (http.readyState != 4) {
|
79
|
+
return callback(false);
|
80
|
+
}
|
81
|
+
|
82
|
+
if (http.status >= 200 && http.status <= 399) {
|
83
|
+
if (config.check_mime_type) {
|
84
|
+
var type = http.getResponseHeader('Content-Type');
|
85
|
+
if (type == null || !type.match(/^image/i)) {
|
86
|
+
return callback(false);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
RetinaImagePath.confirmed_paths.push(that.at_2x_path);
|
91
|
+
return callback(true);
|
92
|
+
} else {
|
93
|
+
return callback(false);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
http.send();
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
function RetinaImage(el) {
|
103
|
+
this.el = el;
|
104
|
+
this.path = new RetinaImagePath(this.el.getAttribute('src'));
|
105
|
+
var that = this;
|
106
|
+
this.path.check_2x_variant(function(hasVariant) {
|
107
|
+
if (hasVariant) that.swap();
|
108
|
+
});
|
109
|
+
}
|
110
|
+
|
111
|
+
root.RetinaImage = RetinaImage;
|
112
|
+
|
113
|
+
RetinaImage.prototype.swap = function(path) {
|
114
|
+
if (typeof path == 'undefined') path = this.path.at_2x_path;
|
115
|
+
|
116
|
+
var that = this;
|
117
|
+
function load() {
|
118
|
+
if (! that.el.complete) {
|
119
|
+
setTimeout(load, 5);
|
120
|
+
} else {
|
121
|
+
that.el.setAttribute('width', that.el.offsetWidth);
|
122
|
+
that.el.setAttribute('height', that.el.offsetHeight);
|
123
|
+
that.el.setAttribute('src', path);
|
124
|
+
that.el.setAttribute('data-retina', true);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
load();
|
128
|
+
}
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
if (Retina.isRetina()) {
|
134
|
+
Retina.init(root);
|
135
|
+
}
|
136
|
+
|
137
|
+
})();
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: retina_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Johan van Zonneveld
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.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: '0'
|
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: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.3'
|
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: '2.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: carrierwave
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: paperclip
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: sqlite3
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rails
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rmagick
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: Retina Rails automatically generates retina versions of your uploaded
|
143
|
+
images (with CarrierWave or Paperclip). It detects with javascript if a visitor
|
144
|
+
has a retina display and if so it displays the @2x version
|
145
|
+
email:
|
146
|
+
- johan@vzonneveld.nl
|
147
|
+
executables: []
|
148
|
+
extensions: []
|
149
|
+
extra_rdoc_files: []
|
150
|
+
files:
|
151
|
+
- .gitignore
|
152
|
+
- Gemfile
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- lib/retina_rails.rb
|
157
|
+
- lib/retina_rails/carrierwave.rb
|
158
|
+
- lib/retina_rails/extensions.rb
|
159
|
+
- lib/retina_rails/paperclip.rb
|
160
|
+
- lib/retina_rails/version.rb
|
161
|
+
- retina_rails.gemspec
|
162
|
+
- spec/carrierwave_spec.rb
|
163
|
+
- spec/extensions_spec.rb
|
164
|
+
- spec/fixtures/db/retina_rails.sqlite3
|
165
|
+
- spec/fixtures/images/avatar.jpeg
|
166
|
+
- spec/paperclip_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/support/schema.rb
|
169
|
+
- vendor/assets/javascripts/retina.js
|
170
|
+
homepage: https://github.com/jhnvz/retina_rails.git
|
171
|
+
licenses: []
|
172
|
+
post_install_message:
|
173
|
+
rdoc_options: []
|
174
|
+
require_paths:
|
175
|
+
- lib
|
176
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
none: false
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 1.8.24
|
191
|
+
signing_key:
|
192
|
+
specification_version: 3
|
193
|
+
summary: Makes your live easier optimizing for retina displays
|
194
|
+
test_files:
|
195
|
+
- spec/carrierwave_spec.rb
|
196
|
+
- spec/extensions_spec.rb
|
197
|
+
- spec/fixtures/db/retina_rails.sqlite3
|
198
|
+
- spec/fixtures/images/avatar.jpeg
|
199
|
+
- spec/paperclip_spec.rb
|
200
|
+
- spec/spec_helper.rb
|
201
|
+
- spec/support/schema.rb
|