sprockets-svgo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69242204acbe5bd5727ac8229e0b977e46d3de50
4
+ data.tar.gz: b624f48bcdcc3cdc4122d099a2ac03cf82fbf0dd
5
+ SHA512:
6
+ metadata.gz: c63e7a76b71ead2e6a8b40acd26126e3c4a274422ba2afb9ff04b183d09c1bc3dabc014dcc5008adb2f8536d508688642519d63f6b7c26fcc2ff2e0fcb7d57a5
7
+ data.tar.gz: 8f72e6e5cce6d5d5ac44db7d6fe2109053e9cab600027c7a7e3a019ca77eea2db67eba7dc3427602f3379253ad37893e0a472caa4280c0a9015c22f837048c92
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sprockets-svgo.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Javan Makhmali
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Sprockets SVGO
2
+
3
+ [Sprockets](https://github.com/rails/sprockets) helpers for optimizing SVG graphics with [svgo](https://github.com/svg/svgo).
4
+
5
+ ## Installing
6
+
7
+ Install svgo
8
+ ```sh
9
+ # Globally
10
+ $ npm install -g svgo
11
+ # Or as a dependency
12
+ $ npm install -s svgo
13
+ ```
14
+ Bundle
15
+ ```ruby
16
+ gem 'sprockets', '>= 3.0.0'
17
+ gem 'sprockets-svgo'
18
+ ```
19
+
20
+ ## Using
21
+
22
+ In a .css, .scss, or .sass file:
23
+ ```css
24
+ /* icons.css */
25
+ .bold {
26
+ background-image: svgo-data-uri("images/bold.svg");
27
+ }
28
+ ```
29
+ In an .erb file:
30
+ ```scss
31
+ /* icons.css.erb */
32
+ .bold {
33
+ background-image: url(<%= svgo_asset_data_uri("images/bold.svg") %>);
34
+ }
35
+ ```
36
+
37
+ ---
38
+
39
+ Licensed under the [MIT License](LICENSE.txt)
40
+
41
+ © 2016 Javan Makhmali
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sprockets/svgo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require "sprockets"
2
+ require "sprockets/svgo/version"
3
+ require "sprockets/svgo/command"
4
+ require "sprockets/svgo/context_extensions"
5
+ require "sprockets/svgo/sass_functions"
6
+
7
+ module Sprockets::SVGO
8
+ def self.uri(options = {})
9
+ options = options.merge(datauri: "enc", output: "-")
10
+ Command.new(options).execute
11
+ end
12
+ end
@@ -0,0 +1,93 @@
1
+ # $ svgo --help
2
+ # Nodejs-based tool for optimizing SVG vector graphics files
3
+ #
4
+ # Usage:
5
+ # svgo [OPTIONS] [ARGS]
6
+ #
7
+ # Options:
8
+ # -h, --help : Help
9
+ # -v, --version : Version
10
+ # -i INPUT, --input=INPUT : Input file, "-" for STDIN
11
+ # -s STRING, --string=STRING : Input SVG data string
12
+ # -f FOLDER, --folder=FOLDER : Input folder, optimize and rewrite all *.svg files
13
+ # -o OUTPUT, --output=OUTPUT : Output file or folder (by default the same as the input), "-" for STDOUT
14
+ # -p PRECISION, --precision=PRECISION : Set number of digits in the fractional part, overrides plugins params
15
+ # --config=CONFIG : Config file to extend or replace default
16
+ # --disable=DISABLE : Disable plugin by name
17
+ # --enable=ENABLE : Enable plugin by name
18
+ # --datauri=DATAURI : Output as Data URI string (base64, URI encoded or unencoded)
19
+ # --multipass : Enable multipass
20
+ # --pretty : Make SVG pretty printed
21
+ # -q, --quiet : Only output error messages, not regular status messages
22
+ # --show-plugins : Show available plugins and exit
23
+ #
24
+ # Arguments:
25
+ # INPUT : Alias to --input
26
+ # OUTPUT : Alias to --output
27
+
28
+ class Sprockets::SVGO::Command
29
+ DEFAULTS = {
30
+ multipass: true,
31
+ enable: "removeViewBox"
32
+ }
33
+
34
+ attr_reader :options
35
+
36
+ def initialize(options = {})
37
+ @options = options.reverse_merge(DEFAULTS)
38
+ end
39
+
40
+ def execute
41
+ command = [svgo_path]
42
+ command << "--input=#{options[:filename]}"
43
+
44
+ if options[:output]
45
+ command << "--output #{options[:output]}"
46
+ end
47
+
48
+ if options[:datauri]
49
+ command << "--datauri=#{options[:datauri]}"
50
+ end
51
+
52
+ if options[:disable]
53
+ options[:disable].to_s.split(" ").each do |plugin|
54
+ command << "--disable=#{plugin}"
55
+ end
56
+ end
57
+
58
+ if options[:enable]
59
+ options[:enable].to_s.split(" ").each do |plugin|
60
+ command << "--enable=#{plugin}"
61
+ end
62
+ end
63
+
64
+ if options[:multipass]
65
+ command << "--multipass"
66
+ end
67
+
68
+ if options[:precision]
69
+ command << "--precision=#{options[:precision]}"
70
+ end
71
+
72
+ `#{command.join(" ")}`.chomp
73
+ end
74
+
75
+ private
76
+ LOCAL_SVGO_PATH = "node_modules/.bin/svgo"
77
+
78
+ def svgo_path
79
+ @svgo_path ||= local_svgo_path || global_svgo_path || svgo_not_installed
80
+ end
81
+
82
+ def local_svgo_path
83
+ LOCAL_SVGO_PATH if File.exists?(LOCAL_SVGO_PATH)
84
+ end
85
+
86
+ def global_svgo_path
87
+ `which svgo`.chomp.presence
88
+ end
89
+
90
+ def svgo_not_installed
91
+ raise "svgo not installed, run `npm install svgo`"
92
+ end
93
+ end
@@ -0,0 +1,12 @@
1
+ module Sprockets
2
+ class Context
3
+ def svgo_asset_data_uri(path, options = {})
4
+ asset = depend_on_asset(path)
5
+ options = options.merge(filename: asset.filename)
6
+
7
+ environment.cache.fetch([:svgo, options.to_s]) do
8
+ SVGO.uri(options)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Sprockets
2
+ module SassProcessor::Functions
3
+ def svgo_data_uri(path, options = {})
4
+ url = sprockets_context.svgo_asset_data_uri(path.value, options.symbolize_keys)
5
+ Autoload::Sass::Script::String.new("url(" + url + ")")
6
+ end
7
+
8
+ Autoload::Sass::Script::Functions.declare :svgo_data_uri, [:path], var_kwargs: true
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Sprockets
2
+ module SVGO
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sprockets/svgo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sprockets-svgo"
8
+ spec.version = Sprockets::SVGO::VERSION
9
+ spec.authors = ["Javan Makhmali"]
10
+ spec.email = ["javan@javan.us"]
11
+
12
+ spec.summary = %q{Sprockets SVGO}
13
+ spec.description = %q{Sprockets helpers for optimizing SVG graphics with svgo}
14
+ spec.homepage = "https://github.com/javan/sprockets-svgo"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-svgo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Javan Makhmali
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-28 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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
+ description: Sprockets helpers for optimizing SVG graphics with svgo
42
+ email:
43
+ - javan@javan.us
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/sprockets/svgo.rb
56
+ - lib/sprockets/svgo/command.rb
57
+ - lib/sprockets/svgo/context_extensions.rb
58
+ - lib/sprockets/svgo/sass_functions.rb
59
+ - lib/sprockets/svgo/version.rb
60
+ - sprockets-svgo.gemspec
61
+ homepage: https://github.com/javan/sprockets-svgo
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.6.6
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Sprockets SVGO
85
+ test_files: []