esvg 2.4.1 → 2.4.2

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: 18967aa14b9ff1be12be160f27011f0d27f52c76
4
- data.tar.gz: d302417c96f774c13fbe8f9f11ba05b11b3efe96
3
+ metadata.gz: 6b087a02dc8dc7a7441b1e1947004e94ec92c0da
4
+ data.tar.gz: 6493260130cb04bbb057919c7fd73ab905794105
5
5
  SHA512:
6
- metadata.gz: b645873370e95a13572a900a08c70782904c8010cd2437c66fe74da38a24e5d2f8c910907fb7d9c948f3a739e3cf915a2c8f8590ab71efc19b95c54f9af31211
7
- data.tar.gz: 41fed94f9feee7e3f45caf23fc520a9f05d06fa146a65796a41eb2ba6c398d0d24fb01f85b994b999c8ffc283a5b5cecd9e0a0145f08e3ed689daec9f2abd1ae
6
+ metadata.gz: dd65cb5d99def4eb3100975670c760e7f4bfed24bd7117844844d3c813d4e5dca289246e45d7cc3c439b0d80be8d73fe3329f3b3d0e3b8417f4ee7bab837c7f4
7
+ data.tar.gz: cd900bbfd5310726d2b946eb82c6f694cf7f947fd2b9a663105a09014364b1876c48f40228b2a0577ed2e795d399a026271e5047196d1c78d00b248c3127ead6
data/CHANGELOG.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ### 2.4.2 (2015-10-26)
4
+ - Fix: Improved reliability and speed of optimization with svgo, by writing a temp file to the file system.
5
+
3
6
  ### 2.4.1 (2015-10-17)
4
- - Fix: Icon embedding (with ruby/rails) uses proper key for lookup.
7
+ - Fix: icon embedding (with ruby/rails) uses proper key for lookup.
5
8
 
6
9
  ### 2.4.0 (2015-10-17)
7
10
  - New: Caching is now based on file modification times. It's much faster and more efficient.
data/lib/esvg/svg.rb CHANGED
@@ -112,15 +112,6 @@ module Esvg
112
112
  }
113
113
  end
114
114
 
115
- #def compress(file)
116
- #if config[:optimize] && svgo?
117
- #Compress files outputting to $STDOUT which returns as a string
118
- #`#{@svgo} #{file} -o -`
119
- #else
120
- #File.read(file)
121
- #end
122
- #end
123
-
124
115
  def use_svg(file, content)
125
116
  name = classname(file)
126
117
  %Q{<svg class="#{config[:base_class]} #{name}" #{dimensions(content)}><use xlink:href="##{name}"/></svg>}
@@ -198,6 +189,12 @@ module Esvg
198
189
  end
199
190
  end
200
191
 
192
+ def write_svg(svg)
193
+ path = File.join(config[:path], '.esvg-cache')
194
+ write_file path, svg
195
+ path
196
+ end
197
+
201
198
  def write_js
202
199
  write_file config[:js_path], js
203
200
  end
@@ -254,10 +251,24 @@ module Esvg
254
251
  end
255
252
 
256
253
  def prep_svg(file, content)
257
- content.gsub(/<svg.+?>/, %Q{<svg class="#{classname(file)}" #{dimensions(content)}>}) # convert svg to symbols
258
- .gsub(/\n/, '') # remove endlines
259
- .gsub(/\s{2,}/, ' ') # remove whitespace
260
- .gsub(/>\s+</, '><') # remove whitespace between tags
254
+ content = content.gsub(/<svg.+?>/, %Q{<svg class="#{classname(file)}" #{dimensions(content)}>}) # convert svg to symbols
255
+ .gsub(/\n/, '') # Remove endlines
256
+ .gsub(/\s{2,}/, ' ') # Remove whitespace
257
+ .gsub(/>\s+</, '><') # Remove whitespace between tags
258
+ .gsub(/style="([^"]*?)fill:(.+?);/m, 'fill="\2" style="\1') # Make fill a property instead of a style
259
+ .gsub(/style="([^"]*?)fill-opacity:(.+?);/m, 'fill-opacity="\2" style="\1') # Move fill-opacity a property instead of a style
260
+ .gsub(/\s?style=".*?";?/,'') # Strip style property
261
+ .gsub(/\s?fill="(#0{3,6}|black|rgba?\(0,0,0\))"/,'') # Strip black fill
262
+ end
263
+
264
+ def optimize(svg)
265
+ if config[:optimize] && svgo?
266
+ path = write_svg(svg)
267
+ svg = `svgo '#{path}' -o -`
268
+ FileUtils.rm(path)
269
+ end
270
+
271
+ svg
261
272
  end
262
273
 
263
274
  def html
@@ -269,13 +280,7 @@ module Esvg
269
280
  symbols << prep_svg(name, data[:content])
270
281
  end
271
282
 
272
- symbols = if config[:optimize] && svgo?
273
- `svgo -s '#{symbols.join}' -o -`
274
- else
275
- symbols.join
276
- end
277
-
278
- symbols = symbols.gsub(/class/,'id').gsub(/svg/,'symbol')
283
+ symbols = optimize(symbols.join).gsub(/class/,'id').gsub(/svg/,'symbol')
279
284
 
280
285
  %Q{<svg id="esvg-symbols" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none">#{symbols}</svg>}
281
286
  end
data/lib/esvg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Esvg
2
- VERSION = "2.4.1"
2
+ VERSION = "2.4.2"
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: 2.4.1
4
+ version: 2.4.2
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-10-18 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler