retina_rails 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 CHANGED
@@ -1,3 +1,4 @@
1
+ .DS_Store
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
@@ -12,7 +13,9 @@ lib/bundler/man
12
13
  pkg
13
14
  rdoc
14
15
  spec/reports
16
+ spec/paperclip_uploads
15
17
  test/tmp
16
18
  test/version_tmp
17
19
  tmp
20
+ log
18
21
  uploads
data/README.md CHANGED
@@ -7,7 +7,7 @@ How it works
7
7
 
8
8
  Retina Rails automatically generates retina versions of your uploaded images (CarrierWave or Paperclip). It detects if a visitor has a retina display and if so it displays the @2x version.
9
9
 
10
- Note: It also works for images that live in assets/images
10
+ Note: It also works for images that live in assets/images.
11
11
 
12
12
  Installation
13
13
  ------------
@@ -52,6 +52,13 @@ class ExampleUploader < ActiveRecord::Base
52
52
  end
53
53
  ```
54
54
 
55
+ For retina images use
56
+ ------------
57
+
58
+ ```ruby
59
+ = image_tag('/assets/image.png', :retina => true)
60
+ ```
61
+
55
62
  Voila! Now you're using Retina Rails.
56
63
 
57
64
  Credits
@@ -2,12 +2,12 @@ require "retina_rails/version"
2
2
  require 'retina_rails/extensions'
3
3
  require "retina_rails/paperclip"
4
4
  require "retina_rails/carrierwave"
5
+ require "retina_rails/helpers"
5
6
 
6
7
  module RetinaRails
7
8
 
8
9
  if defined?(Rails)
9
- class Engine < Rails::Engine
10
- end
10
+ class Engine < Rails::Engine; end
11
11
  end
12
12
 
13
13
  end
@@ -0,0 +1,22 @@
1
+ module ActionView
2
+ module Helpers
3
+ module AssetTagHelper
4
+
5
+ def image_tag_with_retina(source, options={})
6
+ retina = options.delete(:retina)
7
+
8
+ if retina
9
+ retina_source = source.split('.')
10
+ filename = retina_source.slice!(-2)
11
+ retina_source = retina_source.insert(-2, "#{filename}@2x").join('.')
12
+
13
+ options.merge!(:data => { :at2x => path_to_image(retina_source) })
14
+ end
15
+
16
+ image_tag_without_retina(source, options)
17
+ end
18
+ alias_method_chain :image_tag, :retina
19
+
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module RetinaRails
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.add_development_dependency "bundler", ">= 1.0.0"
21
21
  gem.add_development_dependency "rake"
22
22
  gem.add_development_dependency "rspec", ">= 2.3"
23
+ gem.add_development_dependency "rspec-rails", "~> 2.0"
23
24
  gem.add_development_dependency 'carrierwave'
24
25
  gem.add_development_dependency 'paperclip'
25
26
  gem.add_development_dependency "sqlite3"
@@ -0,0 +1,10 @@
1
+ ---
2
+ image.png: image-e8de7f87c2b9d08490575267a4c9eddc.png
3
+ image/index.png: image-e8de7f87c2b9d08490575267a4c9eddc.png
4
+ image@2x.png: image@2x-0842b16379ded9ddcc299912621f76bc.png
5
+ image@2x/index.png: image@2x-0842b16379ded9ddcc299912621f76bc.png
6
+
7
+ image.some.png: image.some-e8de7f87c2b9d08490575267a4c9eddc.png
8
+ image.some/index.png: image.some-e8de7f87c2b9d08490575267a4c9eddc.png
9
+ image.some@2x.png: image.some@2x-0842b16379ded9ddcc299912621f76bc.png
10
+ image.some@2x/index.png: image.some@2x-0842b16379ded9ddcc299912621f76bc.png
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActionView::Helpers::AssetTagHelper, :type => :helper do
4
+
5
+ subject { helper }
6
+
7
+ describe :image_tag do
8
+
9
+ context 'with retina option' do
10
+
11
+ it { subject.image_tag('image.png', :retina => true).should == '<img alt="Image" data-at2x="/assets/image@2x-0842b16379ded9ddcc299912621f76bc.png" src="/assets/image-e8de7f87c2b9d08490575267a4c9eddc.png" />' }
12
+
13
+ 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
+
15
+ end
16
+
17
+ context 'without retina' do
18
+
19
+ it { subject.image_tag('image.png').should == '<img alt="Image" src="/assets/image-e8de7f87c2b9d08490575267a4c9eddc.png" />' }
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -1,18 +1,32 @@
1
+ require 'rubygems'
1
2
  require 'active_support'
2
3
  require 'active_record'
3
4
 
5
+ ## Carrierwave
6
+
4
7
  require 'carrierwave'
5
8
 
9
+ ## Paperclip
6
10
 
7
11
  require 'paperclip'
8
12
  require "paperclip/railtie"
9
13
  Paperclip::Railtie.insert
10
14
 
11
- require 'retina_rails'
15
+ ## Setup fixture database for activerecord
12
16
 
13
17
  ActiveRecord::Base.establish_connection(
14
18
  :adapter => "sqlite3",
15
19
  :database => File.dirname(__FILE__) + "/fixtures/db/retina_rails.sqlite3"
16
20
  )
17
21
 
18
- load File.dirname(__FILE__) + '/support/schema.rb'
22
+ ## Load support files
23
+
24
+ Dir["spec/support/**/*.rb"].each { |f| load f }
25
+
26
+ ## Load rspec rails after initializing rails app
27
+
28
+ require 'rspec/rails'
29
+
30
+ ## Load retina_rails
31
+
32
+ require 'retina_rails'
@@ -0,0 +1,21 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require "sprockets/railtie"
4
+
5
+ module RetinaRailsTest
6
+ class Application < Rails::Application
7
+ config.active_support.deprecation = :log
8
+
9
+ config.assets.manifest = Rails.public_path.gsub('public', 'spec/fixtures')
10
+
11
+ ## Asset config
12
+
13
+ config.assets.version = '1.0'
14
+ config.serve_static_assets = false
15
+ config.assets.enabled = true
16
+ config.assets.compress = true
17
+ config.assets.compile = false
18
+ config.assets.digest = true
19
+ end
20
+ end
21
+ RetinaRailsTest::Application.initialize!
@@ -28,9 +28,7 @@
28
28
  var images = document.getElementsByTagName("img"), retinaImages = [], i, image;
29
29
  for (i = 0; i < images.length; i++) {
30
30
  image = images[i];
31
- if ($(image).attr('data-retina') != 'true') {
32
- retinaImages.push(new RetinaImage(image));
33
- }
31
+ retinaImages.push(new RetinaImage(image));
34
32
  }
35
33
  existing_onload();
36
34
  }
@@ -54,9 +52,15 @@
54
52
 
55
53
  root.RetinaImagePath = RetinaImagePath;
56
54
 
57
- function RetinaImagePath(path) {
55
+ function RetinaImagePath(path, at_2x_path) {
58
56
  this.path = path;
59
- this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
57
+ if (typeof at_2x_path !== "undefined" && at_2x_path !== null) {
58
+ this.at_2x_path = at_2x_path;
59
+ this.perform_check = false;
60
+ } else {
61
+ this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
62
+ this.perform_check = true;
63
+ }
60
64
  }
61
65
 
62
66
  RetinaImagePath.confirmed_paths = [];
@@ -69,6 +73,8 @@
69
73
  var http, that = this;
70
74
  if (this.is_external()) {
71
75
  return callback(false);
76
+ } else if (!this.perform_check && typeof this.at_2x_path !== "undefined" && this.at_2x_path !== null) {
77
+ return callback(true);
72
78
  } else if (this.at_2x_path in RetinaImagePath.confirmed_paths) {
73
79
  return callback(true);
74
80
  } else {
@@ -101,7 +107,7 @@
101
107
 
102
108
  function RetinaImage(el) {
103
109
  this.el = el;
104
- this.path = new RetinaImagePath(this.el.getAttribute('src'));
110
+ this.path = new RetinaImagePath(this.el.getAttribute('src'), this.el.getAttribute('data-at2x'));
105
111
  var that = this;
106
112
  this.path.check_2x_variant(function(hasVariant) {
107
113
  if (hasVariant) that.swap();
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: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '2.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.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: '2.0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: carrierwave
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -157,6 +173,7 @@ files:
157
173
  - lib/retina_rails.rb
158
174
  - lib/retina_rails/carrierwave.rb
159
175
  - lib/retina_rails/extensions.rb
176
+ - lib/retina_rails/helpers.rb
160
177
  - lib/retina_rails/paperclip.rb
161
178
  - lib/retina_rails/version.rb
162
179
  - retina_rails.gemspec
@@ -164,8 +181,11 @@ files:
164
181
  - spec/extensions_spec.rb
165
182
  - spec/fixtures/db/retina_rails.sqlite3
166
183
  - spec/fixtures/images/avatar.jpeg
184
+ - spec/fixtures/manifest.yml
185
+ - spec/helpers_spec.rb
167
186
  - spec/paperclip_spec.rb
168
187
  - spec/spec_helper.rb
188
+ - spec/support/rails.rb
169
189
  - spec/support/schema.rb
170
190
  - vendor/assets/javascripts/retina.js
171
191
  homepage: https://github.com/jhnvz/retina_rails.git
@@ -197,6 +217,9 @@ test_files:
197
217
  - spec/extensions_spec.rb
198
218
  - spec/fixtures/db/retina_rails.sqlite3
199
219
  - spec/fixtures/images/avatar.jpeg
220
+ - spec/fixtures/manifest.yml
221
+ - spec/helpers_spec.rb
200
222
  - spec/paperclip_spec.rb
201
223
  - spec/spec_helper.rb
224
+ - spec/support/rails.rb
202
225
  - spec/support/schema.rb