inline_svg 1.2.0 → 1.2.1

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: 9af50a1ce42f8f67f9df531b740b4d0f8adedc2b
4
- data.tar.gz: 4c4399fffe814ff7587851cefd33deb3cb1910ce
3
+ metadata.gz: d0744ec1e4d10792a793f1214439367b2d94fd3b
4
+ data.tar.gz: 23dd2ee7f07558d6c2e27d97da29815bbbdc94d5
5
5
  SHA512:
6
- metadata.gz: d0facb0d977943f429edd52e7ac6307b3c092dd53a16bd694214048157a3b128cbdd6eb8c168f9a71889837a4427e30b1e97ffffd4b55fd353c87e6aae798fca
7
- data.tar.gz: 1e3e2fe9c6f563bd654fbbba92a216eef5efa340f2d755807ad2934d4b1bccf1bb70877f8ee74e2e1c5192aa8edef894f175f19890c76e6882eeec9e25deab48
6
+ metadata.gz: 85ae8c8c0288d74353a1c6636ab731f0af647204e4c8b59460c9a76f60c872c353a3f7c25a2e6d99e44bf74b9bcb6e87e7e7df7f2c7cec086e88ca6e10e82fa5
7
+ data.tar.gz: a4a4059fedc579a1321471e249e290d078626a96d4a268e78911db79c496d3e39ed7bf271c04833654bd5a3ea5c3cc4f0e66f0e32a0040fc8448ba9d97dca127
data/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  ## [Unreleased][unreleased]
6
6
  - Nothing
7
7
 
8
+ ## [1.2.1] - 2017-05-02
9
+ ### Fixed
10
+ - Select most exactly matching cached asset file when multiple files match
11
+ given asset name [#64](https://github.com/jamesmartin/inline_svg/pull/64)
12
+
8
13
  ## [1.2.0] - 2017-04-20
9
14
  ### Added
10
15
  - Cached asset file (load assets into memory at boot time)
@@ -154,7 +159,8 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
154
159
  ### Added
155
160
  - Basic Railtie and view helper to inline SVG documents to Rails views.
156
161
 
157
- [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.2.0...HEAD
162
+ [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.2.1...HEAD
163
+ [1.2.1]: https://github.com/jamesmartin/inline_svg/compare/v1.2.0...v1.2.1
158
164
  [1.2.0]: https://github.com/jamesmartin/inline_svg/compare/v1.1.0...v1.2.0
159
165
  [1.1.0]: https://github.com/jamesmartin/inline_svg/compare/v1.0.1...v1.1.0
160
166
  [1.0.1]: https://github.com/jamesmartin/inline_svg/compare/v1.0.0...v1.0.1
@@ -31,11 +31,25 @@ module InlineSvg
31
31
  end
32
32
 
33
33
  private
34
- # Internal: Finds the key for a given asset name (using a Regex).
34
+ # Internal: Finds the key for a given asset name (using a Regex). In the
35
+ # event of an ambiguous asset_name matching multiple assets, this method
36
+ # ranks the matches by their full file path, choosing the shortest (most
37
+ # exact) match over all others.
35
38
  #
36
- # Returns a String representing the key for the named asset.
39
+ # Returns a String representing the key for the named asset or nil if there
40
+ # is no match.
37
41
  def key_for_asset(asset_name)
38
- assets.keys.map { |k| k.to_s }.select { |k| /#{asset_name}/.match(k) }.first
42
+ match = all_keys_matching(asset_name).sort do |a, b|
43
+ a.string.size <=> b.string.size
44
+ end.first
45
+ match && match.string
46
+ end
47
+
48
+ # Internal: Find all potential asset keys matching the given asset name.
49
+ #
50
+ # Returns an array of MatchData objects for keys matching the asset name.
51
+ def all_keys_matching(asset_name)
52
+ assets.keys.map { |k| /(#{asset_name})/.match(k.to_s) }.compact
39
53
  end
40
54
 
41
55
  # Internal: Recursively descends through current_paths reading each file it
@@ -1,3 +1,3 @@
1
1
  module InlineSvg
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -34,6 +34,18 @@ describe InlineSvg::CachedAssetFile do
34
34
  expect(known_document_1).to eq(asset_loader.named("assets1/known-document.svg"))
35
35
  end
36
36
 
37
+ it "chooses the closest exact matching file when similar files exist in the same path" do
38
+ known_document = File.read(fixture_path.join("assets0", "known-document.svg"))
39
+ known_document_2 = File.read(fixture_path.join("assets0", "known-document-two.svg"))
40
+
41
+ expect(known_document).not_to eq(known_document_2)
42
+
43
+ asset_loader = InlineSvg::CachedAssetFile.new(paths: fixture_path.join("assets0"), filters: /\.svg/)
44
+
45
+ expect(asset_loader.named("known-document")).to eq(known_document)
46
+ expect(asset_loader.named("known-document-two")).to eq(known_document_2)
47
+ end
48
+
37
49
  it "filters wanted files by simple string matching" do
38
50
  known_document_0 = File.read(fixture_path.join("assets0", "known-document.svg"))
39
51
  known_document_1 = File.read(fixture_path.join("assets1", "known-document.svg"))
@@ -0,0 +1 @@
1
+ <svg>other interesting content</svg>
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: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-20 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,7 @@ files:
150
150
  - spec/asset_file_spec.rb
151
151
  - spec/cached_asset_file_spec.rb
152
152
  - spec/files/example.svg
153
+ - spec/files/static_assets/assets0/known-document-two.svg
153
154
  - spec/files/static_assets/assets0/known-document.svg
154
155
  - spec/files/static_assets/assets0/some-document.svg
155
156
  - spec/files/static_assets/assets1/known-document.svg
@@ -199,6 +200,7 @@ test_files:
199
200
  - spec/asset_file_spec.rb
200
201
  - spec/cached_asset_file_spec.rb
201
202
  - spec/files/example.svg
203
+ - spec/files/static_assets/assets0/known-document-two.svg
202
204
  - spec/files/static_assets/assets0/known-document.svg
203
205
  - spec/files/static_assets/assets0/some-document.svg
204
206
  - spec/files/static_assets/assets1/known-document.svg