sass_inline_svg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjRmZmY2MmM3NDE1MWQ4ZDYyMTQ0OWY2YjQxNTljYjQ5OTlhZTg5Ng==
5
+ data.tar.gz: !binary |-
6
+ N2NmMGMyOWUwNmQzZDYwNmIwYjE4MGIxNjZlNjg1NjkzMTNkMzBlNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YzY0Mjk4OTgxMzUyZjBlZDc2NDBjMTk5MTVlY2U3NzE0ZGQzZGNjMmNiNjFk
10
+ MDgzMTk3ODI1MDFkYjYxNDFlNDNmODdlMzUyYzhmZGI0YTMyODg3MmUwNDI1
11
+ NGY2MDFmY2FmYjYzNWRlYTI2OWJkOWVkMTY2ODZkMjNkZGM1YTY=
12
+ data.tar.gz: !binary |-
13
+ OWRkOTFjZTI1Yjk0MGFlMTM0NjQ2NDBmYWZiZjVhZWY3OTNiNTMyMmRmNzMx
14
+ NDNhZGIxYzk2MmE5ZTkxOGZhNTJjMTc2NzA4ZmU1MWQyMzYwN2ZmNGM0YWQ1
15
+ MWZlNjA1MDBkOTQwOWNmZmQ3ZDQ1NjYzYmRmZmRlM2Y1YTllOWY=
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,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Franz Heidl
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,49 @@
1
+ # Sass-Inline-Svg
2
+
3
+ Inline url-encoded SVG with Sass. Optional variable string replacement included!
4
+
5
+
6
+ ## Installation
7
+
8
+ gem install sass_inline_svg
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'sass_inline_svg'
13
+
14
+
15
+
16
+ ## Usage
17
+
18
+ Sass-inline-svg adds a `inline-svg` function you can use with Sass. It url-encodes the contents of the specified file and inlines it in your CSS.
19
+
20
+ ###Basic
21
+
22
+ .my-thing {
23
+ background-image: inline-svg('my-file.svg');
24
+ }
25
+
26
+ ###Replace Variable Strings
27
+
28
+ Replacing variable strings in SVG when inlining them with Sass makes sense e.g. if you need multiple variants of the same graphic with different fill colors.
29
+
30
+ With Sass-Inline-Svg you only need one source svg file with a variable string for `fill`:
31
+
32
+
33
+ <polygon fill="fillcolor" points="29.43 25.19 20.24 16 29.43 6.81 25.19 2.57 16 11.76 6.81 2.57 2.57 6.81 11.76 16 2.57 25.19 6.81 29.44 16 20.24 25.19 29.44 "/>
34
+
35
+
36
+ The variants needed can be created during inlinig with Sass. Pass a Sass map of replacements as a second parameter:
37
+
38
+ .my-thing {
39
+ background-image: inline-svg('my-file.svg', ( fillcolor: '#fff' ));
40
+ }
41
+
42
+ This will replace all occurences of `fillcolor` in your SVG with `#fff`.
43
+
44
+ __Note:__ If you use `$`- or `@`-prefixed variable names in your SVG, you'll have to quote the keys in your raplement Sass map:
45
+
46
+ .my-thing {
47
+ background-image: inline-svg('my-file.svg', ( '$fillcolor': '#fff' ));
48
+ }
49
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/close-blk.svg ADDED
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Ebene_1" x="0" y="0" width="32" height="32" viewBox="0 0 32 32" enable-background="new 0 0 32 32" xml:space="preserve">
2
+ <polygon fill="#000" points="29.43 25.19 20.24 16 29.43 6.81 25.19 2.57 16 11.76 6.81 2.57 2.57 6.81 11.76 16 2.57 25.19 6.81 29.44 16 20.24 25.19 29.44 "/>
3
+ </svg>
data/close-rd.svg ADDED
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Ebene_1" x="0" y="0" width="32" height="32" viewBox="0 0 32 32" enable-background="new 0 0 32 32" xml:space="preserve">
2
+ <polygon fill="#FF0000" points="29.43 25.19 20.24 16 29.43 6.81 25.19 2.57 16 11.76 6.81 2.57 2.57 6.81 11.76 16 2.57 25.19 6.81 29.44 16 20.24 25.19 29.44 "/>
3
+ </svg>
4
+
@@ -0,0 +1,42 @@
1
+ require "sass_inline_svg/version"
2
+ require "sass"
3
+ require "cgi"
4
+
5
+ module Sass::Script::Functions
6
+
7
+ def svg_inline(path, repl = nil)
8
+ assert_type path, :String
9
+
10
+ svg = _readFile(path.value).strip
11
+
12
+ if repl && repl.respond_to?('to_h')
13
+ repl = repl.to_h
14
+ svg = svg.to_s
15
+
16
+ repl.each_pair do |k, v|
17
+
18
+ if svg.include? k.value
19
+ svg.gsub!(k.value, v.value)
20
+ end
21
+ end
22
+ end
23
+
24
+ encoded = CGI::escape(svg).gsub("+", "%20")
25
+ encoded_url = "url('data:image/svg+xml;charset=utf-8," + encoded + "')"
26
+ Sass::Script::String.new(encoded_url)
27
+ end
28
+
29
+
30
+ private
31
+
32
+ def _readFile(path)
33
+ if File.readable?(path)
34
+ File.open(path, 'rb') do |f|
35
+ f.read
36
+ end
37
+ else
38
+ raise Sass::SyntaxError, "File not found or cannot be read: #{path}"
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,3 @@
1
+ module SassInlineSvg
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sass_inline_svg/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sass_inline_svg"
8
+ spec.version = SassInlineSvg::VERSION
9
+ spec.authors = ["Franz Heidl"]
10
+ spec.email = ["franz@franzheidl.de"]
11
+ spec.summary = %q{Inline url-encoded SVG with Sass}
12
+ spec.description = %q{Inline url-encoded SVG with Sass. Optional variable string replacement included!}
13
+ spec.homepage = "https://github.com/franzheidl/sass-inline-svg"
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.5"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sass_inline_svg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Franz Heidl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-06 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Inline url-encoded SVG with Sass. Optional variable string replacement
42
+ included!
43
+ email:
44
+ - franz@franzheidl.de
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - close-blk.svg
55
+ - close-rd.svg
56
+ - lib/sass_inline_svg.rb
57
+ - lib/sass_inline_svg/version.rb
58
+ - sass_inline_svg.gemspec
59
+ homepage: https://github.com/franzheidl/sass-inline-svg
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.0.rc.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Inline url-encoded SVG with Sass
83
+ test_files: []