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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41039ec47d5e43fa34eaf787648e970efbf07c01
4
- data.tar.gz: 026d0ba494b8d333dee2c4fa1d73e1544c40a972
3
+ metadata.gz: 529e4c1b0bd2b16b4684a2cd241bdb707cd14e74
4
+ data.tar.gz: 86d782dd377e342b750e245001cbd50bba50dc71
5
5
  SHA512:
6
- metadata.gz: 361e754da8e05922c1575bee23500fc40d12675f06a925e35f64db3d9ce3716e2e2719509a710b1f0b3dbbeff2a7c3f8dbd1a4675eda5f72a2848b7aa2ede62b
7
- data.tar.gz: ed37e6ad6598811999e617f6919e759c2eb455d3e91be2e07bcb578c44d8a27a1a104b0087be35b2f57c0f83b022b8698fbfe2f93d06e93b2ddb99692a55b085
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
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "activesupport"
25
25
 
26
26
  spec.add_runtime_dependency "nokogiri", "~> 1.6", '~> 1.6'
27
+ spec.add_runtime_dependency "loofah", ">= 2.0"
27
28
  end
@@ -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]
@@ -1,3 +1,3 @@
1
1
  module InlineSvg
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  <svg xmlns="http://www.w3.org/2000/svg"
2
2
  xml:lang="en"
3
- role="presentation"></svg>
3
+ role="presentation"><!-- This is a comment --></svg>
@@ -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"></svg>
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 additional options' do
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"><title>A title</title>
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 # 'and additional options'
48
-
49
- end # 'when passed a SVG file'
50
-
51
- end #inline_svg
52
-
53
- end # describe InlineSvg::ActionView::Helpers
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.1.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-15 00:00:00.000000000 Z
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