esvg 2.1.1 → 2.2.0
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/.gitignore +1 -0
- data/CHANGELOG.md +5 -1
- data/lib/esvg/svg.rb +39 -6
- 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: 98d1c59b1af38ab4024912d8cf4f3494602f735e
|
4
|
+
data.tar.gz: 1aff4ce984beec1383a7db0ce903af66323985e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03545cceaeb29d22e2c2ff525d69aefd0e1e5b207189100d9fa7d3ff01dbd00acffd0b2edcb754c5e401f62fbecf6d09f9ee2eba09410ca2ee4ab880f10411d7
|
7
|
+
data.tar.gz: 784305c4893813395c187e37f55d0a5e9c0be379978b2b301aa12d5173227bdc42105c50b8587f1b7f73a884981d364ea6725393cab13dd7a5175cc32b3e90b7
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
### 2.
|
3
|
+
### 2.2.0 (2015-09-30)
|
4
|
+
- New: New javascript helpers make it easier to inject SVG icons into javascript templates.
|
5
|
+
- New: Javascript works with module.exports if you're building Javascripts with a module requiring system.
|
6
|
+
|
7
|
+
### 2.1.1 (2015-09-29)
|
4
8
|
- Minor: `Esvg.icons.svgs` will now return the hash of svgs.
|
5
9
|
|
6
10
|
### 2.1.0 (2015-09-28)
|
data/lib/esvg/svg.rb
CHANGED
@@ -12,6 +12,7 @@ module Esvg
|
|
12
12
|
namespace_before: true,
|
13
13
|
font_size: '1em',
|
14
14
|
output_path: Dir.pwd,
|
15
|
+
verbose: false,
|
15
16
|
format: 'js'
|
16
17
|
}
|
17
18
|
|
@@ -122,17 +123,20 @@ module Esvg
|
|
122
123
|
|
123
124
|
classes = files.keys.map{|k| ".#{icon_name(k)}"}.join(', ')
|
124
125
|
preamble = %Q{#{classes} {
|
125
|
-
clip: auto;
|
126
126
|
font-size: #{config[:font_size]};
|
127
|
-
|
127
|
+
clip: auto;
|
128
|
+
background-size: auto;
|
128
129
|
background-repeat: no-repeat;
|
129
130
|
background-position: center center;
|
130
131
|
display: inline-block;
|
131
132
|
overflow: hidden;
|
133
|
+
background-size: auto 1em;
|
132
134
|
height: 1em;
|
133
135
|
width: 1em;
|
134
|
-
color:
|
136
|
+
color: inherit;
|
137
|
+
fill: currentColor;
|
135
138
|
vertical-align: middle;
|
139
|
+
line-height: 1em;
|
136
140
|
}}
|
137
141
|
styles << preamble
|
138
142
|
|
@@ -175,6 +179,30 @@ module Esvg
|
|
175
179
|
if (!document.querySelector('#esvg-symbols')) {
|
176
180
|
document.querySelector('body').insertAdjacentHTML('afterbegin', '#{html.gsub(/\n/,'').gsub("'"){"\\'"}}')
|
177
181
|
}
|
182
|
+
},
|
183
|
+
icon: function(name, classnames) {
|
184
|
+
var svgName = this.iconName(name)
|
185
|
+
var element = document.querySelector('#'+svgName)
|
186
|
+
|
187
|
+
if (element) {
|
188
|
+
return '<svg class="#{config[:base_class]} '+svgName+' '+(classnames || '')+'" '+this.dimensions(element)+'><use xlink:href="#'+svgName+'"/></svg>'
|
189
|
+
} else {
|
190
|
+
console.error('File not found: "'+name+'.svg" at #{File.join(config[:path],'')}')
|
191
|
+
}
|
192
|
+
},
|
193
|
+
iconName: function(name) {
|
194
|
+
var before = #{config[:namespace_before]}
|
195
|
+
if (before) {
|
196
|
+
return "#{config[:namespace]}-"+this.dasherize(name)
|
197
|
+
} else {
|
198
|
+
return name+"-#{config[:namespace]}"
|
199
|
+
}
|
200
|
+
},
|
201
|
+
dimensions: function(el) {
|
202
|
+
return 'viewBox="'+el.getAttribute('viewBox')+'" width="'+el.getAttribute('width')+'" height="'+el.getAttribute('height')+'"'
|
203
|
+
},
|
204
|
+
dasherize: function(input) {
|
205
|
+
return input.replace(/[\W,_]/g, '-').replace(/-{2,}/g, '-')
|
178
206
|
}
|
179
207
|
}
|
180
208
|
|
@@ -186,6 +214,9 @@ document.addEventListener("page:change", function(event) { esvg.embed() })
|
|
186
214
|
|
187
215
|
// Handle standard DOM ready events
|
188
216
|
document.addEventListener("DOMContentLoaded", function(event) { esvg.embed() })
|
217
|
+
|
218
|
+
// Work with module exports:
|
219
|
+
if(typeof(module) != 'undefined') { module.exports = esvg }
|
189
220
|
}
|
190
221
|
end
|
191
222
|
end
|
@@ -223,8 +254,10 @@ document.addEventListener("DOMContentLoaded", function(event) { esvg.embed() })
|
|
223
254
|
|
224
255
|
config.merge!(options)
|
225
256
|
|
226
|
-
|
227
|
-
|
257
|
+
if config[:verbose]
|
258
|
+
config[:path] = File.expand_path(config[:path])
|
259
|
+
config[:output_path] = File.expand_path(config[:output_path])
|
260
|
+
end
|
228
261
|
|
229
262
|
config[:js_path] ||= File.join(config[:output_path], 'esvg.js')
|
230
263
|
config[:css_path] ||= File.join(config[:output_path], 'esvg.css')
|
@@ -266,7 +299,7 @@ document.addEventListener("DOMContentLoaded", function(event) { esvg.embed() })
|
|
266
299
|
end
|
267
300
|
|
268
301
|
def dasherize(input)
|
269
|
-
input.gsub(
|
302
|
+
input.gsub(/[\W,_]/, '-').gsub(/-{2,}/, '-')
|
270
303
|
end
|
271
304
|
|
272
305
|
def find_files
|
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.
|
4
|
+
version: 2.2.0
|
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-09-
|
11
|
+
date: 2015-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|