inline_svg 1.2.0 → 1.3.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.

Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +421 -0
  4. data/CHANGELOG.md +35 -1
  5. data/README.md +46 -9
  6. data/Rakefile +7 -0
  7. data/inline_svg.gemspec +1 -0
  8. data/lib/inline_svg/action_view/helpers.rb +29 -6
  9. data/lib/inline_svg/cached_asset_file.rb +17 -3
  10. data/lib/inline_svg/id_generator.rb +9 -2
  11. data/lib/inline_svg/io_resource.rb +4 -3
  12. data/lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb +16 -19
  13. data/lib/inline_svg/transform_pipeline/transformations/aria_hidden.rb +9 -0
  14. data/lib/inline_svg/transform_pipeline/transformations/aria_hidden_attribute.rb +9 -0
  15. data/lib/inline_svg/transform_pipeline/transformations/class_attribute.rb +5 -6
  16. data/lib/inline_svg/transform_pipeline/transformations/data_attributes.rb +4 -5
  17. data/lib/inline_svg/transform_pipeline/transformations/description.rb +7 -6
  18. data/lib/inline_svg/transform_pipeline/transformations/height.rb +3 -4
  19. data/lib/inline_svg/transform_pipeline/transformations/id_attribute.rb +3 -4
  20. data/lib/inline_svg/transform_pipeline/transformations/no_comment.rb +4 -4
  21. data/lib/inline_svg/transform_pipeline/transformations/preserve_aspect_ratio.rb +3 -4
  22. data/lib/inline_svg/transform_pipeline/transformations/size.rb +4 -5
  23. data/lib/inline_svg/transform_pipeline/transformations/style_attribute.rb +11 -0
  24. data/lib/inline_svg/transform_pipeline/transformations/title.rb +7 -6
  25. data/lib/inline_svg/transform_pipeline/transformations/transformation.rb +13 -0
  26. data/lib/inline_svg/transform_pipeline/transformations/width.rb +3 -4
  27. data/lib/inline_svg/transform_pipeline/transformations.rb +4 -0
  28. data/lib/inline_svg/version.rb +1 -1
  29. data/lib/inline_svg.rb +16 -9
  30. data/spec/cached_asset_file_spec.rb +12 -0
  31. data/spec/files/static_assets/assets0/known-document-two.svg +1 -0
  32. data/spec/helpers/inline_svg_spec.rb +46 -1
  33. data/spec/id_generator_spec.rb +5 -3
  34. data/spec/inline_svg_spec.rb +10 -0
  35. data/spec/transformation_pipeline/transformations/aria_attributes_spec.rb +6 -6
  36. data/spec/transformation_pipeline/transformations/aria_hidden_attribute_spec.rb +12 -0
  37. data/spec/transformation_pipeline/transformations/height_spec.rb +9 -0
  38. data/spec/transformation_pipeline/transformations/style_attribute_spec.rb +26 -0
  39. data/spec/transformation_pipeline/transformations/title_spec.rb +9 -0
  40. data/spec/transformation_pipeline/transformations/transformation_spec.rb +39 -0
  41. data/spec/transformation_pipeline/transformations_spec.rb +5 -1
  42. metadata +30 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9af50a1ce42f8f67f9df531b740b4d0f8adedc2b
4
- data.tar.gz: 4c4399fffe814ff7587851cefd33deb3cb1910ce
3
+ metadata.gz: a9a81169096b9823dbcfa1c77af928523339ae95
4
+ data.tar.gz: 6d04934494ecd9a788a6eeef697abf4571d5accb
5
5
  SHA512:
