esvg 2.5.0 → 2.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
  SHA1:
3
- metadata.gz: 286447567ec0661d4c3e9b4731cee656077ef12f
4
- data.tar.gz: fe5bebe1a92c7fbc693e098d90de34cc3ecbd160
3
+ metadata.gz: 8928ef2748b06a41e7ab4a9abe551d0dd16b96ba
4
+ data.tar.gz: fb3310389aaa166839a767115f94d92df0919a9a
5
5
  SHA512:
6
- metadata.gz: 696665b75357ee9df61d7cd5a6d9e608fb6599ff21f1c297c73787acd6494fffd9a47de9ac6180439313e1a1b2f29d4ddbcbe2dbef5443a7fda8912302f6e89d
7
- data.tar.gz: a98ff82d5493befd179a41d838a8ec5ca1859917b10811fac1414f1d2c0def3f0fd0a2cceb03faf51c0ef4814c8f284fb5b914c3a25e5c3d700c6e7134eec8af
6
+ metadata.gz: dad7eaffda60a40b8dd13eb9e723f9a8dd08e066494f1afc41944a5a441acb74786d65978179a505e568fe71c48d3bd13e40421b72ccae311c24abcfcc947701
7
+ data.tar.gz: 4ab68f00946a4dd1503e1e1d15f4e76624114fd798bf0bcaa30c4215b1cc3d7c3ddd2b9a593a499ab1dfcefb92a9f0b480bae94efb32277cae84cbfe11523fd1
@@ -2,5 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1.2
4
4
  before_install: gem install bundler -v 1.10.3
5
- before_script: npm install svgo -g
6
- script: bundle exec clash
5
+ script: bundle exec clash 1-4
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 2.6.0 (2015-12-07)
4
+ - New - Alias mapping so several different names can be used to reference icons
5
+
3
6
  ### 2.5.0 (2015-11-03)
4
7
  - Improved logging
5
8
  - Added `--version` flag for CLI
data/README.md CHANGED
@@ -102,6 +102,10 @@ base_class: svg-icon # Select all icons with this base classname
102
102
  namespace: icon # Namespace for symbol ids or CSS classnames
103
103
  namespace_before: true # Add namespace before, e.g. icon-kitten
104
104
 
105
+ alias: # Add aliases for icon names
106
+ comment: chat # use "chat" to reference comment.svg
107
+ error: bad, broken # Use "bad" or "broken" to reference error.svg
108
+
105
109
  font_size: 1em # Default size for SVGs (if embeded in stylesheets)
106
110
  ```
107
111
 
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'json'
2
3
 
3
4
  module Esvg
4
5
  class SVG
@@ -14,7 +15,8 @@ module Esvg
14
15
  font_size: '1em',
15
16
  output_path: Dir.pwd,
16
17
  verbose: false,
17
- format: 'js'
18
+ format: 'js',
19
+ alias: {}
18
20
  }
19
21
 
20
22
  CONFIG_RAILS = {
@@ -52,11 +54,35 @@ module Esvg
52
54
  config[:css_path] ||= File.join(config[:output_path], 'esvg.css')
53
55
  config[:html_path] ||= File.join(config[:output_path], 'esvg.html')
54
56
  config.delete(:output_path)
57
+ config[:aliases] = load_aliases(config[:alias])
55
58
 
56
59
  config
57
60
  end
58
61
  end
59
62
 
63
+ # Load aliases from configuration.
64
+ # returns a hash of aliasees mapped to a name.
65
+ # Converts configuration YAML:
66
+ # alias:
67
+ # foo: bar
68
+ # baz: zip, zop
69
+ # To output:
70
+ # { :bar => "foo", :zip => "baz", :zop => "baz" }
71
+ #
72
+ def load_aliases(aliases)
73
+ a = {}
74
+ aliases.each do |name,alternates|
75
+ alternates.split(',').each do |val|
76
+ a[dasherize(val.strip).to_sym] = dasherize(name.to_s)
77
+ end
78
+ end
79
+ a
80
+ end
81
+
82
+ def get_alias(name)
83
+ config[:aliases][dasherize(name).to_sym] || name
84
+ end
85
+
60
86
  def embed
61
87
  return if files.empty?
62
88
  case config[:format]
@@ -115,7 +141,7 @@ module Esvg
115
141
  end
116
142
 
117
143
  def use_svg(file, content)
118
- name = classname(file)
144
+ name = classname(get_alias(file))
119
145
  %Q{<svg class="#{config[:base_class]} #{name}" #{dimensions(content)}><use xlink:href="##{name}"/></svg>}
120
146
  end
121
147
 
@@ -137,6 +163,7 @@ module Esvg
137
163
  end
138
164
 
139
165
  def use_icon(name)
166
+ name = get_alias(name)
140
167
  if svgs[name].nil?
141
168
  raise "No svg named '#{name}' exists at #{config[:path]}"
142
169
  else
@@ -335,6 +362,15 @@ module Esvg
335
362
 
336
363
  // Handle standard DOM ready events
337
364
  document.addEventListener("DOMContentLoaded", function(event) { this.embed() }.bind(this))
365
+ },
366
+ aliases: #{config[:aliases].to_json},
367
+ alias: function(name) {
368
+ var aliased = this.aliases[name]
369
+ if (typeof(aliased) != "undefined") {
370
+ return aliased
371
+ } else {
372
+ return name
373
+ }
338
374
  }
339
375
  }
340
376
 
@@ -1,3 +1,3 @@
1
1
  module Esvg
2
- VERSION = "2.5.0"
2
+ VERSION = "2.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: 2.5.0
4
+ version: 2.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: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2015-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,7 +71,6 @@ email:
71
71
  - brandon@imathis.com
72
72
  executables:
73
73
  - esvg
74
- - esvgo
75
74
  extensions: []
76
75
  extra_rdoc_files: []
77
76
  files:
@@ -87,7 +86,6 @@ files:
87
86
  - bin/setup
88
87
  - esvg.gemspec
89
88
  - exe/esvg
90
- - exe/esvgo
91
89
  - lib/esvg.rb
92
90
  - lib/esvg/helpers.rb
93
91
  - lib/esvg/railties.rb
data/exe/esvgo DELETED
@@ -1,18 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
4
-
5
- require 'optparse'
6
- require 'esvg'
7
-
8
- options = {}
9
-
10
- OptionParser.new do |opts|
11
- opts.on("-c", "--config PATH", String, "Path to a config file (default: esvg.yml, config/esvg.yml)") do |path|
12
- options[:config_file] = path
13
- end
14
- end.parse!
15
-
16
- options[:path] = ARGV.shift
17
-
18
- esvg = Esvg::SVG.new(options).optimize