clear_eyes 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rvmrc +6 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/clear_eyes.gemspec +19 -0
- data/lib/clear_eyes.rb +9 -0
- data/lib/clear_eyes/railtie.rb +12 -0
- data/lib/clear_eyes/tasks/clear_eyes.rake +16 -0
- data/lib/clear_eyes/version.rb +3 -0
- data/lib/clear_eyes/view_helpers.rb +27 -0
- data/vendor/assets/javascripts/clear_eyes.js +4 -0
- metadata +92 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Brian Dear
|
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,36 @@
|
|
1
|
+
# Clear Eyes
|
2
|
+
|
3
|
+
This makes is super easy to handle Retina images in your Rails 3.1+ apps. It adds r_image_tag that can be used in place of the existing image_tag and it'll automatically serve up Retina images to devices that can handle the resolution and normal images otherwise.
|
4
|
+
|
5
|
+
## How to Use it
|
6
|
+
|
7
|
+
In your Gemfile:
|
8
|
+
|
9
|
+
gem 'clear_eyes'
|
10
|
+
|
11
|
+
In your application.js:
|
12
|
+
|
13
|
+
//= require clear_eyes
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
= r_image_tag('my_awesome_image@2x.jpg')
|
17
|
+
|
18
|
+
This assumes that ```my_awesome_image@2x.jpg``` is sized properly for retina images. Remember, Retina images are double the pixel density of standard images.
|
19
|
+
|
20
|
+
Now that you have Retina-ready images and a way to serve them up in your views, what about non-retina machines?
|
21
|
+
|
22
|
+
There's a rake for that! You only need to create one image (the Retina one).
|
23
|
+
|
24
|
+
Running this: ```rake clear_eyes:convert``` will convert create non-retina images from the images in app/assets/images. It's even take care of the file names! Pretty cool right? So, ```my_awesome_image@2x.jpg``` will automatically be copied, downsized and named ```my_awesome_image.jpg```.
|
25
|
+
|
26
|
+
You can thank me later.
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Please contribute! The community is much smarter than me and your help would be appreciated!
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/clear_eyes.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/clear_eyes/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Brian Dear"]
|
6
|
+
gem.email = ["superacidjax@me.com"]
|
7
|
+
gem.description = %q{Automatic Retina Image Handling}
|
8
|
+
gem.summary = %q{This ensures that high resolution images are served for Retina devices and standard resolution images are served for everyone else.}
|
9
|
+
gem.homepage = "https://github.com/superacidjax/clear_eyes"
|
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 = "clear_eyes"
|
15
|
+
gem.require_paths = ["lib", "vendor"]
|
16
|
+
gem.version = ClearEyes::VERSION
|
17
|
+
gem.add_dependency "railties", "~> 3.1"
|
18
|
+
gem.add_dependency "rmagick", "~> 2.13.1"
|
19
|
+
end
|
data/lib/clear_eyes.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'RMagick'
|
2
|
+
|
3
|
+
namespace :clear_eyes do
|
4
|
+
desc 'convert @2x images to normal images'
|
5
|
+
task :convert do
|
6
|
+
r_images = Dir['app/assets/images/**/*@2x*']
|
7
|
+
|
8
|
+
r_images.each do |r_image|
|
9
|
+
img = Magick::ImageList.new(r_image)
|
10
|
+
x1 = img.resize(0.5)
|
11
|
+
x1.write r_image.delete "@2x"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ClearEyes
|
2
|
+
module ViewHelpers
|
3
|
+
def self.included(base)
|
4
|
+
base.send(:attr_accessor, :image, :options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def r_image( pixel_ratio )
|
8
|
+
insert_on = -File.extname(self.image).size-1
|
9
|
+
image_tag(self.image.insert(insert_on, "@#{pixel_ratio}x"), self.options)
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def r_image_tag(image, options = {})
|
14
|
+
self.options = options
|
15
|
+
self.image = image
|
16
|
+
case cookies[:devicePixelRatio]
|
17
|
+
when '2'
|
18
|
+
r_image 2
|
19
|
+
when '1.5'
|
20
|
+
r_image 2
|
21
|
+
else
|
22
|
+
image_tag(self.image, self.options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clear_eyes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Dear
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
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: '3.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rmagick
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.13.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: 2.13.1
|
46
|
+
description: Automatic Retina Image Handling
|
47
|
+
email:
|
48
|
+
- superacidjax@me.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rvmrc
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- clear_eyes.gemspec
|
60
|
+
- lib/clear_eyes.rb
|
61
|
+
- lib/clear_eyes/railtie.rb
|
62
|
+
- lib/clear_eyes/tasks/clear_eyes.rake
|
63
|
+
- lib/clear_eyes/version.rb
|
64
|
+
- lib/clear_eyes/view_helpers.rb
|
65
|
+
- vendor/assets/javascripts/clear_eyes.js
|
66
|
+
homepage: https://github.com/superacidjax/clear_eyes
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
- vendor
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.24
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: This ensures that high resolution images are served for Retina devices and
|
91
|
+
standard resolution images are served for everyone else.
|
92
|
+
test_files: []
|