Skip to content

Commit ba1349f

Browse files
authored
Merge pull request #186 from javierav/support-active-storage
Fix #144. Add support for Tempfile
2 parents 6df8316 + 933cd25 commit ba1349f

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
99
- Freeze string literals. [#172](https://github.com/jamesmartin/inline_svg/pull/172). Thanks, [@tagliala](https://github.com/tagliala)
1010
- Fix thread-local variable leakage in `with_asset_finder`. [#185](https://github.com/jamesmartin/inline_svg/pull/185). Thanks, [@tagliala](https://github.com/tagliala)
1111
- Remove unused `InlineSvg::IOResource.default_for` method. [#187](https://github.com/jamesmartin/inline_svg/pull/187). Thanks, [@tagliala](https://github.com/tagliala)
12+
- Add support for Tempfile. [#186](https://github.com/jamesmartin/inline_svg/pull/186). Thanks, [@javierav](https://github.com/javierav)
1213

1314
## [1.10.0] - 2024-09-03
1415
### Added

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ InlineSvg.configure do |config|
315315
end
316316
```
317317

318+
## ActiveStorage
319+
320+
```erb
321+
<%= user.avatar.open { |file| inline_svg_tag file } %>
322+
```
323+
318324
## Contributing
319325

320326
1. Fork it ( [http://github.com/jamesmartin/inline_svg/fork](http://github.com/jamesmartin/inline_svg/fork) )

lib/inline_svg/io_resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module InlineSvg
44
module IOResource
55
def self.===(object)
6-
object.is_a?(IO) || object.is_a?(StringIO)
6+
object.is_a?(IO) || object.is_a?(StringIO) || object.is_a?(Tempfile)
77
end
88

99
def self.read(object)

spec/io_resource_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
it "for File object" do
2525
expect(subject === File.new("#{Dir.tmpdir}/testfile", "w")).to be true
2626
end
27+
28+
it "for Tempfile object" do
29+
expect(subject === Tempfile.new).to be true
30+
end
2731
end
2832

2933
context 'return false' do
@@ -78,5 +82,18 @@
7882
expect(answer).not_to eq ''
7983
end
8084
end
85+
86+
context 'Tempfile object' do
87+
let(:answer) { 'read' }
88+
let(:rio) do
89+
Tempfile.new.tap do |f|
90+
f.write(answer)
91+
f.rewind
92+
end
93+
end
94+
let(:wio) { File.new(File::NULL, 'w') } # Tempfile cannot be created for write only mode
95+
96+
instance_exec(&tests)
97+
end
8198
end
8299
end

0 commit comments

Comments
 (0)