inline_svg 0.6.2 → 0.6.3
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 +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +5 -3
- data/lib/inline_svg/action_view/helpers.rb +5 -1
- data/lib/inline_svg/io_resource.rb +20 -0
- data/lib/inline_svg/version.rb +1 -1
- data/lib/inline_svg.rb +1 -0
- data/spec/helpers/inline_svg_spec.rb +35 -0
- data/spec/io_resource_spec.rb +80 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61bd9c6cf28c29ebf83c1ced886bf9454a2e3c18
|
4
|
+
data.tar.gz: f6ddecc2e711e872d8c0c62eb08876a1ccfff832
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73e10466544c51fd1d52aa94a75520000da86d32c243440853f7e5cf7d330a35b55dac5508d954627d3bc3fd10e1e06f9eba155a3ed6e15c2cd3770a1b9bbb14
|
7
|
+
data.tar.gz: 44cff146215df03b09301c3b3bc8cd060b631250a619887a78ef67224ce42e78b2b970570be70e9a968c8725635110eaaeafccde236be1a269f89b3d998b11ec
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
5
|
## [Unreleased][unreleased]
|
6
|
+
- Nothing.
|
7
|
+
|
8
|
+
## [0.6.3] - 2016-04-19
|
9
|
+
### Added
|
10
|
+
- Accept `IO` objects as arguments to `inline_svg`. Thanks,
|
11
|
+
[@ASnow](https://github.com/ASnow).
|
12
|
+
|
13
|
+
## [0.6.2] - 2016-01-24
|
14
|
+
### Fixed
|
6
15
|
- Support Sprockets >= 3.0 and config.assets.precompile = false
|
7
16
|
|
8
17
|
## [0.6.1] - 2015-08-06
|
@@ -65,7 +74,9 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
|
|
65
74
|
### Added
|
66
75
|
- Basic Railtie and view helper to inline SVG documents to Rails views.
|
67
76
|
|
68
|
-
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.6.
|
77
|
+
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v0.6.3...HEAD
|
78
|
+
[0.6.2]: https://github.com/jamesmartin/inline_svg/compare/v0.6.2...v0.6.3
|
79
|
+
[0.6.2]: https://github.com/jamesmartin/inline_svg/compare/v0.6.1...v0.6.2
|
69
80
|
[0.6.1]: https://github.com/jamesmartin/inline_svg/compare/v0.6.0...v0.6.1
|
70
81
|
[0.6.0]: https://github.com/jamesmartin/inline_svg/compare/v0.5.3...v0.6.0
|
71
82
|
[0.5.3]: https://github.com/jamesmartin/inline_svg/compare/v0.5.2...v0.5.3
|
data/README.md
CHANGED
@@ -35,10 +35,12 @@ Or install it yourself as:
|
|
35
35
|
```
|
36
36
|
inline_svg(file_name, options={})
|
37
37
|
```
|
38
|
-
|
38
|
+
|
39
|
+
The `file_name` can be a full path to a file, the file's basename or an `IO`
|
40
|
+
object. The
|
39
41
|
actual path of the file on disk is resolved using
|
40
|
-
[Sprockets](://github.com/sstephenson/sprockets),
|
41
|
-
and fingerprint your SVG files like
|
42
|
+
[Sprockets](://github.com/sstephenson/sprockets) (when available), a naive file finder (`/public/assets/...`) or in the case of `IO` objects the SVG data is read from the object.
|
43
|
+
This means you can pre-process and fingerprint your SVG files like other Rails assets, or choose to find SVG data yourself.
|
42
44
|
|
43
45
|
Here's an example of embedding an SVG document and applying a 'class' attribute in
|
44
46
|
HAML:
|
@@ -6,7 +6,11 @@ module InlineSvg
|
|
6
6
|
module Helpers
|
7
7
|
def inline_svg(filename, transform_params={})
|
8
8
|
begin
|
9
|
-
svg_file =
|
9
|
+
svg_file = if InlineSvg::IOResource === filename
|
10
|
+
InlineSvg::IOResource.read filename
|
11
|
+
else
|
12
|
+
InlineSvg::AssetFile.named filename
|
13
|
+
end
|
10
14
|
rescue InlineSvg::AssetFile::FileNotFound
|
11
15
|
return "<svg><!-- SVG file not found: '#{filename}' --></svg>".html_safe
|
12
16
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module InlineSvg
|
2
|
+
module IOResource
|
3
|
+
def self.=== object
|
4
|
+
object.is_a?(IO) || object.is_a?(StringIO)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.default_for object
|
8
|
+
case object
|
9
|
+
when StringIO then ''
|
10
|
+
when IO then 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
def self.read object
|
14
|
+
start = object.pos
|
15
|
+
str = object.read
|
16
|
+
object.seek start
|
17
|
+
str
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/inline_svg/version.rb
CHANGED
data/lib/inline_svg.rb
CHANGED
@@ -4,6 +4,7 @@ require "inline_svg/asset_file"
|
|
4
4
|
require "inline_svg/finds_asset_paths"
|
5
5
|
require "inline_svg/static_asset_finder"
|
6
6
|
require "inline_svg/transform_pipeline"
|
7
|
+
require "inline_svg/io_resource"
|
7
8
|
|
8
9
|
require "inline_svg/railtie" if defined?(Rails)
|
9
10
|
require 'active_support/core_ext/string'
|
@@ -111,6 +111,41 @@ SVG
|
|
111
111
|
expect(helper.inline_svg('some-file', custom: 'some value')).to eq expected_output
|
112
112
|
end
|
113
113
|
end
|
114
|
+
|
115
|
+
end
|
116
|
+
context 'argument polimorphizm' do
|
117
|
+
let(:argument) { double('argument') }
|
118
|
+
it 'accept IO' do
|
119
|
+
expect(InlineSvg::IOResource).to receive(:===).with(argument).and_return(true)
|
120
|
+
expect(InlineSvg::IOResource).to receive(:read).with(argument)
|
121
|
+
expect(InlineSvg::AssetFile).to_not receive(:named)
|
122
|
+
helper.inline_svg(argument)
|
123
|
+
end
|
124
|
+
it 'accept filename' do
|
125
|
+
expect(InlineSvg::IOResource).to receive(:===).with(argument).and_return(false)
|
126
|
+
expect(InlineSvg::IOResource).to_not receive(:read)
|
127
|
+
expect(InlineSvg::AssetFile).to receive(:named).with(argument)
|
128
|
+
helper.inline_svg(argument)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
context 'when passed IO object argument' do
|
132
|
+
let(:io_object) { double('io_object') }
|
133
|
+
let(:file_path) { File.expand_path('../../files/example.svg', __FILE__) }
|
134
|
+
let(:answer) { File.read(file_path) }
|
135
|
+
it 'return valid svg' do
|
136
|
+
expect(InlineSvg::IOResource).to receive(:===).with(io_object).and_return(true)
|
137
|
+
expect(InlineSvg::IOResource).to receive(:read).with(io_object).and_return("<svg><!-- Test IO --></svg>")
|
138
|
+
output = helper.inline_svg(io_object)
|
139
|
+
expect(output).to eq "<svg><!-- Test IO --></svg>\n"
|
140
|
+
expect(output).to be_html_safe
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'return valid svg for file' do
|
144
|
+
output = helper.inline_svg(File.new(file_path))
|
145
|
+
expect(output).to eq "<svg xmlns=\"http://www.w3.org/2000/svg\" xml:lang=\"en\" role=\"presentation\"><!-- This is a test comment --></svg>\n"
|
146
|
+
expect(output).to be_html_safe
|
147
|
+
end
|
148
|
+
|
114
149
|
end
|
115
150
|
end
|
116
151
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require_relative '../lib/inline_svg'
|
2
|
+
require "stringio"
|
3
|
+
require "tempfile"
|
4
|
+
|
5
|
+
describe InlineSvg::IOResource do
|
6
|
+
it "support api methods" do
|
7
|
+
is_expected.to respond_to(:===, :read)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#===' do
|
11
|
+
context 'return true' do
|
12
|
+
it "for IO object" do
|
13
|
+
read_io, write_io = IO.pipe
|
14
|
+
expect(subject === read_io).to be true
|
15
|
+
expect(subject === write_io).to be true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "for StringIO object" do
|
19
|
+
expect(subject === StringIO.new).to be true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "for File object" do
|
23
|
+
expect(subject === File.new("#{Dir.tmpdir}/testfile", "w")).to be true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
context 'return false' do
|
27
|
+
it "for String object" do
|
28
|
+
expect(subject === "string/filename").to be false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#read' do
|
34
|
+
|
35
|
+
tests = proc do
|
36
|
+
it "closed raise error" do
|
37
|
+
rio.close
|
38
|
+
expect do
|
39
|
+
subject.read(rio)
|
40
|
+
end.to raise_error(IOError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "empty" do
|
44
|
+
rio.read
|
45
|
+
expect(subject.read rio).to eq ''
|
46
|
+
end
|
47
|
+
|
48
|
+
it "twice" do
|
49
|
+
expect(subject.read rio).to eq answer
|
50
|
+
expect(subject.read rio).to eq answer
|
51
|
+
end
|
52
|
+
|
53
|
+
it "write only raise error" do
|
54
|
+
expect do
|
55
|
+
subject.read wio
|
56
|
+
end.to raise_error(IOError)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'IO object' do
|
61
|
+
let(:answer) { 'read' }
|
62
|
+
let(:rio) { StringIO.new(answer, 'r') }
|
63
|
+
let(:wio) { StringIO.new('write', 'w') }
|
64
|
+
instance_exec &tests
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'File object' do
|
68
|
+
let(:file_path) { File.expand_path('../files/example.svg', __FILE__) }
|
69
|
+
let(:answer) { File.read(file_path) }
|
70
|
+
let(:rio) { File.new(file_path, 'r') }
|
71
|
+
let(:wio) { File.new('/dev/null', 'w') }
|
72
|
+
instance_exec &tests
|
73
|
+
it 'has non empty body' do
|
74
|
+
expect(answer).to_not eq ''
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
end
|
80
|
+
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.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Martin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/inline_svg/action_view/helpers.rb
|
113
113
|
- lib/inline_svg/asset_file.rb
|
114
114
|
- lib/inline_svg/finds_asset_paths.rb
|
115
|
+
- lib/inline_svg/io_resource.rb
|
115
116
|
- lib/inline_svg/railtie.rb
|
116
117
|
- lib/inline_svg/static_asset_finder.rb
|
117
118
|
- lib/inline_svg/transform_pipeline.rb
|
@@ -133,6 +134,7 @@ files:
|
|
133
134
|
- spec/finds_asset_paths_spec.rb
|
134
135
|
- spec/helpers/inline_svg_spec.rb
|
135
136
|
- spec/inline_svg_spec.rb
|
137
|
+
- spec/io_resource_spec.rb
|
136
138
|
- spec/transformation_pipeline/transformations/data_attributes_spec.rb
|
137
139
|
- spec/transformation_pipeline/transformations/height_spec.rb
|
138
140
|
- spec/transformation_pipeline/transformations/id_attribute_spec.rb
|
@@ -170,6 +172,7 @@ test_files:
|
|
170
172
|
- spec/finds_asset_paths_spec.rb
|
171
173
|
- spec/helpers/inline_svg_spec.rb
|
172
174
|
- spec/inline_svg_spec.rb
|
175
|
+
- spec/io_resource_spec.rb
|
173
176
|
- spec/transformation_pipeline/transformations/data_attributes_spec.rb
|
174
177
|
- spec/transformation_pipeline/transformations/height_spec.rb
|
175
178
|
- spec/transformation_pipeline/transformations/id_attribute_spec.rb
|