retina_image_tag 0.0.1 → 0.0.2

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/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new('spec')
@@ -1,9 +1,12 @@
1
1
  require 'retina_image_tag/view_helpers'
2
2
 
3
+
3
4
  module RetinaImageTag
4
5
  class Railtie < Rails::Engine
6
+
5
7
  initializer "retina_image_tag.view_helpers" do |app|
6
8
  ActionView::Base.send :include, ViewHelpers
7
9
  end
8
- end
10
+
11
+ end
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module RetinaImageTag
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,21 +1,45 @@
1
+ require "image_size"
2
+
1
3
  module RetinaImageTag
2
4
  module ViewHelpers
3
- def retina_image_tag(image)
4
- @file_path = asset_path(image)
5
- @file_ext = File.extname(@file_path)
6
- @file_name = File.basename(@file_path, @file_ext)
7
- @file_dirname = File.dirname(@file_path)
8
-
9
- @devicePixelRatio = cookies[:devicePixelRatio]
10
-
11
- @normal_image_tag = image_tag(@file_path)
12
- @retina_image_path = @file_dirname+"/"+@file_name+"@2x"+@file_ext
13
-
14
- if @devicePixelRatio != '1'
15
- image_tag(@retina_image_path)
16
- else
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
@@ -1 +1,9 @@
1
- require 'retina_image_tag/railtie' if defined? Rails
1
+ module RetinaImageTag
2
+ mattr_accessor :app_root
3
+
4
+ def self.setup
5
+ yield self
6
+ end
7
+ end
8
+
9
+ require "retina_image_tag/railtie"
@@ -14,6 +14,9 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "retina_image_tag"
15
15
  gem.require_paths = ["lib","vendor"]
16
16
  gem.version = RetinaImageTag::VERSION
17
+
17
18
  gem.add_dependency "railties", "~> 3.1"
19
+ gem.add_dependency "image_size"
20
+
18
21
 
19
22
  end
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.1
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: