retina_tag 1.1.2 → 1.1.3
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/README.md +10 -2
- data/lib/retina_tag/engine.rb +47 -0
- data/lib/retina_tag/version.rb +1 -1
- data/lib/retina_tag.rb +0 -1
- metadata +4 -5
- data/lib/retina_tag/image_tag_helper.rb +0 -42
data/README.md
CHANGED
@@ -37,8 +37,16 @@ Be sure to also specify the base dimensions in your `image_tag` calls:
|
|
37
37
|
|
38
38
|
Awesome right?
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
### Forcing Refresh after loading dynamic content
|
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
|
+
|
43
|
+
### Override Hidpi src attribute
|
44
|
+
In some cases it becomes necessary to override the 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
|
+
|
46
|
+
<%=image_tag(user.photo.url(:medium), "hidpi_src" => user.photo.url(:medium_2x), :height=>75, :width => 75%>
|
47
|
+
|
48
|
+
### Lazy Loading Images
|
49
|
+
If you set `:lazy => true` on an image_tag, the src attribute is moved to a 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.
|
42
50
|
|
43
51
|
|
44
52
|
## Contributing
|
data/lib/retina_tag/engine.rb
CHANGED
@@ -1,4 +1,51 @@
|
|
1
|
+
|
1
2
|
module RetinaTag
|
3
|
+
module TagHelper
|
4
|
+
def self.included(base)
|
5
|
+
base.alias_method_chain :image_tag, :retina
|
6
|
+
end
|
7
|
+
|
8
|
+
def image_tag_with_retina(source,options={})
|
9
|
+
hidpi_asset_path = nil
|
10
|
+
begin
|
11
|
+
retina_els = path.split('.')
|
12
|
+
extension = retina_els.last
|
13
|
+
retina_els.slice!(-1)
|
14
|
+
retina_path = "#{retina_els.join('.')}@2x.#{extension}"
|
15
|
+
|
16
|
+
if !Rails.application.assets.find_asset(retina_path).nil?
|
17
|
+
hidpi_asset_path = asset_path(retina_path)
|
18
|
+
end
|
19
|
+
rescue
|
20
|
+
end
|
21
|
+
options_default = { :hidpi_src => hidpi_asset_path }
|
22
|
+
|
23
|
+
if lazy = options.delete(:lazy)
|
24
|
+
options["data-lazy-load"] = lazy
|
25
|
+
end
|
26
|
+
|
27
|
+
options_default.merge!(options)
|
28
|
+
|
29
|
+
image_tag_without_retina(source,options_default)
|
30
|
+
|
31
|
+
if options_default[:"data-lazy-load"]
|
32
|
+
puts "Lazy load detected"
|
33
|
+
options_default[:lowdpi_src] = options_default.delete(:src)
|
34
|
+
end
|
35
|
+
puts "Using custom image Tag!"
|
36
|
+
puts options_default
|
37
|
+
tag("img", options_default)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
|
2
43
|
class Engine < ::Rails::Engine
|
44
|
+
initializer :retina_tag_image_tag do
|
45
|
+
ActionView::Helpers::AssetTagHelper.module_eval do
|
46
|
+
include TagHelper
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
3
50
|
end
|
4
51
|
end
|
data/lib/retina_tag/version.rb
CHANGED
data/lib/retina_tag.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retina_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
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: 2012-12-
|
12
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -59,7 +59,6 @@ files:
|
|
59
59
|
- app/assets/javascripts/retina_tag.js
|
60
60
|
- lib/retina_tag.rb
|
61
61
|
- lib/retina_tag/engine.rb
|
62
|
-
- lib/retina_tag/image_tag_helper.rb
|
63
62
|
- lib/retina_tag/version.rb
|
64
63
|
- retina_tag.gemspec
|
65
64
|
homepage: http://github.com/davydotcom/retina_tag
|
@@ -76,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
75
|
version: '0'
|
77
76
|
segments:
|
78
77
|
- 0
|
79
|
-
hash: -
|
78
|
+
hash: -2618567540484132469
|
80
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
80
|
none: false
|
82
81
|
requirements:
|
@@ -85,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
84
|
version: '0'
|
86
85
|
segments:
|
87
86
|
- 0
|
88
|
-
hash: -
|
87
|
+
hash: -2618567540484132469
|
89
88
|
requirements: []
|
90
89
|
rubyforge_project:
|
91
90
|
rubygems_version: 1.8.24
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module ActionView
|
2
|
-
module Helpers
|
3
|
-
module AssetTagHelper
|
4
|
-
def hidpi_asset_path(path)
|
5
|
-
begin
|
6
|
-
retina_els = path.split('.')
|
7
|
-
extension = retina_els.last
|
8
|
-
retina_els.slice!(-1)
|
9
|
-
retina_path = "#{retina_els.join('.')}@2x.#{extension}"
|
10
|
-
|
11
|
-
if !Rails.application.assets.find_asset(retina_path).nil?
|
12
|
-
asset_path(retina_path)
|
13
|
-
end
|
14
|
-
rescue
|
15
|
-
nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def image_tag_with_retina(source,options={})
|
20
|
-
options_default = { :hidpi_src => hidpi_asset_path(source) }
|
21
|
-
|
22
|
-
if lazy = options.delete(:lazy)
|
23
|
-
options["data-lazy-load"] = lazy
|
24
|
-
end
|
25
|
-
|
26
|
-
options_default.merge!(options)
|
27
|
-
|
28
|
-
image_tag_without_retina(source,options_default)
|
29
|
-
|
30
|
-
if options_default[:"data-lazy-load"]
|
31
|
-
puts "Lazy load detected"
|
32
|
-
options_default[:lowdpi_src] = options_default.delete(:src)
|
33
|
-
end
|
34
|
-
puts "Using custom image Tag!"
|
35
|
-
puts options_default
|
36
|
-
tag("img", options_default)
|
37
|
-
end
|
38
|
-
|
39
|
-
alias_method_chain :image_tag, :retina
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|