esvg 2.7.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa6229774082f4aea9f199648b775df39740ceab
4
- data.tar.gz: 0ae1d189e08fc4052453ca6a2e2a3b60e80c7824
3
+ metadata.gz: 63077454777a28a3ddee5f9aca2f4ea000a3f131
4
+ data.tar.gz: 3d9343e86d77843bcfb4806c4bcd8e2c8aa2c7fd
5
5
  SHA512:
6
- metadata.gz: fcf42cf652f2ba221b232a933a0585e63bd7b74a7cf85827f7c355735351cc7df2c5d24fdb8da1d6acef206b637e33de629687424429bc92efa89586a0f7e2c7
7
- data.tar.gz: dfdd9c185afb48597d998fefab052bc6ba5c6dfc11ca6f7903f7566b7e6498bfc48d38f0da478653207f0eeea55eec2ef82ed211e1bfe215876d995aa501abd8
6
+ metadata.gz: 4c43ee0a52b09ddf416392e6d5098b6039b99ddeca46f9d81c1d1593834f58f29a866a41272a0aeef647b2c6b99d843eb6f0137dfca528cd0d16c46a05d32d23
7
+ data.tar.gz: 1c3e29da770342ea03243064a1da60ab3256ae2e2251b84f04f546e3e2ea06e08bfab9e56a03cf6b4ceaa39eebc08fc23e518dc21e22ce1765935a977b6dbe86
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### 2.8.0 (2015-12-16)
4
+ - New: Added exist? method to ask if an icon exists.
5
+ - New: `fallback` option allows svgs to provide a fallback icon if one is not found.
6
+
3
7
  ### 2.7.0 (2015-12-08)
4
8
  - New: Now option style can append to inlines styles
5
9
 
@@ -29,6 +29,10 @@ module Esvg
29
29
  @icons.svg_icon(name, options)
30
30
  end
31
31
 
32
+ def exist?(name)
33
+ @icons.exist?(name)
34
+ end
35
+
32
36
  def rails?
33
37
  defined?(Rails)
34
38
  end
@@ -146,17 +146,29 @@ module Esvg
146
146
  end
147
147
 
148
148
  def svg_icon(file, options={})
149
- embed = use_icon(file)
150
- embed = embed.sub(/class="(.+?)"/, 'class="\1 '+options[:class]+'"') if options[:class]
151
- if options[:style]
152
- if embed.match(/style/)
153
- embed = embed.sub(/style="(.+?)"/, 'style="\1; '+options[:style]+'"')
149
+
150
+ if !exist?(file)
151
+ if fallback = options.delete(:fallback)
152
+ svg_icon(fallback, options)
154
153
  else
155
- embed = embed.sub(/><use/, %Q{ style="#{options[:style]}"><use})
154
+ raise "no svg named '#{get_alias(file)}' exists at #{config[:path]}"
156
155
  end
156
+ else
157
+
158
+ embed = use_icon(file)
159
+
160
+ embed.sub!(/class="(.+?)"/, 'class="\1 '+options[:class]+'"') if options[:class]
161
+
162
+ if options[:style]
163
+ if embed.match(/style/)
164
+ embed.sub!(/style="(.+?)"/, 'style="\1; '+options[:style]+'"')
165
+ else
166
+ embed.sub!(/><use/, %Q{ style="#{options[:style]}"><use})
167
+ end
168
+ end
169
+
170
+ embed.sub(/><\/svg/, ">#{title(options)}#{desc(options)}</svg")
157
171
  end
158
- embed = embed.sub(/><\/svg/, ">#{title(options)}#{desc(options)}</svg")
159
- embed
160
172
  end
161
173
 
162
174
  def dimensions(input)
@@ -171,13 +183,16 @@ module Esvg
171
183
 
172
184
  def use_icon(name)
173
185
  name = get_alias(name)
174
- if svgs[name].nil?
175
- raise "No svg named '#{name}' exists at #{config[:path]}"
176
- else
177
- svgs[name][:use]
178
- end
186
+ svgs[name][:use]
187
+ end
188
+
189
+ def exist?(name)
190
+ name = get_alias(name)
191
+ !svgs[name].nil?
179
192
  end
180
193
 
194
+ alias_method :exists?, :exist?
195
+
181
196
  def classname(name)
182
197
  name = dasherize(name)
183
198
  if config[:namespace_before]
@@ -1,3 +1,3 @@
1
1
  module Esvg
2
- VERSION = "2.7.0"
2
+ VERSION = "2.8.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: 2.7.0
4
+ version: 2.8.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-12-08 00:00:00.000000000 Z
11
+ date: 2015-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler