retina_tag 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in retina_tag.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 David Estes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # RetinaTag
2
+
3
+ Interested in making your web-sites retina compatible? Rails asset pipeline makes this a pain with retina image_tags, especially when precompiling assets. RetinaTag resolves this by extending image_tag to create a hidpi_src attribute with the retina image path if it exists.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'retina_tag'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install retina_tag
18
+
19
+
20
+ ## Usage
21
+
22
+ Add retina_tag.js to your application.js file after including jquery
23
+
24
+ //require retina_tag
25
+
26
+ Add double pixel resolution images in your assets directory with the @2x modifier
27
+
28
+ logo.png
29
+ logo@2x.png
30
+
31
+ Be sure to also specify the base dimensions in your image_tag calls
32
+
33
+ <%=image_tag('logo.png',:height=>50)%>
34
+
35
+ Awesome right?
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module RetinaTag
2
+ class Engine < ::Rails::Engine
3
+
4
+ end
5
+ end
@@ -0,0 +1,32 @@
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
+ return nil if Rails.application.assets.find_asset(retina_path).nil?
12
+ asset_path = asset_path(retina_path)
13
+ return asset_path
14
+ rescue
15
+ puts " WOAH"
16
+ return nil
17
+ end
18
+ end
19
+ def image_tag_with_retina(source,options={})
20
+
21
+ options_default = {:hidpi_src=>hidpi_asset_path(source)}
22
+
23
+ return image_tag_without_retina(source,options_default.merge(options))
24
+ end
25
+
26
+
27
+
28
+ alias_method_chain :image_tag, :retina
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module RetinaTag
2
+ VERSION = "1.0.0"
3
+ end
data/lib/retina_tag.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "retina_tag/version"
2
+ require 'retina_tag/image_tag_helper'
3
+ module RetinaTag
4
+ # Your code goes here...
5
+ end
6
+
7
+ require "retina_tag/engine"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/retina_tag/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["David Estes"]
6
+ gem.email = ["destes@redwindsw.com"]
7
+ gem.description = "This gem overrides image_tag to support retina resolution images using asset pipeline"
8
+ gem.summary = "image_tag addon for retina graphics, with cache support."
9
+ gem.homepage = "http://github.com/davydotcom/retina_tag"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "retina_tag"
15
+ gem.require_paths = ["lib","vendor"]
16
+ gem.version = RetinaTag::VERSION
17
+
18
+ gem.add_dependency 'jquery-rails'
19
+ gem.add_dependency "railties", "~> 3.1"
20
+
21
+ end
@@ -0,0 +1,34 @@
1
+ function highdpi_init() {
2
+ if(window.devicePixelRatio > 1)
3
+ {
4
+
5
+ var els = jQuery("img").get();
6
+ for(var i = 0; i < els.length; i++) {
7
+ var hiDpiSrc = $(els[i]).attr('hidpi_src');
8
+ var src = els[i].src;
9
+
10
+ if(hiDpiSrc)
11
+ {
12
+ src = hiDpiSrc;
13
+ }
14
+ else
15
+ {
16
+ var path_segments = src.split('.');
17
+ var path_without_extension = path_segments.slice(0, (path_segments.length - 1)).join(".");
18
+ var extension = path_segments[path_segments.length - 1];
19
+ src = path_without_extension + "@2x." + extension;
20
+ }
21
+
22
+ if(hiDpiSrc) {
23
+ els[i].src = hiDpiSrc;
24
+ }
25
+
26
+
27
+
28
+ }
29
+ }
30
+ }
31
+
32
+ $(document).ready(function() {
33
+ highdpi_init();
34
+ });
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: retina_tag
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Estes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jquery-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: railties
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.1'
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: '3.1'
46
+ description: This gem overrides image_tag to support retina resolution images using
47
+ asset pipeline
48
+ email:
49
+ - destes@redwindsw.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/retina_tag.rb
60
+ - lib/retina_tag/engine.rb
61
+ - lib/retina_tag/image_tag_helper.rb
62
+ - lib/retina_tag/version.rb
63
+ - retina_tag.gemspec
64
+ - vendor/assets/javascripts/retina_tag.js
65
+ homepage: http://github.com/davydotcom/retina_tag
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ - vendor
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 3099451232325954057
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: 3099451232325954057
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.24
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: image_tag addon for retina graphics, with cache support.
96
+ test_files: []