retina_image_tag 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -0
- data/lib/retina_image_tag/railtie.rb +4 -1
- data/lib/retina_image_tag/version.rb +1 -1
- data/lib/retina_image_tag/view_helpers.rb +38 -14
- data/lib/retina_image_tag.rb +9 -1
- data/retina_image_tag.gemspec +3 -0
- metadata +17 -1
data/Rakefile
CHANGED
@@ -1,21 +1,45 @@
|
|
1
|
+
require "image_size"
|
2
|
+
|
1
3
|
module RetinaImageTag
|
2
4
|
module ViewHelpers
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
|
6
|
+
|
7
|
+
def retina_image( pixel_ratio )
|
8
|
+
|
9
|
+
if @options[:size] == '@1x'
|
10
|
+
@options[:size] = ImageSize.path(@rails_image_path+"/"+@file_name+@file_ext).size.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
if File.exist?(@rails_image_path+"/"+@file_name+"@#{pixel_ratio}x"+@file_ext)
|
14
|
+
image_tag(@file_dirname+"/"+@file_name+"@#{pixel_ratio}x"+@file_ext, @options)
|
15
|
+
else
|
16
|
+
@normal_image_tag
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def retina_image_tag(image, options = {})
|
22
|
+
@devicePixelRatio = cookies[:devicePixelRatio]
|
23
|
+
@options = options
|
24
|
+
@rails_image_path = Rails.application.assets.paths.first
|
25
|
+
@file_path = asset_path(image)
|
26
|
+
@file_ext = File.extname(@file_path)
|
27
|
+
@file_name = File.basename(@file_path, @file_ext)
|
28
|
+
@file_dirname = File.dirname(@file_path)
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
@normal_image_tag = image_tag(@file_path, @options)
|
33
|
+
|
34
|
+
case @devicePixelRatio
|
35
|
+
when '2'
|
36
|
+
retina_image '2'
|
37
|
+
when '1.5'
|
38
|
+
retina_image '1.5'
|
39
|
+
else
|
17
40
|
@normal_image_tag
|
18
41
|
end
|
19
42
|
end
|
43
|
+
|
20
44
|
end
|
21
45
|
end
|
data/lib/retina_image_tag.rb
CHANGED
data/retina_image_tag.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retina_image_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: image_size
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: ! 'A high-resolution image is loaded when the retina_image_tag is called
|
31
47
|
from a retina display '
|
32
48
|
email:
|