inline_svg 1.2.3 → 1.3.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: 40177208f78422aa2e769bc64df2000d092a2adb
4
- data.tar.gz: 75580ae0380f2888a6bbef173ce86bc85367637d
3
+ metadata.gz: a9a81169096b9823dbcfa1c77af928523339ae95
4
+ data.tar.gz: 6d04934494ecd9a788a6eeef697abf4571d5accb
5
5
  SHA512:
6
- metadata.gz: 7e566fcb2a17948b8208cabe2e8f85f220a4bde915e129cc062dc2c1894d996372d925b3cd1788d5319266fb95705fffa424a76b6017333e49649ecb51f93550
7
- data.tar.gz: 17a41bb9a990012a8d9fec96a05a4ee4464fd2975dfc8275fa88b97a81edc280b47ce1816a92d592967c4e70638f549a9ccca8de6aafc22bbff9b13d97e720ce
6
+ metadata.gz: a94a7a7478d42bb94162461b548741aa5ca04ffa962b1a32aafa60432670226e9b79065493fe932cc18b0f5182d3b66899b919a683d00177308705740dd2e2d3
7
+ data.tar.gz: 46920e1ee1bacc5f3225a61c3391c3457c278888346507fbee50f4e4ce9e4bf800bec1e76f7c1a060aa331220e4afde349de289c1a454756f34813927e611a64
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -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'
@@ -5,6 +5,18 @@ 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
+
8
20
  ## [1.2.3] - 2017-08-17
9
21
  ### Fixed
10
22
  - Handle UTF-8 characters in SVG documents
@@ -172,8 +184,9 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
172
184
  ### Added
173
185
  - Basic Railtie and view helper to inline SVG documents to Rails views.
174
186
 
