esvg 1.0.0 → 1.1.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 +9 -0
- data/README.md +12 -5
- data/lib/esvg.rb +2 -2
- data/lib/esvg/helpers.rb +2 -2
- data/lib/esvg/svg.rb +19 -6
- data/lib/esvg/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c5712f3b740b3238193d1d2ef3d2babd708e8be
|
4
|
+
data.tar.gz: 9d04de7f13bd73bd42d72dcda666894a74bd89d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81f741e63a224d7385f574e7406f5898240bc0ba6f11083c2f5a35d0d9a33887a1d60f7bda7fe0d2f217cc8488ee01b3e8dcebd3c629deb27542fc6979cbd376
|
7
|
+
data.tar.gz: 82279d2eedce5e102b124fe63ba8f0a98da2a207aaaba018b7ff2b446a3e873ca30b060e0b827e39797c72f9c32259030ea3c8c56c2c755d439e1ed0f0615db4
|
data/CHANGELOG.md
ADDED
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
|
-
<
|
30
|
-
...
|
29
|
+
<body>
|
31
30
|
<%= embed_svgs %>
|
32
|
-
|
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
|
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
data/lib/esvg/helpers.rb
CHANGED
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
|
-
|
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
|
-
|
105
|
-
|
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
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.
|
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
|