inline_svg 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

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: 4632d27f08baae878205e66ba52684fbd266dafa
4
- data.tar.gz: c4f1086d39318016ca1143f1cf43df3797f3f59d
3
+ metadata.gz: 41039ec47d5e43fa34eaf787648e970efbf07c01
4
+ data.tar.gz: 026d0ba494b8d333dee2c4fa1d73e1544c40a972
5
5
  SHA512:
6
- metadata.gz: 3a0319168f2a259c4c681e346f44d37fe83cd0cac6bcbcead70c4e89bb52e266a89ddbf891d1f2d6e27b6660f2bb3e7e37cfa98a5bfdf8f8003e66a44fe13797
7
- data.tar.gz: e258223c987a278b449a4a8b1eeecdbc93a5e4ca71090756b3cdd2eb82b1a959f2c82a1f9330de8c6d875de72826683f09685b7efb65c7ce901344f8b37e02c1
6
+ metadata.gz: 361e754da8e05922c1575bee23500fc40d12675f06a925e35f64db3d9ce3716e2e2719509a710b1f0b3dbbeff2a7c3f8dbd1a4675eda5f72a2848b7aa2ede62b
7
+ data.tar.gz: ed37e6ad6598811999e617f6919e759c2eb455d3e91be2e07bcb578c44d8a27a1a104b0087be35b2f57c0f83b022b8698fbfe2f93d06e93b2ddb99692a55b085
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
- # InlineSvg
1
+ # Inline Svg
2
2
 
