esvg 4.6.2 → 4.6.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +1 -1
- data/exe/esvg +1 -0
- data/lib/esvg.rb +25 -19
- data/lib/esvg/jekyll_hooks.rb +1 -1
- data/lib/esvg/svgs.rb +39 -22
- data/lib/esvg/symbol.rb +24 -7
- data/lib/esvg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f283459b842a4ae61b966de4db35aa1be8520bddbdcb3f24ce6c9784b5797137
|
4
|
+
data.tar.gz: '078008b881bdbbc81cfb581bb7a0dc7b692087acd37bd838fad1cf62ccc1d543'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e34a8ff5f0f8b33c6a8c900336facc7649bec44e2aa99dda6601da1cf06a2d9372e9eccf089d74f9a74a3926d34ed0094897c3af4a83c97537c7ddcd165de75
|
7
|
+
data.tar.gz: 28bb6320c1f83fbed93d1b32100bfeb3146f2e1e74668beceaf810d9cbdb2ce94c1a3fc5c64627b262374b2bf3d18ff66a970e3ab52cd6e67d5c3d9369630672
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 4.6.3 (2018-12-19)
|
4
|
+
- Fix: Reworked configuration model, fixing build optimization failures.
|
5
|
+
|
6
|
+
### 4.6.2 (2018-12-18)
|
7
|
+
- New: Config is reloaded on change in development mode (Rails, Jekyll)
|
8
|
+
|
9
|
+
### 4.6.1 (2018-12-17)
|
10
|
+
- New: Embeds All Svgs in development mode (making reubilding after change unnecessary)
|
11
|
+
|
3
12
|
### 4.6.0 (2018-12-12)
|
4
13
|
- New: `presets` configuration. Configure `presets: { icon: { height: '1em', fill: 'currentColor' }}` in esvg.yml and set option `preset: 'icon'` to apply these defaults options.
|
5
14
|
- New: `sizes` configuration. Configure `sizes: { sm: { height: '10px' }, med: { height: '14px' }, … }` in esvg.yml and set option `size: 'sm'` to add load those size configuration options.
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
## Usage: Rails
|
30
30
|
|
31
|
-
Add `Esvg.precompile_assets` to your `config/initializers/assets.rb` to add build with `rake assets:
|
31
|
+
Add `Esvg.precompile_assets` to your `config/initializers/assets.rb` to add build with `rake assets:precompile`.
|
32
32
|
|
33
33
|
Add SVG files to your `app/assets/svgs/` directory.
|
34
34
|
|
data/exe/esvg
CHANGED
data/lib/esvg.rb
CHANGED
@@ -49,6 +49,7 @@ module Esvg
|
|
49
49
|
extend self
|
50
50
|
|
51
51
|
include Esvg::Utils
|
52
|
+
|
52
53
|
def new(options={})
|
53
54
|
@svgs ||=[]
|
54
55
|
c = config(options)
|
@@ -110,10 +111,6 @@ module Esvg
|
|
110
111
|
defined?(Rails) || File.exist?("./bin/rails")
|
111
112
|
end
|
112
113
|
|
113
|
-
def rails_production?
|
114
|
-
rails? && Rails.env.production?
|
115
|
-
end
|
116
|
-
|
117
114
|
def html_safe(input)
|
118
115
|
input = input.html_safe if rails?
|
119
116
|
input
|
@@ -121,9 +118,9 @@ module Esvg
|
|
121
118
|
|
122
119
|
# Add SVG build task to `rake assets:precompile`
|
123
120
|
def precompile_assets
|
124
|
-
if
|
121
|
+
if rails? && defined?(Rake)
|
125
122
|
::Rake::Task['assets:precompile'].enhance do
|
126
|
-
|
123
|
+
svgs.map(&:build)
|
127
124
|
end
|
128
125
|
end
|
129
126
|
end
|
@@ -170,37 +167,46 @@ module Esvg
|
|
170
167
|
|
171
168
|
if rails? || options[:rails]
|
172
169
|
config.merge!(CONFIG_RAILS)
|
170
|
+
config[:env] ||= Rails.env
|
173
171
|
elsif defined?(Jekyll)
|
174
172
|
config.merge!(CONFIG_JEKYLL)
|
173
|
+
config[:env] ||= Jekyll.env
|
175
174
|
end
|
176
175
|
|
176
|
+
config.merge!(options)
|
177
|
+
|
177
178
|
if path = paths.select{ |p| File.exist?(p)}.first
|
178
179
|
options[:config_file] = path
|
179
180
|
config.merge!(deep_symbolize_keys(YAML.load(File.read(path) || {})))
|
181
|
+
|
182
|
+
# Allow CLI passed options to override config file
|
183
|
+
config.merge!(options) if options[:cli]
|
180
184
|
else
|
181
185
|
options[:config_file] = false
|
182
186
|
end
|
183
187
|
|
184
|
-
config.merge!(options)
|
185
|
-
|
186
188
|
if defined? Jekyll
|
187
|
-
config[:build]
|
188
|
-
config[:source]
|
189
|
+
config[:build] = File.join(config[:destination], config[:build])
|
190
|
+
config[:source] = File.join(config[:source_dir], config[:source])
|
189
191
|
end
|
190
192
|
|
191
|
-
config[:filename]
|
193
|
+
config[:filename] = File.basename(config[:filename], '.*')
|
192
194
|
|
193
|
-
config[:pwd]
|
194
|
-
config[:source]
|
195
|
-
config[:build]
|
196
|
-
config[:assets]
|
195
|
+
config[:pwd] = File.expand_path Dir.pwd
|
196
|
+
config[:source] = File.expand_path config[:source] || config[:pwd]
|
197
|
+
config[:build] = File.expand_path config[:build] || config[:pwd]
|
198
|
+
config[:assets] = File.expand_path config[:assets] || config[:pwd]
|
199
|
+
config[:root] ||= config[:pwd] # For relative paths on print
|
197
200
|
|
198
|
-
config[:temp]
|
199
|
-
config[:temp]
|
201
|
+
config[:temp] = config[:pwd] if config[:temp].nil?
|
202
|
+
config[:temp] = File.expand_path( File.join(config[:temp], '.esvg-cache') )
|
200
203
|
|
201
|
-
config[:aliases]
|
204
|
+
config[:aliases] = load_aliases(config[:alias])
|
202
205
|
config[:flatten_dir] = [config[:flatten]].flatten.map { |dir| File.join(dir, '/') }.join('|')
|
203
|
-
config[:read]
|
206
|
+
config[:read] = Time.now.to_i
|
207
|
+
config[:env] ||= 'development'
|
208
|
+
config[:print] ||= true unless config[:env] == 'production'
|
209
|
+
config[:optimize] = true if config[:env] == 'production'
|
204
210
|
|
205
211
|
config
|
206
212
|
end
|
data/lib/esvg/jekyll_hooks.rb
CHANGED
@@ -9,7 +9,7 @@ Jekyll::Hooks.register :site, :post_read do |site|
|
|
9
9
|
site.exclude.push '.esvg-cache'
|
10
10
|
config = {
|
11
11
|
source_dir: site.config['source'],
|
12
|
-
destination: site.config['destination']
|
12
|
+
destination: site.config['destination']
|
13
13
|
}.merge site.config["esvg"] || {}
|
14
14
|
|
15
15
|
Jekyll.esvg = Esvg.seed_cache(config)
|
data/lib/esvg/svgs.rb
CHANGED
@@ -14,22 +14,29 @@ module Esvg
|
|
14
14
|
@config = options
|
15
15
|
@symbols = []
|
16
16
|
@svgs = []
|
17
|
-
@files_loaded = 0
|
18
17
|
read_cache
|
19
18
|
|
20
19
|
load_files
|
21
20
|
end
|
22
21
|
|
22
|
+
def production?
|
23
|
+
@config[:env] == 'production'
|
24
|
+
end
|
25
|
+
|
23
26
|
def config
|
24
27
|
# use cached configuration
|
25
|
-
if !
|
26
|
-
puts "
|
28
|
+
if !production? && config_expired? && config_changed?
|
29
|
+
puts "Reloading ESVG config: #{print_path( @config[:config_file] )}" if @config[:print]
|
27
30
|
@config = Esvg.update_config( @config )
|
28
31
|
else
|
29
32
|
@config
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
36
|
+
def print_path( path )
|
37
|
+
sub_path( @config[:root], path )
|
38
|
+
end
|
39
|
+
|
33
40
|
def config_expired?
|
34
41
|
@config[:throttle_read] < (Time.now.to_i - @config[:read])
|
35
42
|
end
|
@@ -38,34 +45,44 @@ module Esvg
|
|
38
45
|
@config[:config_file] && @config[:read] < File.mtime( @config[:config_file] ).to_i
|
39
46
|
end
|
40
47
|
|
48
|
+
def loaded_recently?
|
49
|
+
@last_load && (Time.now.to_i - @last_load) < @config[:throttle_read]
|
50
|
+
end
|
51
|
+
|
41
52
|
def load_files
|
42
|
-
return if
|
53
|
+
return if loaded_recently?
|
43
54
|
|
44
|
-
files
|
55
|
+
files = Dir[File.join(@config[:source], '**/*.svg')].uniq.sort
|
56
|
+
size_before = @symbols.size
|
57
|
+
added = []
|
58
|
+
removed = []
|
45
59
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# Remove deleted files
|
52
|
-
@symbols.reject(&:read).each { |s| @symbols.delete(s) }
|
60
|
+
# Remove all files which no longer exist
|
61
|
+
@symbols.reject(&:exist?).each { |s|
|
62
|
+
removed.push @symbols.delete(s)
|
63
|
+
}
|
53
64
|
|
54
65
|
files.each do |path|
|
55
66
|
unless @symbols.find { |s| s.path == path }
|
56
67
|
@symbols << Symbol.new(path, self)
|
68
|
+
added.push @symbols.last
|
57
69
|
end
|
58
70
|
end
|
59
71
|
|
72
|
+
if @config[:print]
|
73
|
+
puts %Q{Read #{files.size} SVGs from #{print_path( @config[:source] )}}
|
74
|
+
puts %Q{ Added: #{added.size} SVG#{'s' if added.size != 1} } if added.size > 0
|
75
|
+
puts %Q{ Removed: #{removed.size} SVG#{'s' if removed.size != 1} } if removed.size > 0
|
76
|
+
end
|
77
|
+
|
60
78
|
@svgs.clear
|
61
79
|
|
62
|
-
sort(@symbols.group_by(&:
|
80
|
+
sort(@symbols.group_by(&:dir)).each do |name, symbols|
|
63
81
|
@svgs << Svg.new(name, symbols, self)
|
64
82
|
end
|
65
83
|
|
66
|
-
@
|
67
|
-
|
68
|
-
puts "Read #{@symbols.size} files from #{@config[:source]}" if @config[:print]
|
84
|
+
@last_load = Time.now.to_i
|
85
|
+
write_cache if cache_stale?
|
69
86
|
|
70
87
|
end
|
71
88
|
|
@@ -82,11 +99,11 @@ module Esvg
|
|
82
99
|
@svgs.each do |file|
|
83
100
|
write_file file.path, js(file.embed)
|
84
101
|
|
85
|
-
puts "Writing #{file.path}" if @config[:print]
|
102
|
+
puts "Writing #{print_path( file.path )}" if @config[:print]
|
86
103
|
paths << file.path
|
87
104
|
|
88
105
|
if !file.asset && @config[:gzip] && gz = compress(file.path)
|
89
|
-
puts "Writing #{gz}" if @config[:print]
|
106
|
+
puts "Writing #{print_path( gz )}" if @config[:print]
|
90
107
|
paths << gz
|
91
108
|
end
|
92
109
|
end
|
@@ -96,12 +113,12 @@ module Esvg
|
|
96
113
|
end
|
97
114
|
|
98
115
|
def write_cache
|
99
|
-
puts "Writing cache" if @config[:print]
|
116
|
+
puts "Writing cache: #{ print_path( File.join( @config[:temp], @config[:cache_file]) )}" if @config[:print]
|
100
117
|
write_tmp @config[:cache_file], @symbols.map(&:data).to_yaml
|
101
118
|
end
|
102
119
|
|
103
120
|
def read_cache
|
104
|
-
(YAML.load(read_tmp
|
121
|
+
(YAML.load(read_tmp(@config[:cache_file])) || []).each do |c|
|
105
122
|
@config[:cache] = c
|
106
123
|
@symbols << Symbol.new(c[:path], self)
|
107
124
|
end
|
@@ -109,7 +126,7 @@ module Esvg
|
|
109
126
|
|
110
127
|
# Embed svg symbols
|
111
128
|
def embed_script(names=nil)
|
112
|
-
if
|
129
|
+
if production?
|
113
130
|
embeds = buildable_svgs(names).map(&:embed)
|
114
131
|
else
|
115
132
|
embeds = find_svgs(names).map(&:embed)
|
@@ -136,7 +153,7 @@ module Esvg
|
|
136
153
|
|
137
154
|
def find_symbol(name, fallback=nil)
|
138
155
|
# Ensure that file changes are picked up in development
|
139
|
-
load_files unless
|
156
|
+
load_files unless production?
|
140
157
|
|
141
158
|
name = get_alias dasherize(name)
|
142
159
|
|
data/lib/esvg/symbol.rb
CHANGED
@@ -18,12 +18,20 @@ module Esvg
|
|
18
18
|
@parent.config
|
19
19
|
end
|
20
20
|
|
21
|
+
def exist?
|
22
|
+
File.exist?(@path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def dir
|
26
|
+
@group
|
27
|
+
end
|
28
|
+
|
21
29
|
def read
|
22
|
-
return if !
|
30
|
+
return if !exist?
|
23
31
|
|
24
32
|
# Ensure that cache optimization matches current optimization settings
|
25
33
|
# If config has changed name, reset optimized build (name gets baked in)
|
26
|
-
if changed? || @svgo_optimized !=
|
34
|
+
if changed? || @svgo_optimized != optimize? || name != file_name
|
27
35
|
@optimized = nil
|
28
36
|
@optimized_at = nil
|
29
37
|
end
|
@@ -95,7 +103,7 @@ module Esvg
|
|
95
103
|
defs: @defs,
|
96
104
|
optimized: @optimized,
|
97
105
|
optimized_at: @optimized_at,
|
98
|
-
svgo_optimized:
|
106
|
+
svgo_optimized: optimize? && @svgo_optimized
|
99
107
|
}
|
100
108
|
end
|
101
109
|
|
@@ -160,17 +168,26 @@ module Esvg
|
|
160
168
|
%Q{<use #{attributes(options)}></use>}
|
161
169
|
end
|
162
170
|
|
163
|
-
|
164
|
-
|
171
|
+
# Only optimize if
|
172
|
+
# - Configuration asks for it
|
173
|
+
# - SVGO is present
|
174
|
+
# - If Rails is present
|
175
|
+
def optimize?
|
176
|
+
config[:optimize] && !!Esvg.node_module('svgo') && config[:env] == 'production'
|
165
177
|
end
|
166
178
|
|
167
179
|
def optimize
|
168
180
|
read if changed?
|
169
181
|
|
170
182
|
# Only optimize again if the file has changed
|
171
|
-
|
183
|
+
if @optimized && @optimized_at && @optimized_at > @mtime
|
184
|
+
return @optimized
|
185
|
+
end
|
186
|
+
|
187
|
+
# Only optimize if SVGO is installed
|
188
|
+
if optimize?
|
189
|
+
puts "Optimizing #{name}.svg" if config[:print]
|
172
190
|
|
173
|
-
if svgo?
|
174
191
|
response = Open3.capture3(%Q{#{Esvg.node_module('svgo')} --disable=removeUselessDefs -s '#{@content}' -o -})
|
175
192
|
if !response[0].empty? && response[2].success?
|
176
193
|
@optimized = response[0]
|
data/lib/esvg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esvg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.6.
|
4
|
+
version: 4.6.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: 2018-12-
|
11
|
+
date: 2018-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|