esvg 4.6.0 → 4.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/esvg.rb +4 -0
- data/lib/esvg/svg.rb +2 -2
- data/lib/esvg/svgs.rb +6 -2
- data/lib/esvg/symbol.rb +20 -11
- 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: 8b5d0d6910641142e441309223019ebfbb1d2a89482bddbe54ab449a27043beb
|
4
|
+
data.tar.gz: 46834ffa28ddc045350703ba4e3606c168e65022d3a024dc989970252d3a68cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25e807067537f26d6aba337e6c94acfcf22385842411706fde699338460ed1ae6a49a9850f513a63bba17d75620696107cd4b458b97fc4bff4eadab494786ed2
|
7
|
+
data.tar.gz: e69bfb87e23cffe1b4b7a17e92475f605f0ad24f7d092dd169a97ca4561819f2447790ef39a1dcc3ed6813032b7e8df04eeab4d7710b7d827286beac5d30306a
|
data/lib/esvg.rb
CHANGED
@@ -52,9 +52,13 @@ module Esvg
|
|
52
52
|
def new(options={})
|
53
53
|
@svgs ||=[]
|
54
54
|
c = config(options)
|
55
|
+
|
56
|
+
# If the source path is the same continue
|
57
|
+
# Otherwise add a new SVG group for this path
|
55
58
|
unless @svgs.find { |s| s.config[:source] == c[:source] }
|
56
59
|
@svgs << Svgs.new(c)
|
57
60
|
end
|
61
|
+
|
58
62
|
@svgs.last
|
59
63
|
end
|
60
64
|
|
data/lib/esvg/svg.rb
CHANGED
@@ -80,9 +80,9 @@ module Esvg
|
|
80
80
|
defs = @symbols.map(&:defs).compact.join
|
81
81
|
defs = "<defs>#{defs}</defs>" unless defs.empty?
|
82
82
|
|
83
|
-
|
83
|
+
symbols = @symbols.map(&:symbol).join.gsub("\n",'')
|
84
84
|
|
85
|
-
@svg = %Q{<svg id="esvg-#{id}" #{attributes(attr)} data-turbolinks-permanent>#{defs}#{
|
85
|
+
@svg = %Q{<svg id="esvg-#{id}" #{attributes(attr)} data-turbolinks-permanent>#{defs}#{symbols}</svg>}
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
data/lib/esvg/svgs.rb
CHANGED
@@ -90,9 +90,13 @@ module Esvg
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
# Embed
|
93
|
+
# Embed svg symbols
|
94
94
|
def embed_script(names=nil)
|
95
|
-
|
95
|
+
if Esvg.rails? && Rails.env.production?
|
96
|
+
embeds = buildable_svgs(names).map(&:embed)
|
97
|
+
else
|
98
|
+
embeds = find_svgs(names).map(&:embed)
|
99
|
+
end
|
96
100
|
|
97
101
|
write_cache if cache_stale?
|
98
102
|
|
data/lib/esvg/symbol.rb
CHANGED
@@ -83,7 +83,6 @@ module Esvg
|
|
83
83
|
def data
|
84
84
|
{
|
85
85
|
path: @path,
|
86
|
-
id: @id,
|
87
86
|
name: @name,
|
88
87
|
group: @group,
|
89
88
|
mtime: @mtime,
|
@@ -102,10 +101,12 @@ module Esvg
|
|
102
101
|
|
103
102
|
def use(options={})
|
104
103
|
|
104
|
+
# If preset key is set, merge presets from configuration
|
105
105
|
if options[:preset] && preset = @config[:presets][ options.delete(:preset).to_sym ]
|
106
106
|
options = options.merge( preset )
|
107
107
|
end
|
108
108
|
|
109
|
+
# If size key is set, merge size class from configuration
|
109
110
|
if options[:size] && size_class = @config[:sizes][ options.delete(:size).to_sym ]
|
110
111
|
options = options.merge( size_class )
|
111
112
|
end
|
@@ -165,20 +166,23 @@ module Esvg
|
|
165
166
|
# Only optimize again if the file has changed
|
166
167
|
return @optimized if @optimized && @optimized_at && @optimized_at > @mtime
|
167
168
|
|
168
|
-
@optimized = @content
|
169
|
-
|
170
169
|
if svgo?
|
171
|
-
response = Open3.capture3(%Q{#{Esvg.node_module('svgo')} --disable=removeUselessDefs -s '#{@
|
170
|
+
response = Open3.capture3(%Q{#{Esvg.node_module('svgo')} --disable=removeUselessDefs -s '#{@content}' -o -})
|
172
171
|
if !response[0].empty? && response[2].success?
|
173
172
|
@optimized = response[0]
|
174
173
|
@svgo_optimized = true
|
175
174
|
end
|
175
|
+
|
176
|
+
post_optimize
|
177
|
+
@optimized_at = Time.now.to_i
|
178
|
+
|
179
|
+
@optimized
|
176
180
|
end
|
177
181
|
|
178
|
-
|
179
|
-
@optimized_at = Time.now.to_i
|
182
|
+
end
|
180
183
|
|
181
|
-
|
184
|
+
def symbol
|
185
|
+
symbolize( optimize || @content )
|
182
186
|
end
|
183
187
|
|
184
188
|
def changed?
|
@@ -279,17 +283,22 @@ module Esvg
|
|
279
283
|
end
|
280
284
|
|
281
285
|
def post_optimize
|
282
|
-
@optimized
|
286
|
+
@optimized.gsub!(/\w+=""/,'') # Remove empty attributes
|
287
|
+
end
|
288
|
+
|
289
|
+
def symbolize( str )
|
290
|
+
strip_attributes( str )
|
283
291
|
.gsub(/<\/svg/,'</symbol') # Replace svgs with symbols
|
284
292
|
.gsub(/\w+=""/,'') # Remove empty attributes
|
293
|
+
.sub(/<svg/, "<symbol #{attributes(attr)}")
|
285
294
|
end
|
286
295
|
|
287
|
-
def
|
296
|
+
def strip_attributes( str )
|
288
297
|
attr.keys.each do |key|
|
289
|
-
|
298
|
+
str.sub!(/ #{key}=".+?"/,'')
|
290
299
|
end
|
291
300
|
|
292
|
-
|
301
|
+
str
|
293
302
|
end
|
294
303
|
|
295
304
|
# Scans <def> blocks for IDs
|
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.1
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|