esvg 1.0.0 → 1.1.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: 5617c1952dc7fd76da427719eb2a7ddb5a8e7910
4
- data.tar.gz: 7ab87e15d4af16d39aac5c53116e9f945719b09c
3
+ metadata.gz: 2c5712f3b740b3238193d1d2ef3d2babd708e8be
4
+ data.tar.gz: 9d04de7f13bd73bd42d72dcda666894a74bd89d0
5
5
  SHA512:
6
- metadata.gz: f1fd6835394f4aad7832edf92997f79a89e2f3a2d9b4cf1f1aab4e2bad25ea088c5d4f8b93f35e250f2e447edd6fa3c0e649c6536149e58d72fa42df82ee283e
7
- data.tar.gz: 94a0b8da7fc8e9314bcbecc1f0052f4dca9934214e8ea4a013400d73d24f44a03afdd300f6ff1d36ac6d013afd17a857355851bfcbd4de31534707b0937bc154
6
+ metadata.gz: 81f741e63a224d7385f574e7406f5898240bc0ba6f11083c2f5a35d0d9a33887a1d60f7bda7fe0d2f217cc8488ee01b3e8dcebd3c629deb27542fc6979cbd376
7
+ data.tar.gz: 82279d2eedce5e102b124fe63ba8f0a98da2a207aaaba018b7ff2b446a3e873ca30b060e0b827e39797c72f9c32259030ea3c8c56c2c755d439e1ed0f0615db4
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ### 1.1.0 (2015-06-29)
4
+
5
+ - Now `embed_svgs` accepts an array, allowing a subset of icons to be embedded per page.
6
+
7
+ ## 1.0.0 (2015-06-29)
8
+
9
+ - Initial release
data/README.md CHANGED
@@ -23,16 +23,23 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage: Rails
25
25
 
26
- Add SVG files to your `app/assets/svg_icons/` directory, then embed these SVGs in your application layout like this:
26
+ Add SVG files to your `app/assets/svg_icons/` directory, then embed these SVGs in your application layout at the top of the `<body>`, like this:
27
27
 
28
28
  ```
29
- <head>
30
- ...
29
+ <body>
31
30
  <%= embed_svgs %>
32
- </head>
31
+ ...
32
+ </body>
33
+ ```
34
+
35
+ To include only a subset of SVG icons on a page you can pass an array of icon names like this.
36
+
37
+ ```
38
+ # Say we're on user/show
39
+ <%= embed_svgs %w(siloutte gear menu) %>
33
40
  ```
34
41
 
35
- To reference an SVG, use the `svg_icon` helper.
42
+ To place an SVG icon, use the `svg_icon` helper.
36
43
 
37
44
  ```
38
45
  # Syntax: svg_icon name, [options]
data/lib/esvg.rb CHANGED
@@ -22,8 +22,8 @@ module Esvg
22
22
  @icons
23
23
  end
24
24
 
25
- def embed_svgs
26
- icons.html.html_safe
25
+ def embed_svgs(names=[])
26
+ icons.html(names).html_safe
27
27
  end
28
28
 
29
29
  def svg_icon(name, options={})
data/lib/esvg/helpers.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Esvg::Helpers
2
- def embed_svgs
3
- Esvg.embed_svgs
2
+ def embed_svgs(names=[])
3
+ Esvg.embed_svgs(Array(names))
4
4
  end
5
5
 
6
6
  def svg_icon(name, options={})
data/lib/esvg/svg.rb CHANGED
@@ -5,6 +5,7 @@ module Esvg
5
5
 
6
6
  CONFIG = {
7
7
  path: Dir.pwd,
8
+ base_class: 'svg-icon',
8
9
  namespace: 'icon',
9
10
  namespace_after: true,
10
11
  font_size: '1em',
@@ -31,6 +32,7 @@ module Esvg
31
32
 
32
33
  def read_icons
33
34
  @files = {}
35
+ @svgs = {}
34
36
 
35
37
  find_files.each do |f|
36
38
  svg = File.read(f)
@@ -87,25 +89,36 @@ module Esvg
87
89
  styles.join("\n")
88
90
  end
89
91
 
90
- def html
92
+ def html(names=[])
93
+ names = Array(names) # In case a single string is passed
94
+
91
95
  if @files.empty?
92
96
  ''
93
97
  else
94
- svg = []
95
- svg << %Q{<svg class="icon-symbols" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none">}
96
98
  files.each do |name, contents|
97
- svg << contents.gsub(/<svg.+?>/, %Q{<symbol id="#{icon_name(name)}" #{dimensions(contents)}>}) # convert svg to symbols
99
+ @svgs[name] = contents.gsub(/<svg.+?>/, %Q{<symbol id="#{icon_name(name)}" #{dimensions(contents)}>}) # convert svg to symbols
98
100
  .gsub(/<\/svg/, '</symbol') # convert svg to symbols
99
101
  .gsub(/style=['"].+?['"]/, '') # remove inline styles
100
102
  .gsub(/\n/, '') # remove endlines
101
103
  .gsub(/\s{2,}/, ' ') # remove whitespace
102
104
  .gsub(/>\s+</, '><') # remove whitespace between tags
103
105
  end
104
- svg << %Q{</svg>}
105
- svg.join("\n")
106
+
107
+ if names.empty?
108
+ icons = @svgs
109
+ else
110
+ icons = @svgs.select { |k,v| names.include?(k) }
111
+ end
112
+
113
+ %Q{<svg class="icon-symbols" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none">#{icons.values.join("\n")}</svg>}
106
114
  end
107
115
  end
108
116
 
117
+ def svg_icon(name, options={})
118
+ name = icon_name(name)
119
+ %Q{<svg class="#{config[:base_class]} #{name} #{options[:class] || ""}"><use xlink:href="##{name}"/>#{title(options)}#{desc(options)}</svg>}.html_safe
120
+ end
121
+
109
122
  def config(options={})
110
123
  @config ||= begin
111
124
  paths = [options[:config_file], 'config/esvg.yml', 'esvg.yml'].compact
data/lib/esvg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Esvg
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esvg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
78
  - ".travis.yml"
79
+ - CHANGELOG.md
79
80
  - CODE_OF_CONDUCT.md
80
81
  - Gemfile
81
82
  - LICENSE.txt