svg_fallback 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a582cc107bc79283feb136fe633b572ea5418272
4
+ data.tar.gz: 21a66cdf79f35051364210c32afbd18eb18fd531
5
+ SHA512:
6
+ metadata.gz: e5a07b873464bc2fc540688a19eb1d1219d9f6b88f926efdc9a2abb5fe936ef48add4014f365d79f845f60bdb161969c872bc3e4340ae6b44caf76953f10ab6f
7
+ data.tar.gz: 14d888505806ed900f008ad65bd46f13708b207d38c4339686408a94965d52b3138c1a17c498fa05e21d44d9124a6649b9597064b27962a6582ad9e3d1c29ae6
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in image_fallback.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Daniel Lockhart
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,57 @@
1
+ # svg_fallback
2
+
3
+ Using svg files is nice. What's not nice however is having to comply with Internet Explorer 8 and below when using svg files.
4
+
5
+ svg_fallback provides a wrapper to image_tag that detects the user's browser and if it is incompatible with svg files it will fallback to a compatible filetype.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'svg_fallback'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install svg_fallback
22
+
23
+ ## Usage
24
+
25
+ The parameters sent to svg_fallback_tag are identical to the parameters passed to an image_tag. Just leave off the extension from your svg files.
26
+
27
+ When using this tag you will need to provide both an svg and png file of the same filepath to ensure this works. Of course if you are using fallback_extension to set an alternative filetype to fall back to you will need to provide an svg and a file of the given filetype instead of a png.
28
+
29
+ On a browser compatible with svg files:
30
+ ```ruby
31
+ svg_fallback_tag 'assets/images/cat' #=> <img src='/assets/images/cat.svg'>
32
+
33
+ svg_fallback_tag 'assets/images/cat', class: 'cat-image' #=> <img src='/assets/images/cat.svg' class='cat-image'>
34
+
35
+ svg_fallback_tag 'assets/images/cat', id: 'cat-image-1' #=> <img src='/assets/images/cat.svg' id='cat-image-1'>
36
+ ```
37
+
38
+ On a browser that is NOT compatible with svg files:
39
+ ```ruby
40
+ svg_fallback_tag 'assets/images/cat' #=> <img src='assets/images/cat.png'>
41
+
42
+ svg_fallback_tag 'assets/images/cat', fallback_extension: 'jpg' #=> <img src='/assets/images/cat.jpg'>
43
+
44
+ svg_fallback_tag 'assets/images/cat', fallback_extension: 'bmp' #=> <img src='/assets/images/cat.bmp'>
45
+
46
+ svg_fallback_tag 'assets/images/cat', class: 'cat-image' #=> <img src='/assets/images/cat.png' class='cat-image'>
47
+
48
+ svg_fallback_tag 'assets/images/cat', id: 'cat-image-1' #=> <img src='/assets/images/cat.png' id='cat-image-1'>
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/lockyy/svg_fallback/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,21 @@
1
+ require 'browser'
2
+
3
+ module SVGFallbackHelper
4
+
5
+ def svg_fallback_tag path, options = {}
6
+ extension = 'svg'
7
+ if browser.name == 'Internet Explorer' && browser.version >= 8
8
+ if options[:fallback_extension]
9
+ extension = options[:fallback_extension]
10
+ options.delete :fallback_extension
11
+ else
12
+ extension = 'png'
13
+ end
14
+ end
15
+
16
+ path = "#{path}.#{extension}"
17
+
18
+ image_tag path, options
19
+ end
20
+
21
+ end
@@ -0,0 +1,3 @@
1
+ module SVGFallback
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "svg_fallback/version"
2
+ require 'svg_fallback/svgFallbackHelper'
3
+
4
+ module SVGFallback
5
+
6
+ ActionView::Base.send :include, SVGFallbackHelper
7
+
8
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'svg_fallback/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "svg_fallback"
8
+ spec.version = SVGFallback::VERSION
9
+ spec.authors = ["Daniel Lockhart"]
10
+ spec.email = ["daniel@lockyy.com"]
11
+ spec.summary = %q{Adds helper method to rails views for image tags with fallback}
12
+ spec.description = %q{Adds a helper method to rails views that creates an image_tag that falls back from svg when the user is using a non-modern browser.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "browser", "0.8.0"
25
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svg_fallback
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Lockhart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: browser
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.0
55
+ description: Adds a helper method to rails views that creates an image_tag that falls
56
+ back from svg when the user is using a non-modern browser.
57
+ email:
58
+ - daniel@lockyy.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/svg_fallback.rb
69
+ - lib/svg_fallback/svgFallbackHelper.rb
70
+ - lib/svg_fallback/version.rb
71
+ - svg_fallback.gemspec
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.4
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Adds helper method to rails views for image tags with fallback
96
+ test_files: []