esvg 4.5.0 → 4.6.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/CHANGELOG.md +4 -0
- data/README.md +17 -0
- data/lib/esvg.rb +19 -6
- data/lib/esvg/jekyll_hooks.rb +1 -1
- data/lib/esvg/svgs.rb +1 -1
- data/lib/esvg/symbol.rb +9 -0
- data/lib/esvg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 820db24a0bf898bc0a5fc35930e83c09fc14c7d83e352cb31b0150d0d84b74c3
|
4
|
+
data.tar.gz: 25e7b4d70ec12353ac66a44379359f039f44cc2d554afb99d4bb73f1239a4a7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc625fd97ac79845b97224d438a9f8187c95894651a2418b942ba6ef5dfbf04d7529f66f210136829ef89d0c6c4e8160a4b9cb508591fe0170b3fc11ab822623
|
7
|
+
data.tar.gz: 49fa04b7635aa59a5d42c9bf358ab7c4bc63b195454a3abb9c6eb0783e2b557eda5d409e281053e475de1245a8764545c6856acd6e45dd86445fb130c0da27dc
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 4.6.0 (2018-12-12)
|
4
|
+
- New: `presets` configuration. Configure `presets: { icon: { height: '1em', fill: 'currentColor' }}` in esvg.yml and set option `preset: 'icon'` to apply these defaults options.
|
5
|
+
- New: `sizes` configuration. Configure `sizes: { sm: { height: '10px' }, med: { height: '14px' }, … }` in esvg.yml and set option `size: 'sm'` to add load those size configuration options.
|
6
|
+
|
3
7
|
### 4.5.0 (2018-12-11)
|
4
8
|
- New: width and height will be scaled proportionately. So passing only `width: 50` will set height proportionately based on original svg dimensions.
|
5
9
|
- To disable automatic calculation pass `scale: true`.
|
data/README.md
CHANGED
@@ -82,6 +82,12 @@ To place an SVG, use the `use_svg` vew helper. This helper will embed an SVG `us
|
|
82
82
|
# Add custom styles
|
83
83
|
<%= use_svg 'logo', style: 'fill: #c0ffee' %>
|
84
84
|
|
85
|
+
# Use presets (setup in config yaml)
|
86
|
+
<%= use_svg 'chevron', preset: 'icon' %>
|
87
|
+
|
88
|
+
# Use size classes (setup in config yaml)
|
89
|
+
<%= use_svg 'chevron', size: 'small' %>
|
90
|
+
|
85
91
|
# Output:
|
86
92
|
# <svg class="svg-symbol svg-logo" style="fill: #coffee;"><use xlink:href="#svg-logo"/></svg>
|
87
93
|
|
@@ -129,6 +135,17 @@ namespace_before: true # Add namespace before, e.g. 'svg-logo', false would
|
|
129
135
|
alias: # Add aliases for icon names
|
130
136
|
comment: chat # use "chat" to reference comment.svg
|
131
137
|
error: bad, broken # Use "bad" or "broken" to reference error.svg
|
138
|
+
|
139
|
+
presets: # Add named presets for setting common options
|
140
|
+
icon: # Passing option preset: 'icon' will set these defaults
|
141
|
+
height: 1em
|
142
|
+
class: icon
|
143
|
+
|
144
|
+
sizes: # Define size classes for easy assignment
|
145
|
+
small: # size classes override presets
|
146
|
+
height: 10px
|
147
|
+
medium:
|
148
|
+
height: 20px
|
132
149
|
```
|
133
150
|
|
134
151
|
## Contributing
|
data/lib/esvg.rb
CHANGED
@@ -26,7 +26,9 @@ CONFIG = {
|
|
26
26
|
fingerprint: true,
|
27
27
|
throttle_read: 4,
|
28
28
|
flatten: [],
|
29
|
-
alias: {}
|
29
|
+
alias: {},
|
30
|
+
presets: {},
|
31
|
+
sizes: {}
|
30
32
|
}
|
31
33
|
|
32
34
|
CONFIG_RAILS = {
|
@@ -133,10 +135,21 @@ module Esvg
|
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
136
|
-
def
|
137
|
-
|
138
|
-
|
139
|
-
|
138
|
+
def deep_transform_keys_in_object(object, &block)
|
139
|
+
case object
|
140
|
+
when Hash
|
141
|
+
object.each_with_object({}) do |(key, value), result|
|
142
|
+
result[yield(key)] = deep_transform_keys_in_object(value, &block)
|
143
|
+
end
|
144
|
+
when Array
|
145
|
+
object.map {|e| deep_transform_keys_in_object(e, &block) }
|
146
|
+
else
|
147
|
+
object
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def deep_symbolize_keys(hash)
|
152
|
+
deep_transform_keys_in_object( hash ){ |key| key.to_sym rescue key }
|
140
153
|
end
|
141
154
|
|
142
155
|
def config(options={})
|
@@ -151,7 +164,7 @@ module Esvg
|
|
151
164
|
end
|
152
165
|
|
153
166
|
if path = paths.select{ |p| File.exist?(p)}.first
|
154
|
-
config.merge!(
|
167
|
+
config.merge!(deep_symbolize_keys(YAML.load(File.read(path) || {})))
|
155
168
|
end
|
156
169
|
|
157
170
|
config.merge!(options)
|
data/lib/esvg/jekyll_hooks.rb
CHANGED
data/lib/esvg/svgs.rb
CHANGED
@@ -106,7 +106,7 @@ module Esvg
|
|
106
106
|
path = File.join(config[:temp], config[:cache_file])
|
107
107
|
|
108
108
|
# No cache file exists or cache file is older than a new symbol
|
109
|
-
!File.exist?(path) || File.mtime(path).to_i < @symbols.map(&:mtime).sort.last
|
109
|
+
!File.exist?(path) || @symbols.size > 0 && File.mtime(path).to_i < @symbols.map(&:mtime).sort.last
|
110
110
|
end
|
111
111
|
|
112
112
|
def build_paths(names=nil)
|
data/lib/esvg/symbol.rb
CHANGED
@@ -101,6 +101,15 @@ module Esvg
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def use(options={})
|
104
|
+
|
105
|
+
if options[:preset] && preset = @config[:presets][ options.delete(:preset).to_sym ]
|
106
|
+
options = options.merge( preset )
|
107
|
+
end
|
108
|
+
|
109
|
+
if options[:size] && size_class = @config[:sizes][ options.delete(:size).to_sym ]
|
110
|
+
options = options.merge( size_class )
|
111
|
+
end
|
112
|
+
|
104
113
|
options.delete(:fallback)
|
105
114
|
content = options.delete(:content) || ''
|
106
115
|
|
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: 4.
|
4
|
+
version: 4.6.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: 2018-12-
|
11
|
+
date: 2018-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|