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 +4 -4
- data/CHANGELOG.md +6 -1
- data/lib/esvg.rb +4 -18
- data/lib/esvg/helpers.rb +4 -20
- data/lib/esvg/svg.rb +30 -7
- data/lib/esvg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3c75eeb77428c51bc4e6746328c9e8749b853d6
|
4
|
+
data.tar.gz: 258aa171b7119d73f4d744770986d075b21a3375
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9768ae503d3368438f470917b7740d592f2f679c8681fcbc9d50f3cea7c316a691e2286e68d1d3e0f0cceee59ab6d833df5b93a7dc19197f3fd56fefa68611b3
|
7
|
+
data.tar.gz: a6eb7131c5168194727cc4e8f6894284fbd551d95b5bf334dfbd99e9548d4878df13cb65772a84ec6eea075aaf611ea2ef15655d42eee234ef5af5f8b7196772
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
### 2.8.
|
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)
|
data/lib/esvg.rb
CHANGED
@@ -11,26 +11,12 @@ end
|
|
11
11
|
module Esvg
|
12
12
|
extend self
|
13
13
|
|
14
|
-
def
|
15
|
-
|
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
|
33
|
-
|
18
|
+
def embed
|
19
|
+
new.embed
|
34
20
|
end
|
35
21
|
|
36
22
|
def rails?
|
data/lib/esvg/helpers.rb
CHANGED
@@ -1,23 +1,7 @@
|
|
1
1
|
module Esvg::Helpers
|
2
|
-
def
|
3
|
-
Esvg.
|
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
|
data/lib/esvg/svg.rb
CHANGED
@@ -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
|
-
|
89
|
-
when "html"
|
90
|
+
output = if config[:format] == "html"
|
90
91
|
html
|
91
|
-
|
92
|
+
elsif config[:format] == "js"
|
92
93
|
js
|
93
|
-
|
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
|
-
|
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
|
|
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: 2.8.
|
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-
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|