inline_svg 0.1.0 → 0.2.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.
Potentially problematic release.
This version of inline_svg might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/inline_svg.gemspec +1 -0
- data/lib/inline_svg/action_view/helpers.rb +7 -0
- data/lib/inline_svg/version.rb +1 -1
- data/spec/files/example.svg +1 -1
- data/spec/helpers/inline_svg_spec.rb +22 -12
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 529e4c1b0bd2b16b4684a2cd241bdb707cd14e74
|
4
|
+
data.tar.gz: 86d782dd377e342b750e245001cbd50bba50dc71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46dba646464d60a3df6cc59f27767a58ef482faee661a15bd93841f5c32aeb405a30b77fc0dc53bf3f12e74ab12edb2dac9b0bc3c35505388432701010263dec
|
7
|
+
data.tar.gz: 9ee8d699f27cd417bcdef5c42fc0036b7797d5fb5394c38fa7cfca576f1a16b3e3ee950f4cb082015d184ea0eebfedd26fd0c373777989e8e414b94326b9ad62
|
data/README.md
CHANGED
@@ -60,12 +60,14 @@ blue:
|
|
60
60
|
* `class`: set a CSS class attribute on the SVG
|
61
61
|
* `title`: add a \<title\> node inside the top level of the SVG document
|
62
62
|
* `desc`: add a \<desc\> node inside the top level of the SVG document
|
63
|
+
* `nocomment`: remove comment tags (and other unsafe/unknown tags) from svg
|
64
|
+
(uses the [Loofah](https://github.com/flavorjones/loofah) gem)
|
63
65
|
|
64
66
|
Example:
|
65
67
|
|
66
68
|
```
|
67
69
|
inline_svg("some-document.svg", class: 'some-class', title: 'Some Title', desc:
|
68
|
-
'Some interesting description')
|
70
|
+
'Some interesting description', nocomment: true)
|
69
71
|
```
|
70
72
|
|
71
73
|
## Contributing
|
data/inline_svg.gemspec
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'action_view/helpers' if defined?(Rails)
|
2
2
|
require 'action_view/context' if defined?(Rails)
|
3
3
|
require 'nokogiri'
|
4
|
+
require 'loofah'
|
4
5
|
|
5
6
|
module InlineSvg
|
6
7
|
module ActionView
|
@@ -8,6 +9,12 @@ module InlineSvg
|
|
8
9
|
def inline_svg(filename, options={})
|
9
10
|
file = File.read(Rails.root.join('app', 'assets', 'images', filename))
|
10
11
|
doc = Nokogiri::HTML::DocumentFragment.parse file
|
12
|
+
|
13
|
+
# remove comments from svg file
|
14
|
+
if options[:nocomment].present?
|
15
|
+
doc = Loofah.fragment(doc.to_s).scrub!(:strip)
|
16
|
+
end
|
17
|
+
|
11
18
|
svg = doc.at_css 'svg'
|
12
19
|
if options[:class]
|
13
20
|
svg['class'] = options[:class]
|
data/lib/inline_svg/version.rb
CHANGED
data/spec/files/example.svg
CHANGED
@@ -23,31 +23,41 @@ describe InlineSvg::ActionView::Helpers do
|
|
23
23
|
|
24
24
|
context 'when passed a SVG file' do
|
25
25
|
|
26
|
-
subject { mock_helper.inline_svg( 'mocked_path' ) }
|
26
|
+
subject { mock_helper.inline_svg( 'mocked_path' ).strip }
|
27
27
|
let(:example_svg) {
|
28
28
|
<<-SVG.sub(/\n$/, '')
|
29
|
-
<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"
|
29
|
+
<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><!-- This is a comment --></svg>
|
30
30
|
SVG
|
31
31
|
}
|
32
32
|
|
33
33
|
it { is_expected.to eql example_svg }
|
34
34
|
|
35
|
-
context 'and
|
35
|
+
context 'and title and description options' do
|
36
36
|
|
37
|
-
subject { mock_helper.inline_svg( 'mocked_path', title: 'A title', desc: 'A desc' ) }
|
37
|
+
subject { mock_helper.inline_svg( 'mocked_path', title: 'A title', desc: 'A desc' ).strip }
|
38
38
|
let(:example_svg) {
|
39
39
|
<<-SVG.sub(/\n$/, '')
|
40
|
-
<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"
|
40
|
+
<svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><!-- This is a comment --><title>A title</title>
|
41
41
|
<desc>A desc</desc></svg>
|
42
42
|
SVG
|
43
43
|
}
|
44
44
|
|
45
45
|
it { is_expected.to eql example_svg }
|
46
46
|
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'and the "nocomment" option' do
|
50
|
+
|
51
|
+
subject { mock_helper.inline_svg( 'mocked_path', nocomment: true).strip }
|
52
|
+
let(:example_svg) {
|
53
|
+
<<-SVG.sub(/\n$/, '')
|
54
|
+
<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>
|
55
|
+
SVG
|
56
|
+
}
|
57
|
+
|
58
|
+
it { is_expected.to eql example_svg }
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inline_svg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: loofah
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
83
97
|
description: Get an SVG into your view and then style it with CSS.
|
84
98
|
email:
|
85
99
|
- inline_svg@jmrtn.com
|