6
- metadata.gz: d0facb0d977943f429edd52e7ac6307b3c092dd53a16bd694214048157a3b128cbdd6eb8c168f9a71889837a4427e30b1e97ffffd4b55fd353c87e6aae798fca
7
- data.tar.gz: 1e3e2fe9c6f563bd654fbbba92a216eef5efa340f2d755807ad2934d4b1bccf1bb70877f8ee74e2e1c5192aa8edef894f175f19890c76e6882eeec9e25deab48
6
+ metadata.gz: a94a7a7478d42bb94162461b548741aa5ca04ffa962b1a32aafa60432670226e9b79065493fe932cc18b0f5182d3b66899b919a683d00177308705740dd2e2d3
7
+ data.tar.gz: 46920e1ee1bacc5f3225a61c3391c3457c278888346507fbee50f4e4ce9e4bf800bec1e76f7c1a060aa331220e4afde349de289c1a454756f34813927e611a64
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,421 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-10-10 17:17:56 -0400 using RuboCop version 0.50.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 17
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
12
+ # SupportedStyles: leading, trailing
13
+ Layout/DotPosition:
14
+ Exclude:
15
+ - 'spec/finds_asset_paths_spec.rb'
16
+ - 'spec/helpers/inline_svg_spec.rb'
17
+ - 'spec/id_generator_spec.rb'
18
+ - 'spec/transformation_pipeline/transformations/aria_attributes_spec.rb'
19
+ - 'spec/transformation_pipeline/transformations/data_attributes_spec.rb'
20
+
21
+ # Offense count: 2
22
+ # Cop supports --auto-correct.
23
+ Layout/EmptyLineAfterMagicComment:
24
+ Exclude:
25
+ - 'inline_svg.gemspec'
26
+ - 'spec/cached_asset_file_spec.rb'
27
+
28
+ # Offense count: 1
29
+ # Cop supports --auto-correct.
30
+ # Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
31
+ Layout/EmptyLineBetweenDefs:
32
+ Exclude:
33
+ - 'spec/inline_svg_spec.rb'
34
+
35
+ # Offense count: 1
36
+ # Cop supports --auto-correct.
37
+ Layout/EmptyLinesAroundAccessModifier:
38
+ Exclude:
39
+ - 'lib/inline_svg/cached_asset_file.rb'
40
+
41
+ # Offense count: 8
42
+ # Cop supports --auto-correct.
43
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
44
+ # SupportedStyles: empty_lines, no_empty_lines
45
+ Layout/EmptyLinesAroundBlockBody:
46
+ Exclude:
47
+ - 'spec/helpers/inline_svg_spec.rb'
48
+ - 'spec/inline_svg_spec.rb'
49
+ - 'spec/io_resource_spec.rb'
50
+ - 'spec/transformation_pipeline/transformations_spec.rb'
51
+
52
+ # Offense count: 1
53
+ # Cop supports --auto-correct.
54
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
55
+ # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
56
+ Layout/EmptyLinesAroundClassBody:
57
+ Exclude:
58
+ - 'lib/inline_svg.rb'
59
+
60
+ # Offense count: 4
61
+ # Cop supports --auto-correct.
62
+ # Configuration parameters: SupportedStyles, IndentationWidth.
63
+ # SupportedStyles: special_inside_parentheses, consistent, align_brackets
64
+ Layout/IndentArray:
65
+ EnforcedStyle: consistent
66
+
67
+ # Offense count: 11
68
+ # Cop supports --auto-correct.
69
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
70
+ # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
71
+ Layout/IndentHeredoc:
72
+ Exclude:
73
+ - 'spec/helpers/inline_svg_spec.rb'
74
+
75
+ # Offense count: 1
76
+ # Cop supports --auto-correct.
77
+ Layout/LeadingCommentSpace:
78
+ Exclude:
79
+ - 'Rakefile'
80
+
81
+ # Offense count: 4
82
+ # Cop supports --auto-correct.
83
+ # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
84
+ # SupportedStyles: aligned, indented, indented_relative_to_receiver
85
+ Layout/MultilineMethodCallIndentation:
86
+ Exclude:
87
+ - 'spec/transformation_pipeline/transformations/data_attributes_spec.rb'
88
+ - 'spec/transformation_pipeline/transformations/style_attribute_spec.rb'
89
+
90
+ # Offense count: 2
91
+ # Cop supports --auto-correct.
92
+ # Configuration parameters: SupportedStyles.
93
+ # SupportedStyles: space, no_space
94
+ Layout/SpaceAroundEqualsInParameterDefault:
95
+ EnforcedStyle: no_space
96
+
97
+ # Offense count: 8
98
+ # Cop supports --auto-correct.
99
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
100
+ # SupportedStyles: space, no_space
101
+ # SupportedStylesForEmptyBraces: space, no_space
102
+ Layout/SpaceInsideBlockBraces:
103
+ Exclude:
104
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
105
+
106
+ # Offense count: 2
107
+ # Cop supports --auto-correct.
108
+ Layout/SpaceInsideBrackets:
109
+ Exclude:
110
+ - 'lib/inline_svg.rb'
111
+
112
+ # Offense count: 20
113
+ # Cop supports --auto-correct.
114
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces.
115
+ # SupportedStyles: space, no_space, compact
116
+ # SupportedStylesForEmptyBraces: space, no_space
117
+ Layout/SpaceInsideHashLiteralBraces:
118
+ Exclude:
119
+ - 'spec/helpers/inline_svg_spec.rb'
120
+ - 'spec/inline_svg_spec.rb'
121
+ - 'spec/transformation_pipeline/transformations/data_attributes_spec.rb'
122
+ - 'spec/transformation_pipeline/transformations_spec.rb'
123
+
124
+ # Offense count: 4
125
+ # Cop supports --auto-correct.
126
+ Layout/SpaceInsideParens:
127
+ Exclude:
128
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
129
+ - 'spec/helpers/inline_svg_spec.rb'
130
+
131
+ # Offense count: 3
132
+ # Cop supports --auto-correct.
133
+ Layout/TrailingWhitespace:
134
+ Exclude:
135
+ - 'spec/io_resource_spec.rb'
136
+
137
+ # Offense count: 2
138
+ Lint/AmbiguousOperator:
139
+ Exclude:
140
+ - 'spec/io_resource_spec.rb'
141
+
142
+ # Offense count: 2
143
+ Lint/ShadowingOuterLocalVariable:
144
+ Exclude:
145
+ - 'lib/inline_svg/transform_pipeline/transformations/description.rb'
146
+ - 'lib/inline_svg/transform_pipeline/transformations/title.rb'
147
+
148
+ # Offense count: 1
149
+ # Cop supports --auto-correct.
150
+ Lint/UnneededSplatExpansion:
151
+ Exclude:
152
+ - 'lib/inline_svg.rb'
153
+
154
+ # Offense count: 2
155
+ # Cop supports --auto-correct.
156
+ # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
157
+ Lint/UnusedBlockArgument:
158
+ Exclude:
159
+ - 'lib/inline_svg/railtie.rb'
160
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
161
+
162
+ # Offense count: 3
163
+ # Cop supports --auto-correct.
164
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
165
+ Lint/UnusedMethodArgument:
166
+ Exclude:
167
+ - 'spec/inline_svg_spec.rb'
168
+
169
+ # Offense count: 2
170
+ Lint/UselessAssignment:
171
+ Exclude:
172
+ - 'spec/cached_asset_file_spec.rb'
173
+ - 'spec/transformation_pipeline/transformations/transformation_spec.rb'
174
+
175
+ # Offense count: 1
176
+ Metrics/AbcSize:
177
+ Max: 17
178
+
179
+ # Offense count: 20
180
+ # Configuration parameters: CountComments, ExcludedMethods.
181
+ Metrics/BlockLength:
182
+ Max: 169
183
+
184
+ # Offense count: 144
185
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
186
+ # URISchemes: http, https
187
+ Metrics/LineLength:
188
+ Max: 183
189
+
190
+ # Offense count: 3
191
+ # Configuration parameters: CountComments.
192
+ Metrics/MethodLength:
193
+ Max: 14
194
+
195
+ # Offense count: 6
196
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
197
+ # SupportedStyles: snake_case, normalcase, non_integer
198
+ Naming/VariableNumber:
199
+ Exclude:
200
+ - 'spec/cached_asset_file_spec.rb'
201
+
202
+ # Offense count: 1
203
+ # Cop supports --auto-correct.
204
+ Performance/StringReplacement:
205
+ Exclude:
206
+ - 'lib/inline_svg/transform_pipeline/transformations/data_attributes.rb'
207
+
208
+ # Offense count: 1
209
+ # Cop supports --auto-correct.
210
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
211
+ # SupportedStyles: always, conditionals
212
+ Style/AndOr:
213
+ Exclude:
214
+ - 'lib/inline_svg/cached_asset_file.rb'
215
+
216
+ # Offense count: 1
217
+ # Cop supports --auto-correct.
218
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
219
+ # SupportedStyles: line_count_based, semantic, braces_for_chaining
220
+ # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
221
+ # FunctionalMethods: let, let!, subject, watch
222
+ # IgnoredMethods: lambda, proc, it
223
+ Style/BlockDelimiters:
224
+ Exclude:
225
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
226
+
227
+ # Offense count: 11
228
+ # Cop supports --auto-correct.
229
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
230
+ # SupportedStyles: braces, no_braces, context_dependent
231
+ Style/BracesAroundHashParameters:
232
+ Exclude:
233
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
234
+ - 'spec/helpers/inline_svg_spec.rb'
235
+ - 'spec/inline_svg_spec.rb'
236
+ - 'spec/transformation_pipeline/transformations/data_attributes_spec.rb'
237
+ - 'spec/transformation_pipeline/transformations_spec.rb'
238
+
239
+ # Offense count: 6
240
+ Style/CaseEquality:
241
+ Exclude:
242
+ - 'lib/inline_svg/action_view/helpers.rb'
243
+ - 'spec/io_resource_spec.rb'
244
+
245
+ # Offense count: 14
246
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
247
+ # SupportedStyles: nested, compact
248
+ Style/ClassAndModuleChildren:
249
+ Exclude:
250
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
251
+ - 'lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb'
252
+ - 'lib/inline_svg/transform_pipeline/transformations/class_attribute.rb'
253
+ - 'lib/inline_svg/transform_pipeline/transformations/data_attributes.rb'
254
+ - 'lib/inline_svg/transform_pipeline/transformations/description.rb'
255
+ - 'lib/inline_svg/transform_pipeline/transformations/height.rb'
256
+ - 'lib/inline_svg/transform_pipeline/transformations/id_attribute.rb'
257
+ - 'lib/inline_svg/transform_pipeline/transformations/no_comment.rb'
258
+ - 'lib/inline_svg/transform_pipeline/transformations/preserve_aspect_ratio.rb'
259
+ - 'lib/inline_svg/transform_pipeline/transformations/size.rb'
260
+ - 'lib/inline_svg/transform_pipeline/transformations/style_attribute.rb'
261
+ - 'lib/inline_svg/transform_pipeline/transformations/title.rb'
262
+ - 'lib/inline_svg/transform_pipeline/transformations/transformation.rb'
263
+ - 'lib/inline_svg/transform_pipeline/transformations/width.rb'
264
+
265
+ # Offense count: 26
266
+ Style/Documentation:
267
+ Enabled: false
268
+
269
+ # Offense count: 1
270
+ # Cop supports --auto-correct.
271
+ Style/EachWithObject:
272
+ Exclude:
273
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
274
+
275
+ # Offense count: 1
276
+ # Cop supports --auto-correct.
277
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AutoCorrectEncodingComment.
278
+ # SupportedStyles: when_needed, always, never
279
+ Style/Encoding:
280
+ Exclude:
281
+ - 'inline_svg.gemspec'
282
+
283
+ # Offense count: 4
284
+ # Configuration parameters: MinBodyLength.
285
+ Style/GuardClause:
286
+ Exclude:
287
+ - 'lib/inline_svg.rb'
288
+ - 'lib/inline_svg/action_view/helpers.rb'
289
+
290
+ # Offense count: 1
291
+ # Cop supports --auto-correct.
292
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
293
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
294
+ Style/HashSyntax:
295
+ Exclude:
296
+ - 'Rakefile'
297
+
298
+ # Offense count: 2
299
+ # Cop supports --auto-correct.
300
+ # Configuration parameters: MaxLineLength.
301
+ Style/IfUnlessModifier:
302
+ Exclude:
303
+ - 'lib/inline_svg/static_asset_finder.rb'
304
+ - 'lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb'
305
+
306
+ # Offense count: 1
307
+ # Cop supports --auto-correct.
308
+ # Configuration parameters: InverseMethods, InverseBlocks.
309
+ Style/InverseMethods:
310
+ Exclude:
311
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
312
+
313
+ # Offense count: 2
314
+ # Cop supports --auto-correct.
315
+ Style/MutableConstant:
316
+ Exclude:
317
+ - 'lib/inline_svg/asset_file.rb'
318
+ - 'lib/inline_svg/version.rb'
319
+
320
+ # Offense count: 3
321
+ # Cop supports --auto-correct.
322
+ # Configuration parameters: Whitelist.
323
+ # Whitelist: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with
324
+ Style/NestedParenthesizedCalls:
325
+ Exclude:
326
+ - 'spec/io_resource_spec.rb'
327
+
328
+ # Offense count: 1
329
+ # Cop supports --auto-correct.
330
+ # Configuration parameters: IncludeSemanticChanges.
331
+ Style/NonNilCheck:
332
+ Exclude:
333
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
334
+
335
+ # Offense count: 2
336
+ # Cop supports --auto-correct.
337
+ # Configuration parameters: PreferredDelimiters.
338
+ Style/PercentLiteralDelimiters:
339
+ Exclude:
340
+ - 'inline_svg.gemspec'
341
+
342
+ # Offense count: 6
343
+ # Cop supports --auto-correct.
344
+ # Configuration parameters: SupportedStyles.
345
+ # SupportedStyles: compact, exploded
346
+ Style/RaiseArgs:
347
+ EnforcedStyle: compact
348
+
349
+ # Offense count: 1
350
+ # Cop supports --auto-correct.
351
+ Style/RedundantBegin:
352
+ Exclude:
353
+ - 'lib/inline_svg.rb'
354
+
355
+ # Offense count: 8
356
+ # Cop supports --auto-correct.
357
+ Style/RedundantSelf:
358
+ Exclude:
359
+ - 'lib/inline_svg/transform_pipeline/transformations/data_attributes.rb'
360
+ - 'lib/inline_svg/transform_pipeline/transformations/height.rb'
361
+ - 'lib/inline_svg/transform_pipeline/transformations/id_attribute.rb'
362
+ - 'lib/inline_svg/transform_pipeline/transformations/preserve_aspect_ratio.rb'
363
+ - 'lib/inline_svg/transform_pipeline/transformations/size.rb'
364
+ - 'lib/inline_svg/transform_pipeline/transformations/transformation.rb'
365
+ - 'lib/inline_svg/transform_pipeline/transformations/width.rb'
366
+
367
+ # Offense count: 1
368
+ # Cop supports --auto-correct.
369
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
370
+ # SupportedStyles: slashes, percent_r, mixed
371
+ Style/RegexpLiteral:
372
+ Exclude:
373
+ - 'spec/transformation_pipeline/transformations/transformation_spec.rb'
374
+
375
+ # Offense count: 1
376
+ # Cop supports --auto-correct.
377
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
378
+ # SupportedStyles: use_perl_names, use_english_names
379
+ Style/SpecialGlobalVars:
380
+ Exclude:
381
+ - 'inline_svg.gemspec'
382
+
383
+ # Offense count: 280
384
+ # Cop supports --auto-correct.
385
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
386
+ # SupportedStyles: single_quotes, double_quotes
387
+ Style/StringLiterals:
388
+ Enabled: false
389
+
390
+ # Offense count: 3
391
+ # Cop supports --auto-correct.
392
+ # Configuration parameters: IgnoredMethods.
393
+ # IgnoredMethods: respond_to, define_method
394
+ Style/SymbolProc:
395
+ Exclude:
396
+ - 'lib/inline_svg/transform_pipeline/transformations/description.rb'
397
+ - 'lib/inline_svg/transform_pipeline/transformations/no_comment.rb'
398
+ - 'lib/inline_svg/transform_pipeline/transformations/title.rb'
399
+
400
+ # Offense count: 1
401
+ # Cop supports --auto-correct.
402
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline.
403
+ # SupportedStylesForMultiline: comma, consistent_comma, no_comma
404
+ Style/TrailingCommaInArguments:
405
+ Exclude:
406
+ - 'spec/transformation_pipeline/transformations_spec.rb'
407
+
408
+ # Offense count: 3
409
+ # Cop supports --auto-correct.
410
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline.
411
+ # SupportedStylesForMultiline: comma, consistent_comma, no_comma
412
+ Style/TrailingCommaInLiteral:
413
+ Exclude:
414
+ - 'lib/inline_svg/transform_pipeline/transformations.rb'
415
+ - 'spec/transformation_pipeline/transformations_spec.rb'
416
+
417
+ # Offense count: 2
418
+ # Cop supports --auto-correct.
419
+ Style/UnneededPercentQ:
420
+ Exclude:
421
+ - 'inline_svg.gemspec'
data/CHANGELOG.md CHANGED
@@ -5,6 +5,36 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5
5
  ## [Unreleased][unreleased]