175
- [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.2.3...HEAD
176
- [1.2.3]: https://github.com/jamesmartin/inline_svg/compare/v1.2.1...v1.2.3
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
177
190
  [1.2.2]: https://github.com/jamesmartin/inline_svg/compare/v1.2.1...v1.2.2
178
191
  [1.2.1]: https://github.com/jamesmartin/inline_svg/compare/v1.2.0...v1.2.1
179
192
  [1.2.0]: https://github.com/jamesmartin/inline_svg/compare/v1.1.0...v1.2.0
data/README.md CHANGED
@@ -77,6 +77,7 @@ 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
@@ -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"
@@ -37,14 +37,14 @@ module InlineSvg
37
37
  end
38
38
 
39
39
  def asset_finder=(finder)
40
- if finder.respond_to?(:find_asset)
41
- @asset_finder = finder
42
- else
43
- # fallback to a naive static asset finder (sprokects >= 3.0 &&
44
- # config.assets.precompile = false
45
- # See: https://github.com/jamesmartin/inline_svg/issues/25
46
- @asset_finder = InlineSvg::StaticAssetFinder
47
- end
40
+ @asset_finder = if finder.respond_to?(:find_asset)
41
+ finder
42
+ else
43
+ # fallback to a naive static asset finder
44
+ # (sprokects >= 3.0 && config.assets.precompile = false
45
+ # See: https://github.com/jamesmartin/inline_svg/issues/25
46
+ InlineSvg::StaticAssetFinder
47
+ end
48
48
  asset_finder
49
49
  end
50
50
 
@@ -6,16 +6,16 @@ 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
- if InlineSvg.configuration.svg_not_found_css_class.nil?
16
- return "<svg><!-- SVG file not found: '#{filename}' #{extension_hint(filename)}--></svg>".html_safe
17
- else
18
- return "<svg class='#{InlineSvg.configuration.svg_not_found_css_class}'><!-- 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
19
  end
20
20
  end
21
21
 
@@ -24,6 +24,25 @@ module InlineSvg
24
24
 
25
25
  private
26
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
+
27
46
  def configured_asset_file
28
47
  InlineSvg.configuration.asset_file
29
48
  end
@@ -1,7 +1,14 @@
1
1
  module InlineSvg
2
2
  class IdGenerator
3
- def self.generate(base, salt)
4
- bytes = Digest::SHA1.digest("#{base}-#{salt}")
3
+ class Randomness
4
+ require "securerandom"
5
+ def self.call
6
+ SecureRandom.hex(10)
7
+ end
8
+ end
9
+
10
+ def self.generate(base, salt, randomness: Randomness)
11
+ bytes = Digest::SHA1.digest("#{base}-#{salt}-#{randomness.call}")
5
12
  Digest.hexencode(bytes).to_i(16).to_s(36)
6
13
  end
7
14
  end
@@ -1,16 +1,17 @@
1
1
  module InlineSvg
2
2
  module IOResource
3
- def self.=== object
3
+ def self.===(object)
4
4
  object.is_a?(IO) || object.is_a?(StringIO)
5
5
  end
6
6
 
7
- def self.default_for object
7
+ def self.default_for(object)
8
8
  case object
9
9
  when StringIO then ''
10
10
  when IO then 1
11
11
  end
12
12
  end
13
- def self.read object
13
+
14
+ def self.read(object)
14
15
  start = object.pos
15
16
  str = object.read
16
17
  object.seek start
@@ -6,7 +6,9 @@ module InlineSvg::TransformPipeline::Transformations
6
6
  desc: { transform: Description, priority: 2 },
7
7
  title: { transform: Title, priority: 3 },
8
8
  aria: { transform: AriaAttributes },
9
+ aria_hidden: { transform: AriaHiddenAttribute },
9
10
  class: { transform: ClassAttribute },
11
+ style: { transform: StyleAttribute },
10
12
  data: { transform: DataAttributes },
11
13
  height: { transform: Height },
12
14
  nocomment: { transform: NoComment },
@@ -72,6 +74,7 @@ end
72
74
  require 'inline_svg/transform_pipeline/transformations/transformation'
73
75
  require 'inline_svg/transform_pipeline/transformations/no_comment'
74
76
  require 'inline_svg/transform_pipeline/transformations/class_attribute'
77
+ require 'inline_svg/transform_pipeline/transformations/style_attribute'
75
78
  require 'inline_svg/transform_pipeline/transformations/title'
76
79
  require 'inline_svg/transform_pipeline/transformations/description'
77
80
  require 'inline_svg/transform_pipeline/transformations/size'
@@ -81,3 +84,4 @@ require 'inline_svg/transform_pipeline/transformations/id_attribute'
81
84
  require 'inline_svg/transform_pipeline/transformations/data_attributes'
82
85
  require 'inline_svg/transform_pipeline/transformations/preserve_aspect_ratio'
83
86
  require 'inline_svg/transform_pipeline/transformations/aria_attributes'
87
+ require "inline_svg/transform_pipeline/transformations/aria_hidden_attribute"
@@ -0,0 +1,9 @@
1
+ module InlineSvg::TransformPipeline::Transformations
2
+ class AriaHidden < Transformation
3
+ def transform(doc)
4
+ with_svg(doc) do |svg|
5
+ svg["aria-hidden"] = self.value
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module InlineSvg::TransformPipeline::Transformations
2
+ class AriaHiddenAttribute < Transformation
3
+ def transform(doc)
4
+ with_svg(doc) do |svg|
5
+ svg["aria-hidden"] = self.value
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module InlineSvg::TransformPipeline::Transformations
2
+ class StyleAttribute < Transformation
3
+ def transform(doc)
4
+ with_svg(doc) do |svg|
5
+ styles = svg["style"].to_s.split(";")
6
+ styles << value
7
+ svg["style"] = styles.join(";")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module InlineSvg
2
- VERSION = "1.2.3"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -52,6 +52,20 @@ describe InlineSvg::ActionView::Helpers do
52
52
  expect(output).to eq "<svg class='missing-svg'><!-- SVG file not found: 'some-other-missing-file.svg' --></svg>"
53
53
  expect(output).to be_html_safe
54
54
  end
55
+
56
+ context "and a fallback that does exist" do
57
+ it "displays the fallback" do
58
+ allow(InlineSvg::AssetFile).to receive(:named).
59
+ with('missing.svg').
60
+ and_raise(InlineSvg::AssetFile::FileNotFound.new)
61
+
62
+ fallback_file = <<-SVG
63
+ <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>
64
+ SVG
65
+ allow(InlineSvg::AssetFile).to receive(:named).with('fallback.svg').and_return(fallback_file)
66
+ expect(helper.inline_svg('missing.svg', fallback: 'fallback.svg')).to eq fallback_file
67
+ end
68
+ end
55
69
  end
56
70
 
57
71
  context "when passed an existing SVG file" do
@@ -105,6 +119,19 @@ SVG
105
119
  end
106
120
  end
107
121
 
122
+ context "and the 'aria_hidden' option" do
123
+ it "sets 'aria-hidden=true' in the output" do
124
+ input_svg = <<-SVG
125
+ <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"></svg>
126
+ SVG
127
+ expected_output = <<-SVG
128
+ <svg xmlns="http://www.w3.org/2000/svg" xml:lang="en" aria-hidden="true"></svg>
129
+ SVG
130
+ allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)
131
+ expect(helper.inline_svg('some-file', aria_hidden: true)).to eq expected_output
132
+ end
133
+ end
134
+
108
135
  context "and all options" do
