retina_tag 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28acff04b272c96deb4b0754d8070a9cb196adc0
4
- data.tar.gz: c1e08ba947ae3b7fc053b853a8238a63ee4c8652
3
+ metadata.gz: be758b14dfbee1b2a1214ea8001f00dba536dd85
4
+ data.tar.gz: f66a6ac77692eb0dffaf7e5e3e2846e2b1710619
5
5
  SHA512:
6
- metadata.gz: 6b880d2efe14c00ff966500eab438a2e6b3395ce9080f6286cdc19f951974892b7eed612658d7eb2e97a386d072a7381a6deb4c36500fd59556b9a79cc775797
7
- data.tar.gz: 5494f7869f91f985e03749636d2935651f3b9378cd29c952749561cd8d5342c382ff9ed8c150b4172e5944b97d9fc3ad64c3b5dbf39d5ba4a125b1e166ae7198
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 `hidpi_src`
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 hidpi_src attribute and skip asset pipeline. A good example of this might be to load a users profile picture which is stored elsewhere.
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), "hidpi_src" => user.photo.url(:medium_2x), :height=>75, :width => 75%>
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 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.
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
@@ -1,41 +1,48 @@
1
-
2
1
  module RetinaTag
3
2
  module TagHelper
4
3
  def self.included(base)
5
- base.alias_method_chain :image_tag, :retina
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
- retina_els = source.split('.')
14
- extension = retina_els.last
15
- retina_els.slice!(-1)
16
- retina_path = "#{retina_els.join('.')}@2x.#{extension}"
17
-
18
- if !Rails.application.assets.find_asset(retina_path).nil?
19
- hidpi_asset_path = asset_path(retina_path)
20
- end
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 = { "data-hidpi-src" => hidpi_asset_path }
31
+ options_default = { 'data-hidpi-src' => hidpi_asset_path }
24
32
 
25
33
  if lazy = options.delete(:lazy)
26
- options["data-lazy-load"] = lazy
34
+ options['data-lazy-load'] = lazy
27
35
  end
28
36
 
29
37
  options_default.merge!(options)
30
38
 
31
- if options_default[:"data-lazy-load"]
32
- options_default["data-lowdpi-src"] = options_default.delete(:src)
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
@@ -1,3 +1,3 @@
1
1
  module RetinaTag
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.0"
3
3
  end
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.3.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: 2014-04-28 00:00:00.000000000 Z
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.2.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.