3
- TODO: Write a gem description
3
+ Styling a SVG document with CSS for use on the web is most reliably achieved by
4
+ [adding classes to the document and
5
+ embedding](http://css-tricks.com/using-svg/) it inline in the HTML.
6
+
7
+ This gem is a little helper method (`inline_svg`) that reads an SVG document from a Rails
8
+ image directory, applies a CSS class attribute to the root of the document and
9
+ then embeds it into a view.
4
10
 
5
11
  ## Installation
6
12
 
@@ -18,11 +24,53 @@ Or install it yourself as:
18
24
 
19
25
  ## Usage
20
26
 
21
- TODO: Write usage instructions here
27
+ ```
28
+ inline_svg(file_name, options={})
29
+ ```
30
+
31
+ Currently, this little helper only works in the context of a Rails app. Here's
32
+ an example of embedding an SVG document and applying a 'class' attribute in
33
+ HAML:
34
+
35
+ ```
36
+ !!! 5
37
+ %html
38
+ %head
39
+ %title Embedded SVG Documents
40
+ %body
41
+ %h1 Embedded SVG Documents
42
+ %div
43
+ = inline_svg "some-document.svg", class: 'some-class'
44
+ ```
45
+
46
+ Here's some CSS to target the SVG, resize it and turn it an attractive shade of
47
+ blue:
48
+
49
+ ```
50
+ .some-class {
51
+ display: block;
52
+ margin: 0 auto;
53
+ fill: #3498db;
54
+ width: 5em;
55
+ height: 5em;
56
+ }
57
+ ```
58
+
59
+ ## Options
60
+ * `class`: set a CSS class attribute on the SVG
61
+ * `title`: add a \<title\> node inside the top level of the SVG document
62
+ * `desc`: add a \<desc\> node inside the top level of the SVG document
63
+
64
+ Example:
65
+
66
+ ```
67
+ inline_svg("some-document.svg", class: 'some-class', title: 'Some Title', desc:
68
+ 'Some interesting description')
69
+ ```
22
70
 
23
71
  ## Contributing
24
72
 
25
- 1. Fork it ( http://github.com/<my-github-username>/inline_svg/fork )
73
+ 1. Fork it ( [http://github.com/<my-github-username>/inline_svg/fork](http://github.com/<my-github-username>/inline_svg/fork) )
26
74
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
75
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
76
  4. Push to the branch (`git push origin my-new-feature`)
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.6"
24
+ spec.add_development_dependency "activesupport"
23
25
 
24
- spec.add_runtime_dependency "nokogiri", "~> 1.6"
26
+ spec.add_runtime_dependency "nokogiri", "~> 1.6", '~> 1.6'
25
27
  end
@@ -1,5 +1,6 @@
1
- require 'action_view/helpers'
2
- require 'action_view/context'
1
+ require 'action_view/helpers' if defined?(Rails)
2
+ require 'action_view/context' if defined?(Rails)
3
+ require 'nokogiri'
3
4
 
4
5
  module InlineSvg
5
6
  module ActionView
@@ -8,9 +9,19 @@ module InlineSvg
8
9
  file = File.read(Rails.root.join('app', 'assets', 'images', filename))
9
10
  doc = Nokogiri::HTML::DocumentFragment.parse file
10
11
  svg = doc.at_css 'svg'
11
- if options[:class].present?
12
+ if options[:class]
12
13
  svg['class'] = options[:class]
13
14
  end
15
+ if options[:title].present?
16
+ title = Nokogiri::XML::Node.new("title", doc)
17
+ title.content = options[:title]
18
+ svg.add_child title
19
+ end
20
+ if options[:desc].present?
21
+ desc = Nokogiri::XML::Node.new("desc", doc)
22
+ desc.content = options[:desc]
23
+ svg.add_child desc
24
+ end
14
25
  doc.to_html.html_safe
15
26
  end
16
27
  end
@@ -1,3 +1,3 @@
1
1
  module InlineSvg
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg"
2
+ xml:lang="en"
3
+ role="presentation"></svg>
@@ -0,0 +1,53 @@
1
+ require 'inline_svg'
2
+ require 'nokogiri'
3
+ require 'active_support/core_ext'
4
+
5
+ describe InlineSvg::ActionView::Helpers do
6
+
7
+ before(:each) do
8
+ # Mock Rails
9
+ unless defined?(::Rails)
10
+ @mocked_rails_class = true
11
+ class ::Rails
12
+ end
13
+ end
14
+ # Allow mock Rails to give a path to our SVG
15
+ path_mocker = double("path_mocker")
16
+ allow(path_mocker).to receive(:join) { 'spec/files/example.svg' }
17
+ allow(Rails).to receive(:root) { path_mocker }
18
+ end
19
+
20
+ let(:mock_helper) { ( Class.new { include InlineSvg::ActionView::Helpers } ).new }
21
+
22
+ describe "#inline_svg" do
23
+
24
+ context 'when passed a SVG file' do
25
+
26
+ subject { mock_helper.inline_svg( 'mocked_path' ) }
27
+ let(:example_svg) {
28
+ <<-SVG.sub(/\n$/, '')
29
+ <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"></svg>
30
+ SVG
31
+ }
32
+
33
+ it { is_expected.to eql example_svg }
34
+
35
+ context 'and additional options' do
36
+
37
+ subject { mock_helper.inline_svg( 'mocked_path', title: 'A title', desc: 'A desc' ) }
38
+ let(:example_svg) {
39
+ <<-SVG.sub(/\n$/, '')
40
+ <svg xmlns="http://www.w3.org/2000/svg" role="presentation" xml:lang="en"><title>A title</title>
41
+ <desc>A desc</desc></svg>
42
+ SVG
43
+ }
44
+
45
+ it { is_expected.to eql example_svg }
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
metadata CHANGED
@@ -1,55 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.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-11-21 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: nokogiri
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - ~>
73
+ - - "~>"
46
74
  - !ruby/object:Gem::Version
47
75
  version: '1.6'
48
76
  type: :runtime
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - ~>
80
+ - - "~>"
53
81
  - !ruby/object:Gem::Version
54
82
  version: '1.6'
55
83
  description: Get an SVG into your view and then style it with CSS.
@@ -59,7 +87,7 @@ executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
- - .gitignore
90
+ - ".gitignore"
63
91
  - Gemfile
64
92
  - LICENSE.txt
65
93
  - README.md
@@ -69,6 +97,8 @@ files:
69
97
  - lib/inline_svg/action_view/helpers.rb
70
98
  - lib/inline_svg/railtie.rb
71
99
  - lib/inline_svg/version.rb
100
+ - spec/files/example.svg
101
+ - spec/helpers/inline_svg_spec.rb
72
102
  homepage: ''
73
103
  licenses:
74
104
  - MIT
@@ -79,12 +109,12 @@ require_paths:
79
109
  - lib
80
110
  required_ruby_version: !ruby/object:Gem::Requirement
81
111
  requirements:
82
- - - '>='
112
+ - - ">="
83
113
  - !ruby/object:Gem::Version
84
114
  version: '0'
85
115
  required_rubygems_version: !ruby/object:Gem::Requirement
86
116
  requirements:
87
- - - '>='
117
+ - - ">="
88
118
  - !ruby/object:Gem::Version
89
119
  version: '0'
90
120
  requirements: []
@@ -93,4 +123,6 @@ rubygems_version: 2.2.2
93
123
  signing_key:
94
124
  specification_version: 4
95
125
  summary: Embeds an SVG document, inline.
96
- test_files: []
126
+ test_files:
127
+ - spec/files/example.svg
128
+ - spec/helpers/inline_svg_spec.rb