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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09c5c765988ce0a64353406948e42d7d97d4c5b7326ae4d8531987d98650f510'
4
- data.tar.gz: 63248c8391f17ec3d197f2ef525e88d9e84f67415a9e85e0b2b7d3533764f3dc
3
+ metadata.gz: 820db24a0bf898bc0a5fc35930e83c09fc14c7d83e352cb31b0150d0d84b74c3
4
+ data.tar.gz: 25e7b4d70ec12353ac66a44379359f039f44cc2d554afb99d4bb73f1239a4a7d
5
5
  SHA512:
6
- metadata.gz: 7a480482a7aa333789dee900e968fae4930998f06da35af24f18238253302542caf542748707898140d0fac81c658f01330e5625751583c62f51d946594202c5
7
- data.tar.gz: 53016c37c452c2adb00234baa5d98a9c6e059373136dba962b26864bac3da8512e0c9cf77f973857a002b2ae3c7bda6235866727d001610e3bd511d038632ced
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 symbolize_keys(hash)
137
- h = {}
138
- hash.each {|k,v| h[k.to_sym] = v }
139
- h
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!(symbolize_keys(YAML.load(File.read(path) || {})))
167
+ config.merge!(deep_symbolize_keys(YAML.load(File.read(path) || {})))
155
168
  end
156
169
 
157
170
  config.merge!(options)
@@ -57,7 +57,7 @@ module Jekyll
57
57
  if @options.empty?
58
58
  @options = {}
59
59
  else
60
- @options = Jekyll::Utils.symbolize_hash_keys(YAML.load(@options)) unless @options.empty?
60
+ @options = Esvg.deep_symbolize_hash_keys(YAML.load(@options)) unless @options.empty?
61
61
  end
62
62
  end
63
63
 
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
@@ -1,3 +1,3 @@
1
1
  module Esvg
2
- VERSION = "4.5.0"
2
+ VERSION = "4.6.0"
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.5.0
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 00:00:00.000000000 Z
11
+ date: 2018-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler