esvg 2.8.2 → 2.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa191e67f41886a10774b5cf8afe96d36e9df8b2
4
- data.tar.gz: 663b4c607e06517b9e3f5db6c7b7d9dfe849b0a3
3
+ metadata.gz: c3c75eeb77428c51bc4e6746328c9e8749b853d6
4
+ data.tar.gz: 258aa171b7119d73f4d744770986d075b21a3375
5
5
  SHA512:
6
- metadata.gz: 964a746975dc300ef9baf7c45fae3f06761a3b7f6e6c8906f60e4de392eb4a231b94ec644afc2c627d9d79801a05dc773b7ca8018ce626d7e33e7f15d8136df9
7
- data.tar.gz: 5af0496f0676f485ea0d7c3f186ffe0c96ecc76e2add8a7f491b2030be66a0b4b47d03f620da00b11f2ff8350ebbee17b3d772c54eba7fae1627cb369f9d2d8b
6
+ metadata.gz: 9768ae503d3368438f470917b7740d592f2f679c8681fcbc9d50f3cea7c316a691e2286e68d1d3e0f0cceee59ab6d833df5b93a7dc19197f3fd56fefa68611b3
7
+ data.tar.gz: a6eb7131c5168194727cc4e8f6894284fbd551d95b5bf334dfbd99e9548d4878df13cb65772a84ec6eea075aaf611ea2ef15655d42eee234ef5af5f8b7196772
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
 
3
- ### 2.8.1 (2015-01-03)
3
+ ### 2.8.3 (2016-01-04)
4
+ - Fix: file read throttling
5
+ - Fix: Caching for Rails helper
6
+ - Improved tests covering dash vs. underscore usage
7
+
8
+ ### 2.8.2 (2016-01-03)
4
9
  - Fix: Rails helpers work better out of the box and hit the file system only when necessary.
5
10
 
6
11
  ### 2.8.1 (2015-12-16)
@@ -11,26 +11,12 @@ end
11
11
  module Esvg
12
12
  extend self
13
13
 
14
- def icons(options={})
15
- @icons ||= SVG.new(options)
16
-
17
- if !rails? || Rails.env.development?
18
- @icons.read_files
19
- end
20
-
21
- @icons
22
- end
23
-
24
- def embed(options={})
25
- icons(options).embed
26
- end
27
-
28
- def svg_icon(name, options={})
29
- @icons.svg_icon(name, options)
14
+ def new(options={})
15
+ SVG.new(options)
30
16
  end
31
17
 
32
- def exist?(name)
33
- @icons.exist?(name)
18
+ def embed
19
+ new.embed
34
20
  end
35
21
 
36
22
  def rails?
@@ -1,23 +1,7 @@
1
1
  module Esvg::Helpers
2
- def embed_svgs(options={})
3
- Esvg.icons(options).embed.html_safe
2
+ def svg_icons(options={})
3
+ @@svg_icons ||= Esvg.new(options)
4
+ @@svg_icons.read_files if Rails.env.development?
5
+ @@svg_icons
4
6
  end
5
-
6
- def svg_icon(name, options={})
7
- name = dasherize(name)
8
-
9
- begin
10
- icon_svg = Esvg.icons.svg_icon(name, options).html_safe
11
- rescue Exception => e
12
- raise e if !Rails.env.production?
13
- icon_svg = ''
14
- end
15
-
16
- icon_svg
17
- end
18
-
19
- def dasherize(input)
20
- input.gsub(/[\W,_]/, '-').gsub(/-{2,}/, '-')
21
- end
22
-
23
7
  end
@@ -3,7 +3,7 @@ require 'json'
3
3
 
4
4
  module Esvg
5
5
  class SVG
6
- attr_accessor :files, :svgs
6
+ attr_accessor :files, :svgs, :last_read
7
7
 
8
8
  CONFIG = {
9
9
  path: Dir.pwd,
@@ -16,6 +16,7 @@ module Esvg
16
16
  output_path: Dir.pwd,
17
17
  verbose: false,
18
18
  format: 'js',
19
+ throttle_read: 4,
19
20
  alias: {}
20
21
  }
21
22
 
@@ -27,6 +28,7 @@ module Esvg
27
28
  config(options)
28
29
 
29
30
  @svgo = nil
31
+ @last_read = nil
30
32
  @svgs = {}
31
33
 
32
34
  read_files
@@ -85,17 +87,26 @@ module Esvg
85
87
 
86
88
  def embed
87
89
  return if files.empty?
88
- case config[:format]
89
- when "html"
90
+ output = if config[:format] == "html"
90
91
  html
91
- when "js"
92
+ elsif config[:format] == "js"
92
93
  js
93
- when "css"
94
+ elsif config[:format] == "css"
94
95
  css
95
96
  end
97
+
98
+ if Esvg.rails?
99
+ output.html_safe
100
+ else
101
+ output
102
+ end
96
103
  end
97
104
 
98
105
  def read_files
106
+ if !@last_read.nil? && (Time.now.to_i - @last_read) < config[:throttle_read]
107
+ return
108
+ end
109
+
99
110
  @files = {}
100
111
 
101
112
  # Get a list of svg files and modification times
@@ -104,6 +115,8 @@ module Esvg
104
115
  files[f] = File.mtime(f)
105
116
  end
106
117
 
118
+ @last_read = Time.now.to_i
119
+
107
120
  puts "Read #{files.size} files from #{config[:path]}" if config[:cli]
108
121
 
109
122
  process_files
@@ -151,7 +164,11 @@ module Esvg
151
164
  if fallback = options.delete(:fallback)
152
165
  svg_icon(fallback, options)
153
166
  else
154
- raise "no svg named '#{get_alias(file)}' exists at #{config[:path]}"
167
+ if Esvg.rails? && Rails.env.production?
168
+ return ''
169
+ else
170
+ raise "no svg named '#{get_alias(file)}' exists at #{config[:path]}"
171
+ end
155
172
  end
156
173
  else
157
174
 
@@ -166,7 +183,13 @@ module Esvg
166
183
  end
167
184
  end
168
185
 
169
- embed.sub(/><\/svg/, ">#{title(options)}#{desc(options)}</svg")
186
+ embed = embed.sub(/><\/svg/, ">#{title(options)}#{desc(options)}</svg")
187
+
188
+ if Esvg.rails?
189
+ embed.html_safe
190
+ else
191
+ embed
192
+ end
170
193
  end
171
194
  end
172
195
 
@@ -1,3 +1,3 @@
1
1
  module Esvg
2
- VERSION = "2.8.2"
2
+ VERSION = "2.8.3"
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.8.2
4
+ version: 2.8.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: 2016-01-03 00:00:00.000000000 Z
11
+ date: 2016-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler