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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -3
  3. data/.travis.yml +16 -4
  4. data/README.md +57 -29
  5. data/UPGRADING +7 -0
  6. data/UPGRADING.md +60 -0
  7. data/lib/retina_rails.rb +11 -7
  8. data/lib/retina_rails/extensions.rb +16 -0
  9. data/lib/retina_rails/extensions/carrierwave.rb +25 -0
  10. data/lib/retina_rails/extensions/paperclip.rb +23 -0
  11. data/lib/retina_rails/helpers.rb +42 -12
  12. data/lib/retina_rails/processors.rb +14 -0
  13. data/lib/retina_rails/processors/carrierwave.rb +49 -0
  14. data/lib/retina_rails/processors/paperclip.rb +30 -0
  15. data/lib/retina_rails/strategies.rb +6 -7
  16. data/lib/retina_rails/strategies/carrierwave.rb +56 -50
  17. data/lib/retina_rails/strategies/paperclip.rb +53 -55
  18. data/lib/retina_rails/version.rb +1 -1
  19. data/retina_rails.gemspec +11 -4
  20. data/spec/fixtures/db/retina_rails.sqlite3 +0 -0
  21. data/spec/helpers_spec.rb +87 -13
  22. data/spec/spec_helper.rb +10 -4
  23. data/spec/strategies/carrierwave_spec.rb +117 -154
  24. data/spec/strategies/paperclip_spec.rb +77 -104
  25. data/spec/support/carrierwave.rb +15 -0
  26. data/spec/support/file_string_io.rb +2 -0
  27. data/spec/support/paperclip.rb +9 -0
  28. data/spec/support/rails.rb +0 -11
  29. data/spec/support/schema.rb +8 -2
  30. metadata +53 -52
  31. data/lib/retina_rails/deprecation/carrierwave.rb +0 -23
  32. data/lib/retina_rails/deprecation/paperclip.rb +0 -23
  33. data/lib/retina_rails/exception.rb +0 -15
  34. data/spec/deprecation/carrierwave_spec.rb +0 -13
  35. data/spec/deprecation/paperclip_spec.rb +0 -14
  36. data/spec/fixtures/images/avatar.with.dots.jpeg +0 -0
  37. data/spec/fixtures/manifest.yml +0 -10
  38. data/vendor/assets/javascripts/retina.js +0 -113
@@ -1,23 +0,0 @@
1
- module RetinaRails
2
-
3
- module CarrierWave
4
-
5
- extend ActiveSupport::Concern
6
-
7
- module ClassMethods
8
-
9
- def raise_depraction_error!
10
- raise RetinaRails::DeprecationError.new("As of version 1.0.0.beta1 activating RetinaRails by including `RetinaRails::Carrierwave` is depracted. Add `retina!` to your uploader instead.")
11
- end
12
-
13
- end
14
-
15
- included do
16
-
17
- raise_depraction_error!
18
-
19
- end
20
-
21
- end
22
-
23
- end
@@ -1,23 +0,0 @@
1
- module RetinaRails
2
-
3
- module Paperclip
4
-
5
- extend ActiveSupport::Concern
6
-
7
- module ClassMethods
8
-
9
- def raise_depraction_error!
10
- raise RetinaRails::DeprecationError.new("As of version 1.0.0.beta1 activating RetinaRails by including `RetinaRails::Paperclip` is depracted. Add `retina!` to your model instead.")
11
- end
12
-
13
- end
14
-
15
- included do
16
-
17
- raise_depraction_error!
18
-
19
- end
20
-
21
- end
22
-
23
- end
@@ -1,15 +0,0 @@
1
- module RetinaRails
2
-
3
- class Exception < StandardError
4
-
5
- attr_accessor :message
6
-
7
- def initialize(message = nil)
8
- self.message = message
9
- end
10
-
11
- end
12
-
13
- class DeprecationError < Exception; end
14
-
15
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RetinaRails::CarrierWave do
4
-
5
- it 'should raise a deprection error when included the old way' do
6
- expect do
7
- class DeprecatedUploader < CarrierWave::Uploader::Base
8
- include RetinaRails::CarrierWave
9
- end
10
- end.to raise_error(RetinaRails::DeprecationError)
11
- end
12
-
13
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RetinaRails::Paperclip do
4
-
5
- it 'should raise a deprection error when included the old way' do
6
- expect do
7
- class PaperclipUpload < ActiveRecord::Base
8
- include RetinaRails::Paperclip
9
- end
10
- end.to raise_error(RetinaRails::DeprecationError)
11
- end
12
-
13
- end
14
-
@@ -1,10 +0,0 @@
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
@@ -1,113 +0,0 @@
1
- (function () {
2
- var root = (typeof exports == 'undefined' ? window : exports);
3
- var config = {
4
- // Ensure Content-Type is an image before trying to load @2x image
5
- // https://github.com/imulus/retinajs/pull/45)
6
- check_mime_type: true
7
- };
8
- root.Retina = Retina;
9
-
10
- function Retina() {}
11
- Retina.configure = function (options) {
12
- if (options == null) options = {};
13
- for (var prop in options) config[prop] = options[prop];
14
- };
15
- Retina.init = function (context) {
16
- if (context == null) context = root;
17
- var existing_onload = context.onload || new Function;
18
- context.onload = function () {
19
- var images = document.getElementsByTagName("img"),
20
- retinaImages = [],
21
- i, image;
22
- for (i = 0; i < images.length; i++) {
23
- image = images[i];
24
- retinaImages.push(new RetinaImage(image));
25
- }
26
- existing_onload();
27
- }
28
- };
29
- Retina.isRetina = function () {
30
- var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
31
- (min--moz-device-pixel-ratio: 1.5),\
32
- (-o-min-device-pixel-ratio: 3/2),\
33
- (min-resolution: 1.5dppx)";
34
- if (root.devicePixelRatio > 1)
35
- return true;
36
- if (root.matchMedia && root.matchMedia(mediaQuery).matches)
37
- return true;
38
- return false;
39
- };
40
- root.RetinaImagePath = RetinaImagePath;
41
-
42
- function RetinaImagePath(path, at_2x_path) {
43
- this.path = path;
44
- if (typeof at_2x_path !== "undefined" && at_2x_path !== null) {
45
- this.at_2x_path = at_2x_path;
46
- this.perform_check = false;
47
- } else {
48
- this.at_2x_path = path.replace(/\.\w+$/, function (match) {
49
- return "@2x" + match;
50
- });
51
- this.perform_check = true;
52
- }
53
- }
54
- RetinaImagePath.confirmed_paths = [];
55
- RetinaImagePath.prototype.check_2x_variant = function (callback) {
56
- var http, that = this;
57
- if (!this.perform_check && typeof this.at_2x_path !== "undefined" && this.at_2x_path !== null) {
58
- return callback(true);
59
- } else if (this.at_2x_path in RetinaImagePath.confirmed_paths) {
60
- return callback(true);
61
- } else {
62
- http = new XMLHttpRequest;
63
- http.open('HEAD', this.at_2x_path);
64
- http.onreadystatechange = function () {
65
- if (http.readyState != 4) {
66
- return callback(false);
67
- }
68
- if (http.status >= 200 && http.status <= 399) {
69
- if (config.check_mime_type) {
70
- var type = http.getResponseHeader('Content-Type');
71
- if (type == null || !type.match(/^image/i)) {
72
- return callback(false);
73
- }
74
- }
75
- RetinaImagePath.confirmed_paths.push(that.at_2x_path);
76
- return callback(true);
77
- } else {
78
- return callback(false);
79
- }
80
- }
81
- http.send();
82
- }
83
- }
84
-
85
- function RetinaImage(el) {
86
- this.el = el;
87
- this.path = new RetinaImagePath(this.el.getAttribute('src'), this.el.getAttribute('data-at2x'));
88
- var that = this;
89
- this.path.check_2x_variant(function (hasVariant) {
90
- if (hasVariant) that.swap();
91
- });
92
- }
93
- root.RetinaImage = RetinaImage;
94
- RetinaImage.prototype.swap = function (path) {
95
- if (typeof path == 'undefined') path = this.path.at_2x_path;
96
- var that = this;
97
-
98
- function load() {
99
- if (!that.el.complete) {
100
- setTimeout(load, 5);
101
- } else {
102
- that.el.setAttribute('width', that.el.offsetWidth);
103
- that.el.setAttribute('height', that.el.offsetHeight);
104
- that.el.setAttribute('src', path);
105
- that.el.setAttribute('data-retina', true);
106
- }
107
- }
108
- load();
109
- }
110
- if (Retina.isRetina()) {
111
- Retina.init(root);
112
- }
113
- })();