109
136
  it "applies all expected transformations to the output" do
110
137
  input_svg = <<-SVG
@@ -1,8 +1,10 @@
1
1
  require_relative '../lib/inline_svg/id_generator'
2
2
 
3
3
  describe InlineSvg::IdGenerator do
4
- it "generates a hexencoded ID based on a salt" do
5
- expect(InlineSvg::IdGenerator.generate("some-base", "some-salt")).
6
- to eq("ksiuuy1jduycacqpoj5smn2kyt9iv02")
4
+ it "generates a hexencoded ID based on a salt and a random value" do
5
+ randomizer = -> { "some-random-value" }
6
+
7
+ expect(InlineSvg::IdGenerator.generate("some-base", "some-salt", randomness: randomizer)).
8
+ to eq("t2c17mkqnvopy36iccxspura7wnreqf")
7
9
  end
8
10
  end
@@ -0,0 +1,12 @@
1
+ require 'inline_svg/transform_pipeline'
2
+
3
+ describe InlineSvg::TransformPipeline::Transformations::AriaHiddenAttribute do
4
+ it "adds an aria-hidden='true' attribute to a SVG document" do
5
+ document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
6
+ transformation = InlineSvg::TransformPipeline::Transformations::AriaHiddenAttribute.create_with_value(true)
7
+
8
+ expect(transformation.transform(document).to_html).to eq(
9
+ "<svg aria-hidden=\"true\">Some document</svg>\n"
10
+ )
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ require "inline_svg/transform_pipeline"
2
+
3
+ describe InlineSvg::TransformPipeline::Transformations::ClassAttribute do
4
+ it "adds a style attribute to a SVG document" do
5
+ document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
6
+ transformation =
7
+ InlineSvg::TransformPipeline::Transformations::StyleAttribute
8
+ .create_with_value("padding: 10px")
9
+
10
+ expect(transformation.transform(document).to_html).to eq(
11
+ "<svg style=\"padding: 10px\">Some document</svg>\n"
12
+ )
13
+ end
14
+
15
+ it "preserves existing style attributes on a SVG document" do
16
+ xml = '<svg style="fill: red">Some document</svg>'
17
+ document = Nokogiri::XML::Document.parse(xml)
18
+ transformation =
19
+ InlineSvg::TransformPipeline::Transformations::StyleAttribute
20
+ .create_with_value("padding: 10px")
21
+
22
+ expect(transformation.transform(document).to_html).to eq(
23
+ "<svg style=\"fill: red;padding: 10px\">Some document</svg>\n"
24
+ )
25
+ end
26
+ end
@@ -15,6 +15,7 @@ describe InlineSvg::TransformPipeline::Transformations do
15
15
  transformations = InlineSvg::TransformPipeline::Transformations.lookup(
16
16
  nocomment: 'irrelevant',
17
17
  class: 'irrelevant',
18
+ style: 'irrelevant',
18
19
  title: 'irrelevant',
19
20
  desc: 'irrelevant',
20
21
  size: 'irrelevant',
@@ -24,11 +25,13 @@ describe InlineSvg::TransformPipeline::Transformations do
24
25
  data: 'irrelevant',
25
26
  preserve_aspect_ratio: 'irrelevant',
26
27
  aria: 'irrelevant',
28
+ aria_hidden: "true"
27
29
  )
28
30
 
29
31
  expect(transformations.map(&:class)).to match_array([
30
32
  InlineSvg::TransformPipeline::Transformations::NoComment,
31
33
  InlineSvg::TransformPipeline::Transformations::ClassAttribute,
34
+ InlineSvg::TransformPipeline::Transformations::StyleAttribute,
32
35
  InlineSvg::TransformPipeline::Transformations::Title,
33
36
  InlineSvg::TransformPipeline::Transformations::Description,
34
37
  InlineSvg::TransformPipeline::Transformations::Size,
@@ -37,7 +40,8 @@ describe InlineSvg::TransformPipeline::Transformations do
37
40
  InlineSvg::TransformPipeline::Transformations::IdAttribute,
38
41
  InlineSvg::TransformPipeline::Transformations::DataAttributes,
39
42
  InlineSvg::TransformPipeline::Transformations::PreserveAspectRatio,
40
- InlineSvg::TransformPipeline::Transformations::AriaAttributes
43
+ InlineSvg::TransformPipeline::Transformations::AriaAttributes,
44
+ InlineSvg::TransformPipeline::Transformations::AriaHiddenAttribute
41
45
  ])