6
6
  - Nothing
7
7
 
8
+ ## [1.2.4] - 2017-10-30
9
+ ### Added
10
+ - Aria hidden attribute
11
+ [#78](https://github.com/jamesmartin/inline_svg/pull/78)
12
+ and [#79](https://github.com/jamesmartin/inline_svg/pull/79)
13
+ - In-line CSS style attribute
14
+ [#71](https://github.com/jamesmartin/inline_svg/pull/71)
15
+
16
+ ### Fixed
17
+ - Make aria ID attributes unique
18
+ [#77](https://github.com/jamesmartin/inline_svg/pull/77)
19
+
20
+ ## [1.2.3] - 2017-08-17
21
+ ### Fixed
22
+ - Handle UTF-8 characters in SVG documents
23
+ [#60](https://github.com/jamesmartin/inline_svg/pull/69)
24
+
25
+ ## [1.2.2] - 2017-07-06
26
+ ### Fixed
27
+ - Handle malformed documents that don't contain a root SVG element
28
+ [#60](https://github.com/jamesmartin/inline_svg/pull/65)
29
+ ### Added
30
+ - Add configurable CSS class to empty SVG document
31
+ [#67](https://github.com/jamesmartin/inline_svg/pull/67)
32
+
33
+ ## [1.2.1] - 2017-05-02
34
+ ### Fixed
35
+ - Select most exactly matching cached asset file when multiple files match
36
+ given asset name [#64](https://github.com/jamesmartin/inline_svg/pull/64)
37
+
8
38
  ## [1.2.0] - 2017-04-20
9
39
  ### Added
10
40
  - Cached asset file (load assets into memory at boot time)
@@ -154,7 +184,11 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
154
184
  ### Added
155
185
  - Basic Railtie and view helper to inline SVG documents to Rails views.
156
186
 
157
- [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.2.0...HEAD
187
+ [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.2.4...HEAD
188
+ [1.2.4]: https://github.com/jamesmartin/inline_svg/compare/v1.2.3...v1.2.4
189
+ [1.2.3]: https://github.com/jamesmartin/inline_svg/compare/v1.2.2...v1.2.3
190
+ [1.2.2]: https://github.com/jamesmartin/inline_svg/compare/v1.2.1...v1.2.2
191
+ [1.2.1]: https://github.com/jamesmartin/inline_svg/compare/v1.2.0...v1.2.1
158
192
  [1.2.0]: https://github.com/jamesmartin/inline_svg/compare/v1.1.0...v1.2.0
159
193
  [1.1.0]: https://github.com/jamesmartin/inline_svg/compare/v1.0.1...v1.1.0
160
194
  [1.0.1]: https://github.com/jamesmartin/inline_svg/compare/v1.0.0...v1.0.1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Inline SVG
2
2
 
3
- [![CircleCI](https://circleci.com/gh/jamesmartin/inline_svg.svg?style=svg)](https://circleci.com/gh/jamesmartin/inline_svg)
3
+ [![Build Status](https://travis-ci.org/jamesmartin/inline_svg.svg?branch=master)](https://travis-ci.org/jamesmartin/inline_svg)
4
4
 
5
5
  Styling a SVG document with CSS for use on the web is most reliably achieved by
6
6
  [adding classes to the document and
@@ -71,12 +71,13 @@ blue:
71
71
  }
72
72
  ```
73
73
 
74
- ## Options
74
+ ## Options
75
75
 
76
76
  key | description
77
- :---------------------- | :----------
77
+ :---------------------- | :----------
78
78
  `id` | set a ID attribute on the SVG
79
79
  `class` | set a CSS class attribute on the SVG
80
+ `style` | set a CSS style attribute on the SVG
80
81
  `data` | add data attributes to the SVG (supply as a hash)
81
82
  `size` | set width and height attributes on the SVG <br/> Can also be set using `height` and/or `width` attributes, which take precedence over `size` <br/> Supplied as "{Width} * {Height}" or "{Number}", so "30px\*45px" becomes `width="30px"` and `height="45px"`, and "50%" becomes `width="50%"` and `height="50%"`
82
83
  `title` | add a \<title\> node inside the top level of the SVG document
@@ -84,12 +85,24 @@ key | description
84
85
  `nocomment` | remove comment tags from the SVG document
85
86
  `preserve_aspect_ratio` | adds a `preserveAspectRatio` attribute to the SVG
86
87
  `aria` | adds common accessibility attributes to the SVG (see [PR #34](https://github.com/jamesmartin/inline_svg/pull/34#issue-152062674) for details)
88
+ `aria_hidden` | adds the `aria-hidden=true` attribute to the SVG
87
89
 
88
90
  Example:
89
91
 
90
92
  ```ruby
91
- inline_svg("some-document.svg", id: 'some-id', class: 'some-class', data: {some: "value"}, size: '30% * 20%', title: 'Some Title', desc:
92
- 'Some description', nocomment: true, preserve_aspect_ratio: 'xMaxYMax meet', aria: true)
93
+ inline_svg(
94
+ "some-document.svg",
95
+ id: 'some-id',
96
+ class: 'some-class',
97
+ data: {some: "value"},
98
+ size: '30% * 20%',
99
+ title: 'Some Title',
100
+ desc: 'Some description',
101
+ nocomment: true,
102
+ preserve_aspect_ratio: 'xMaxYMax meet',
103
+ aria: true,
104
+ aria_hidden: true
105
+ )
93
106
  ```
94
107
 
95
108
  ## Accessibility
@@ -133,10 +146,9 @@ For example, inherit from `InlineSvg::CustomTransformation` and implement the `#
133
146
 
134
147
  class MyCustomTransform < InlineSvg::CustomTransformation
135
148
  def transform(doc)
136
- doc = Nokogiri::XML::Document.parse(doc.to_html)
137
- svg = doc.at_css 'svg'
138
- svg['custom'] = value
139
- doc
149
+ with_svg(doc) do |svg|
150
+ svg["custom"] = value
151
+ end
140
152
  end
141
153
  end
142
154
  ```
@@ -257,6 +269,31 @@ end
257
269
  restricted to as few paths as possible, and using the filter option to further
258
270
  restrict assets to only those likely to be used by `inline_svg`.
259
271
 
272
+ ## Missing SVG Files
273
+
274
+ If the specified SVG file cannot be found a helpful, empty SVG document is
275
+ embedded into the page instead. The embedded document contains a single comment
276
+ displaying the filename of the SVG image the helper tried to render:
277
+
278
+ ```html
279
+ <svg><!-- SVG file not found: 'some-missing-file.svg' --></svg>
280
+ ```
281
+
282
+ You may apply a class to this empty SVG document by specifying the following
283
+ configuration:
284
+
285
+ ```rb
286
+ InlineSvg.configure do |config|
287
+ config.svg_not_found_css_class = 'svg-not-found'
288
+ end
289
+ ```
290
+
291
+ Which would instead render:
292
+
293
+ ```html
294
+ <svg class='svg-not-found'><!-- SVG file not found: 'some-missing-file.svg' --></svg>
295
+ ```
296
+
260
297
  ## Contributing
261
298
 
262
299
  1. Fork it ( [http://github.com/jamesmartin/inline_svg/fork](http://github.com/jamesmartin/inline_svg/fork) )
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.pattern = Dir.glob("spec/**/*_spec.rb")
6
+ #t.rspec_opts = "--format documentation"
7
+ end
8
+ task :default => :spec
data/inline_svg.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec", "~> 3.2"
24
24
  spec.add_development_dependency "rspec_junit_formatter", "0.2.2"
25
25
  spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "rubocop"
26
27
 
27
28
  spec.add_runtime_dependency "activesupport", ">= 3.0"
28
29
  spec.add_runtime_dependency "nokogiri", ">= 1.6"
@@ -6,13 +6,17 @@ module InlineSvg
6
6
  module Helpers
7
7
  def inline_svg(filename, transform_params={})
8
8
  begin
9
- svg_file = if InlineSvg::IOResource === filename
10
- InlineSvg::IOResource.read filename
11
- else
12
- configured_asset_file.named filename
13
- end
9
+ svg_file = read_svg(filename)
14
10
  rescue InlineSvg::AssetFile::FileNotFound
15
- return "<svg><!-- SVG file not found: '#{filename}' #{extension_hint(filename)}--></svg>".html_safe
11
+ return placeholder(filename) unless transform_params[:fallback].present?
12
+
13
+ if transform_params[:fallback].present?
14
+ begin
15
+ svg_file = read_svg(transform_params[:fallback])
16
+ rescue InlineSvg::AssetFile::FileNotFound
17
+ placeholder(filename)
18
+ end
19
+ end
16
20
  end
17
21
 
18
22
  InlineSvg::TransformPipeline.generate_html_from(svg_file, transform_params).html_safe
@@ -20,6 +24,25 @@ module InlineSvg
20
24
 
21
25
  private
22
26
 
27
+ def read_svg(filename)
28
+ if InlineSvg::IOResource === filename
29
+ InlineSvg::IOResource.read filename
30
+ else
31
+ configured_asset_file.named filename
32
+ end
33
+ end
34
+
35
+ def placeholder(filename)
36
+ css_class = InlineSvg.configuration.svg_not_found_css_class
37
+ not_found_message = "'#{filename}' #{extension_hint(filename)}"
38
+
39
+ if css_class.nil?
40
+ return "<svg><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
41
+ else
42
+ return "<svg class='#{css_class}'><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
43
+ end
44
+ end
45
+
23
46
  def configured_asset_file
24
47
  InlineSvg.configuration.asset_file
25
48
  end
@@ -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