esvg 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b0c206a64c04632e938319e8691c9de670e3fa6
4
- data.tar.gz: b60c62f573cee170960725e72ca8a557bef8aa74
3
+ metadata.gz: ce03f468b00edef2311bb762573567e6be4dc210
4
+ data.tar.gz: b3e999343131df4bf21abaa1f5e69625c09a7bd9
5
5
  SHA512:
6
- metadata.gz: 66ad8fb1565b46cb83b73c45a7265f5a4719ff4c7db7a1cc0a9f7fab8a8cbb17c8edfe3260868c2d63c2ca541a2f29e7b1133e81d7fdab7341998f335138cab8
7
- data.tar.gz: 0f3eb9c16d85a346d47125e828e2d015a22f715bef07de6464c308ce8a5f397815e8c067b3d0ce2cae2cf51e17feabbeb63e7304547899981186be3f249325b9
6
+ metadata.gz: 234e339099f30cb2390e64d2da36b035ab9865b6d6b3667f99a56a380b2236d37171d1b9070aa6c30197c662a0ca2f7923a98dc2be5ec93313e8fe741601ea09
7
+ data.tar.gz: 0469ebe8dd5d341709e1887a5df5dc8185f6957aa3a55238a15a781af7e904c93ca8da80c322becaa8dad0e7e3508ee5fd8068751297d150e05fdff981616aba
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /test/build
11
+ /test/optimized
@@ -2,4 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1.2
4
4
  before_install: gem install bundler -v 1.10.3
5
+ before_script: npm install svgo -g
5
6
  script: bundle exec clash
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 2.0.2 (2015-09-23)
4
+ - Fix: Caching on just about everything.
5
+
3
6
  ### 2.0.2 (2015-07-10)
4
7
  - Fix: Caching on just about everything.
5
8
 
data/README.md CHANGED
@@ -28,7 +28,7 @@ Or install it yourself as:
28
28
 
29
29
  ## Usage: Rails
30
30
 
31
- First, add SVG files to your `app/assets/svg_icons/` directory.
31
+ First, add SVG files to your `app/assets/esvg/` directory.
32
32
 
33
33
  ### Inject SVG symbols
34
34
 
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "svg_optimizer", "~> 0.0.2"
22
-
23
21
  spec.add_development_dependency "bundler", "~> 1.10"
24
22
  spec.add_development_dependency "rake", "~> 10.0"
25
23
  spec.add_development_dependency "pry-byebug"
@@ -0,0 +1,18 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
4
+
5
+ require 'optparse'
6
+ require 'esvg'
7
+
8
+ options = {}
9
+
10
+ OptionParser.new do |opts|
11
+ opts.on("-c", "--config PATH", String, "Path to a config file (default: esvg.yml, config/esvg.yml)") do |path|
12
+ options[:config_file] = path
13
+ end
14
+ end.parse!
15
+
16
+ options[:path] = ARGV.shift
17
+
18
+ esvg = Esvg::SVG.new(options).optimize
@@ -1,4 +1,3 @@
1
- require "svg_optimizer"
2
1
  require "fileutils"
3
2
 
4
3
  require "esvg/version"
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module Esvg
2
4
  class SVG
3
5
  attr_accessor :files
@@ -6,6 +8,7 @@ module Esvg
6
8
  path: Dir.pwd,
7
9
  base_class: 'svg-icon',
8
10
  namespace: 'icon',
11
+ optimize: false,
9
12
  namespace_before: true,
10
13
  font_size: '1em',
11
14
  output_path: Dir.pwd,
@@ -39,6 +42,12 @@ module Esvg
39
42
  @mtime != mtime
40
43
  end
41
44
 
45
+ def svgo?
46
+ @svgo ||= begin
47
+ !(`npm ls -g svgo`.match(/empty/) && `npm ls svgo`.match(/emtpy/))
48
+ end
49
+ end
50
+
42
51
  def cache_name(input, options)
43
52
  input + options.flatten.join('-')
44
53
  end
@@ -52,8 +61,27 @@ module Esvg
52
61
  @mtime = File.mtime(found.last)
53
62
 
54
63
  found.each do |f|
55
- svg = File.read(f)
56
- @files[File.basename(f, ".*")] = SvgOptimizer.optimize(svg)
64
+ @files[File.basename(f, ".*")] = read(f)
65
+ end
66
+ end
67
+
68
+ def read(file)
69
+ if config[:optimize] && svgo?
70
+ # Compress files outputting to $STDOUT
71
+ `svgo #{file} -o -`
72
+ else
73
+ File.read(file)
74
+ end
75
+ end
76
+
77
+ # Optiize all svg source files
78
+ #
79
+ def optimize
80
+ if svgo?
81
+ puts "Optimzing #{config[:path]}"
82
+ system "svgo -f #{config[:path]}"
83
+ else
84
+ abort 'To optimize files, please install svgo; `npm install svgo -g`'
57
85
  end
58
86
  end
59
87
 
@@ -185,13 +213,13 @@ document.addEventListener("DOMContentLoaded", function(event) { esvg.embed() })
185
213
  @config ||= begin
186
214
  paths = [options[:config_file], 'config/esvg.yml', 'esvg.yml'].compact
187
215
 
188
- config = if path = paths.select{ |p| File.exist?(p)}.first
189
- CONFIG.merge(symbolize_keys(YAML.load(File.read(path) || {})))
190
- else
191
- CONFIG
216
+ config = CONFIG
217
+ config.merge!(CONFIG_RAILS) if Esvg.rails?
218
+
219
+ if path = paths.select{ |p| File.exist?(p)}.first
220
+ config.merge!(symbolize_keys(YAML.load(File.read(path) || {})))
192
221
  end
193
222
 
194
- config.merge!(CONFIG_RAILS) if Esvg.rails?
195
223
  config.merge!(options)
196
224
 
197
225
  config[:js_path] ||= File.join(config[:output_path], 'esvg.js')
@@ -1,3 +1,3 @@
1
1
  module Esvg
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esvg
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: svg_optimizer
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.0.2
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.0.2
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -85,6 +71,7 @@ email:
85
71
  - brandon@imathis.com
86
72
  executables:
87
73
  - esvg
74
+ - esvgo
88
75
  extensions: []
89
76
  extra_rdoc_files: []
90
77
  files:
@@ -100,6 +87,7 @@ files:
100
87
  - bin/setup
101
88
  - esvg.gemspec
102
89
  - exe/esvg
90
+ - exe/esvgo
103
91
  - lib/esvg.rb
104
92
  - lib/esvg/helpers.rb
105
93
  - lib/esvg/railties.rb
@@ -125,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
113
  version: '0'
126
114
  requirements: []
127
115
  rubyforge_project:
128
- rubygems_version: 2.4.7
116
+ rubygems_version: 2.4.5
129
117
  signing_key:
130
118
  specification_version: 4
131
119
  summary: Embed svgs in HTML or CSS