esvg 4.3.4 → 4.3.5

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
  SHA1:
3
- metadata.gz: 8c8ce957c55ac551dc1f3d5b6f258aa17e0c9e07
4
- data.tar.gz: 79721c7d5e990437a7860aa33928484c43c7fe9c
3
+ metadata.gz: 8106c249cd9020c020a26e4ad41524946b1918d7
4
+ data.tar.gz: 78ad6edd6beac2930cbb2316ef9746ea079a80c9
5
5
  SHA512:
6
- metadata.gz: 26dee9b0b6b601bbd04b9dfa2ea1729afa20c06772ca433e70c270a6459b3dcbf0b913a91e530510b0cb7f0d768363e47c354807b47bd94c54fb091b67a17030
7
- data.tar.gz: 8e58aa8424c853ee832d13f16e95af4e94e1819cea792cdfbb4da8accbe8829ea7195a2951d4aeaf683715d208cb444db160df7283c9baef3c15c67a661bcac6
6
+ metadata.gz: f9fe3f77e80cb73477f0a93a300fc428251730958b414d14f2660d604a90223aaa2361bb980a4046ac8f19a81c8324ce5655e77b6f572c829ce03eaaa07a056d
7
+ data.tar.gz: 7278b841d68181cf8c56c8a6e767266916922c52cdcdbee5f64f65d8a0b2f30a707b8d5632b03b1170d7a50d4cf12d156b13c59851d760d5e8644ee2e0cd5376
data/lib/esvg/svg.rb CHANGED
@@ -67,19 +67,23 @@ module Esvg
67
67
  end
68
68
 
69
69
  def svg
70
- attr = {
71
- "data-symbol-class" => @config[:class],
72
- "data-prefix" => @config[:prefix],
73
- "version" => "1.1",
74
- "style" => "height:0;position:absolute"
75
- }
70
+ if @svg && @symbols.select(&:changed?).empty?
71
+ @svg
72
+ else
73
+ attr = {
74
+ "data-symbol-class" => @config[:class],
75
+ "data-prefix" => @config[:prefix],
76
+ "version" => "1.1",
77
+ "style" => "height:0;position:absolute"
78
+ }
76
79
 
77
- defs = @symbols.map(&:defs).compact.join
78
- defs = "<defs>#{defs}</defs>" unless defs.empty?
80
+ defs = @symbols.map(&:defs).compact.join
81
+ defs = "<defs>#{defs}</defs>" unless defs.empty?
79
82
 
80
- optimized = @symbols.map(&:optimize).join.gsub("\n",'')
83
+ optimized = @symbols.map(&:optimize).join.gsub("\n",'')
81
84
 
82
- %Q{<svg id="esvg-#{id}" #{attributes(attr)}>#{defs}#{optimized}</svg>}
85
+ @svg = %Q{<svg id="esvg-#{id}" #{attributes(attr)}>#{defs}#{optimized}</svg>}
86
+ end
83
87
  end
84
88
 
85
89
  end
data/lib/esvg/svgs.rb CHANGED
@@ -14,6 +14,7 @@ module Esvg
14
14
  filename: 'svgs',
15
15
  class: 'svg-symbol',
16
16
  prefix: 'svg',
17
+ cache_file: '.symbols',
17
18
  core: true,
18
19
  optimize: false,
19
20
  gzip: false,
@@ -132,11 +133,12 @@ module Esvg
132
133
  end
133
134
 
134
135
  def write_cache
135
- write_tmp '.symbols', @symbols.map(&:data).to_yaml
136
+ puts "Writing cache" if config[:print]
137
+ write_tmp config[:cache_file], @symbols.map(&:data).to_yaml
136
138
  end
137
139
 
138
140
  def read_cache
139
- (YAML.load(read_tmp '.symbols') || []).each do |c|
141
+ (YAML.load(read_tmp config[:cache_file]) || []).each do |c|
140
142
  config[:cache] = c
141
143
  @symbols << Symbol.new(c[:path], config)
142
144
  end
@@ -145,9 +147,20 @@ module Esvg
145
147
  # Embed only build scripts
146
148
  def embed_script(names=nil)
147
149
  embeds = buildable_svgs(names).map(&:embed)
150
+
151
+ write_cache if cache_stale?
152
+
148
153
  if !embeds.empty?
149
154
  "<script>#{js(embeds.join("\n"))}</script>"
150
155
  end
156
+
157
+ end
158
+
159
+ def cache_stale?
160
+ path = File.join(config[:temp], config[:cache_file])
161
+
162
+ # No cache file exists or cache file is older than a new symbol
163
+ !File.exist?(path) || File.mtime(path).to_i < @symbols.map(&:mtime).sort.last
151
164
  end
152
165
 
153
166
  def build_paths(names=nil)
data/lib/esvg/symbol.rb CHANGED
@@ -9,6 +9,7 @@ module Esvg
9
9
  def initialize(path, config={})
10
10
  @config = config
11
11
  @path = path
12
+ @last_checked = 0
12
13
  load_data
13
14
  read
14
15
  end
@@ -16,11 +17,9 @@ module Esvg
16
17
  def read
17
18
  return if !File.exist?(@path)
18
19
 
19
- time = last_modified
20
-
21
20
  # Ensure that cache optimization matches current optimization settings
22
21
  # If config has changed name, reset optimized build (name gets baked in)
23
- if @mtime != time || @svgo_optimized != svgo? || name != file_name
22
+ if changed? || @svgo_optimized != svgo? || name != file_name
24
23
  @optimized = nil
25
24
  @optimized_at = nil
26
25
  end
@@ -29,9 +28,9 @@ module Esvg
29
28
  @name = file_name
30
29
  @id = file_id file_key
31
30
 
32
- if @mtime != time
31
+ if changed?
33
32
  @content = prep_defs pre_optimize File.read(@path)
34
- @mtime = time
33
+ @mtime = last_modified
35
34
  @size = dimensions
36
35
  end
37
36
 
@@ -115,8 +114,10 @@ module Esvg
115
114
  end
116
115
 
117
116
  def optimize
117
+ read if changed?
118
+
118
119
  # Only optimize again if the file has changed
119
- return @optimized if @optimized && @optimized_at > @mtime
120
+ return @optimized if @optimized && @optimized_at && @optimized_at > @mtime
120
121
 
121
122
  @optimized = @content
122
123
 
@@ -134,6 +135,10 @@ module Esvg
134
135
  @optimized
135
136
  end
136
137
 
138
+ def changed?
139
+ last_modified != mtime
140
+ end
141
+
137
142
  private
138
143
 
139
144
  def load_data
@@ -145,7 +150,12 @@ module Esvg
145
150
  end
146
151
 
147
152
  def last_modified
148
- File.mtime(@path).to_i
153
+ if Time.now.to_i - @last_checked < @config[:throttle_read]
154
+ @last_modified
155
+ else
156
+ @last_checked = Time.now.to_i
157
+ @last_modified = File.mtime(@path).to_i
158
+ end
149
159
  end
150
160
 
151
161
  def file_id(name)
data/lib/esvg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Esvg
2
- VERSION = "4.3.4"
2
+ VERSION = "4.3.5"
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.3.4
4
+ version: 4.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-08 00:00:00.000000000 Z
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler