retina_tag 1.3.1 → 1.4.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.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/retina_tag/engine.rb +23 -17
- data/lib/retina_tag/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be758b14dfbee1b2a1214ea8001f00dba536dd85
|
4
|
+
data.tar.gz: f66a6ac77692eb0dffaf7e5e3e2846e2b1710619
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a38a469ddd135e6320df1fbfdfc806885ed6b680734dbd5a39e56b11538a2992a5a50460abd7031996f9af8725ca18b3ef7f78527c1f084ccea3bd98eb143353
|
7
|
+
data.tar.gz: 05dc502a23eeeed21390f2fcd4ca043afd537e98ae7f091b8f1aea6a1938a0c24565b9cc14c381bc6c6775d369d1f3fe8b156c278d4f881c2cec1cb7693715b2
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Interested in making your web-sites retina compatible? Rails asset pipeline
|
4
4
|
makes this a pain with retina `image_tag`s, especially when precompiling assets.
|
5
|
-
RetinaTag resolves this by extending `image_tag` to create a `
|
5
|
+
RetinaTag resolves this by extending `image_tag` to create a `data-hidpi-src`
|
6
6
|
attribute with the retina image path if it exists.
|
7
7
|
|
8
8
|
## Installation
|
@@ -40,13 +40,13 @@ Awesome right?
|
|
40
40
|
### Forcing Refresh after loading dynamic content
|
41
41
|
Retina tag listens to the global event on document called `retina_tag:refresh`. Firing this event will force retina_tag to rescan the dom for images and update their image src if necessary. Useful if loading content dynamically. **Note:** retina_tag automatically supports turbolinks.
|
42
42
|
|
43
|
-
### Override Hidpi src attribute
|
44
|
-
In some cases it becomes necessary to override the
|
43
|
+
### Override Hidpi src data attribute
|
44
|
+
In some cases it becomes necessary to override the data-hidpi-src attribute and skip asset pipeline. A good example of this might be to load a users profile picture which is stored elsewhere.
|
45
45
|
|
46
|
-
<%=image_tag(user.photo.url(:medium), "
|
46
|
+
<%=image_tag(user.photo.url(:medium), "data-hidpi-src" => user.photo.url(:medium_2x), :height=>75, :width => 75%>
|
47
47
|
|
48
48
|
### Lazy Loading Images
|
49
|
-
If you set `:lazy => true` on an image_tag, the src attribute is moved to a
|
49
|
+
If you set `:lazy => true` on an image_tag, the src attribute is moved to a data-lodpi-src attribute. You will need to manually instruct the image to load. To do this use `RetinaTag.refreshImage(img)` where img is the image element.
|
50
50
|
|
51
51
|
|
52
52
|
## Contributing
|
data/lib/retina_tag/engine.rb
CHANGED
@@ -1,41 +1,48 @@
|
|
1
|
-
|
2
1
|
module RetinaTag
|
3
2
|
module TagHelper
|
4
3
|
def self.included(base)
|
5
|
-
base.
|
4
|
+
base.module_eval do
|
5
|
+
alias_method :image_tag_without_retina, :image_tag
|
6
|
+
alias_method :image_tag, :image_tag_with_retina
|
7
|
+
end
|
6
8
|
end
|
7
9
|
|
8
|
-
def image_tag_with_retina(source,options={})
|
10
|
+
def image_tag_with_retina(source, options={})
|
9
11
|
hidpi_asset_path = nil
|
10
12
|
src = options[:src] = path_to_image(source)
|
11
13
|
|
12
14
|
begin
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
retina_els = source.split('.')
|
16
|
+
extension = retina_els.last
|
17
|
+
retina_els.slice!(-1)
|
18
|
+
retina_path = "#{retina_els.join('.')}@2x.#{extension}"
|
19
|
+
|
20
|
+
retina_asset_present = if Rails.application.assets.present?
|
21
|
+
Rails.application.assets.find_asset(retina_path).present?
|
22
|
+
else
|
23
|
+
Rails.application.assets_manifest.files.values.any? { |asset| asset['logical_path'] == retina_path }
|
24
|
+
end
|
25
|
+
|
26
|
+
if retina_asset_present
|
27
|
+
hidpi_asset_path = asset_path(retina_path)
|
28
|
+
end
|
21
29
|
rescue
|
22
30
|
end
|
23
|
-
options_default = {
|
31
|
+
options_default = { 'data-hidpi-src' => hidpi_asset_path }
|
24
32
|
|
25
33
|
if lazy = options.delete(:lazy)
|
26
|
-
options[
|
34
|
+
options['data-lazy-load'] = lazy
|
27
35
|
end
|
28
36
|
|
29
37
|
options_default.merge!(options)
|
30
38
|
|
31
|
-
if options_default[:
|
32
|
-
options_default[
|
39
|
+
if options_default[:'data-lazy-load']
|
40
|
+
options_default['data-lowdpi-src'] = options_default.delete(:src)
|
33
41
|
end
|
34
42
|
|
35
43
|
image_tag_without_retina(source, options_default)
|
36
44
|
end
|
37
45
|
|
38
|
-
|
39
46
|
end
|
40
47
|
|
41
48
|
class Engine < ::Rails::Engine
|
@@ -43,7 +50,6 @@ module RetinaTag
|
|
43
50
|
ActionView::Helpers::AssetTagHelper.module_eval do
|
44
51
|
include TagHelper
|
45
52
|
end
|
46
|
-
|
47
53
|
end
|
48
54
|
end
|
49
55
|
end
|
data/lib/retina_tag/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retina_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Estes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.5.1
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: image_tag addon for retina graphics, with cache support.
|