42
46
  end
43
47
 
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.3
4
+ version: 1.3.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: 2017-08-16 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: activesupport
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +130,8 @@ extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
118
132
  - ".gitignore"
133
+ - ".rubocop.yml"
134
+ - ".rubocop_todo.yml"
119
135
  - CHANGELOG.md
120
136
  - Gemfile
121
137
  - LICENSE.txt
@@ -135,6 +151,8 @@ files:
135
151
  - lib/inline_svg/transform_pipeline.rb
136
152
  - lib/inline_svg/transform_pipeline/transformations.rb
137
153
  - lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb
154
+ - lib/inline_svg/transform_pipeline/transformations/aria_hidden.rb
155
+ - lib/inline_svg/transform_pipeline/transformations/aria_hidden_attribute.rb
138
156
  - lib/inline_svg/transform_pipeline/transformations/class_attribute.rb
139
157
  - lib/inline_svg/transform_pipeline/transformations/data_attributes.rb
140
158
  - lib/inline_svg/transform_pipeline/transformations/description.rb
@@ -143,6 +161,7 @@ files:
143
161
  - lib/inline_svg/transform_pipeline/transformations/no_comment.rb
144
162
  - lib/inline_svg/transform_pipeline/transformations/preserve_aspect_ratio.rb
145
163
  - lib/inline_svg/transform_pipeline/transformations/size.rb
164
+ - lib/inline_svg/transform_pipeline/transformations/style_attribute.rb
146
165
  - lib/inline_svg/transform_pipeline/transformations/title.rb
147
166
  - lib/inline_svg/transform_pipeline/transformations/transformation.rb
148
167
  - lib/inline_svg/transform_pipeline/transformations/width.rb
@@ -162,6 +181,7 @@ files:
162
181
  - spec/inline_svg_spec.rb
163
182
  - spec/io_resource_spec.rb
164
183
  - spec/transformation_pipeline/transformations/aria_attributes_spec.rb
184
+ - spec/transformation_pipeline/transformations/aria_hidden_attribute_spec.rb
165
185
  - spec/transformation_pipeline/transformations/class_attribute_spec.rb
166
186
  - spec/transformation_pipeline/transformations/data_attributes_spec.rb
167
187
  - spec/transformation_pipeline/transformations/description_spec.rb
@@ -169,6 +189,7 @@ files:
169
189
  - spec/transformation_pipeline/transformations/id_attribute_spec.rb
170
190
  - spec/transformation_pipeline/transformations/preserve_aspect_ratio_spec.rb
171
191
  - spec/transformation_pipeline/transformations/size_spec.rb
192
+ - spec/transformation_pipeline/transformations/style_attribute_spec.rb
172
193
  - spec/transformation_pipeline/transformations/title_spec.rb
173
194
  - spec/transformation_pipeline/transformations/transformation_spec.rb
174
195
  - spec/transformation_pipeline/transformations/width_spec.rb
@@ -213,6 +234,7 @@ test_files:
213
234
  - spec/inline_svg_spec.rb
214
235
  - spec/io_resource_spec.rb
215
236
  - spec/transformation_pipeline/transformations/aria_attributes_spec.rb
237
+ - spec/transformation_pipeline/transformations/aria_hidden_attribute_spec.rb
216
238
  - spec/transformation_pipeline/transformations/class_attribute_spec.rb
217
239
  - spec/transformation_pipeline/transformations/data_attributes_spec.rb
218
240
  - spec/transformation_pipeline/transformations/description_spec.rb
@@ -220,6 +242,7 @@ test_files:
220
242
  - spec/transformation_pipeline/transformations/id_attribute_spec.rb
221
243
  - spec/transformation_pipeline/transformations/preserve_aspect_ratio_spec.rb
222
244
  - spec/transformation_pipeline/transformations/size_spec.rb
245
+ - spec/transformation_pipeline/transformations/style_attribute_spec.rb
223
246
  - spec/transformation_pipeline/transformations/title_spec.rb
224
247
  - spec/transformation_pipeline/transformations/transformation_spec.rb
225
248
  - spec/transformation_pipeline/transformations/width_spec.rb