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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 820db24a0bf898bc0a5fc35930e83c09fc14c7d83e352cb31b0150d0d84b74c3
4
- data.tar.gz: 25e7b4d70ec12353ac66a44379359f039f44cc2d554afb99d4bb73f1239a4a7d
3
+ metadata.gz: 8b5d0d6910641142e441309223019ebfbb1d2a89482bddbe54ab449a27043beb
4
+ data.tar.gz: 46834ffa28ddc045350703ba4e3606c168e65022d3a024dc989970252d3a68cc
5
5
  SHA512:
6
- metadata.gz: cc625fd97ac79845b97224d438a9f8187c95894651a2418b942ba6ef5dfbf04d7529f66f210136829ef89d0c6c4e8160a4b9cb508591fe0170b3fc11ab822623
7
- data.tar.gz: 49fa04b7635aa59a5d42c9bf358ab7c4bc63b195454a3abb9c6eb0783e2b557eda5d409e281053e475de1245a8764545c6856acd6e45dd86445fb130c0da27dc
6
+ metadata.gz: 25e807067537f26d6aba337e6c94acfcf22385842411706fde699338460ed1ae6a49a9850f513a63bba17d75620696107cd4b458b97fc4bff4eadab494786ed2
7
+ data.tar.gz: e69bfb87e23cffe1b4b7a17e92475f605f0ad24f7d092dd169a97ca4561819f2447790ef39a1dcc3ed6813032b7e8df04eeab4d7710b7d827286beac5d30306a
@@ -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
 
@@ -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
- optimized = @symbols.map(&:optimize).join.gsub("\n",'')
83
+ symbols = @symbols.map(&:symbol).join.gsub("\n",'')
84
84
 
85
- @svg = %Q{<svg id="esvg-#{id}" #{attributes(attr)} data-turbolinks-permanent>#{defs}#{optimized}</svg>}
85
+ @svg = %Q{<svg id="esvg-#{id}" #{attributes(attr)} data-turbolinks-permanent>#{defs}#{symbols}</svg>}
86
86
  end
87
87
  end
88
88
 
@@ -90,9 +90,13 @@ module Esvg
90
90
  end
91
91
  end
92
92
 
93
- # Embed only build scripts
93
+ # Embed svg symbols
94
94
  def embed_script(names=nil)
95
- embeds = buildable_svgs(names).map(&:embed)
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
 
@@ -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 '#{@optimized}' -o -})
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
- post_optimize
179
- @optimized_at = Time.now.to_i
182
+ end
180
183
 
181
- @optimized
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 = set_attributes
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 set_attributes
296
+ def strip_attributes( str )
288
297
  attr.keys.each do |key|
289
- @optimized.sub!(/ #{key}=".+?"/,'')
298
+ str.sub!(/ #{key}=".+?"/,'')
290
299
  end
291
300
 
292
- @optimized.sub(/<svg/, "<symbol #{attributes(attr)}")
301
+ str
293
302
  end
294
303
 
295
304
  # Scans <def> blocks for IDs
@@ -1,3 +1,3 @@
1
1
  module Esvg
2
- VERSION = "4.6.0"
2
+ VERSION = "4.6.1"
3
3
  end
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.0
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-13 00:00:00.000000000 Z
11
+ date: 2018-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler