/
assets_helper.rb
752 lines (702 loc) · 23.6 KB
/
assets_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# frozen_string_literal: true
require "uri"
require "hanami/view"
# rubocop:disable Metrics/ModuleLength
module Hanami
module Helpers
# HTML assets helpers
#
# Inject these helpers in a view
#
# @since 0.1.0
#
# @see http://www.rubydoc.info/gems/hanami-helpers/Hanami/Helpers/HtmlHelper
module AssetsHelper
# @since 0.1.0
# @api private
NEW_LINE_SEPARATOR = "\n"
# @since 0.1.0
# @api private
WILDCARD_EXT = ".*"
# @since 0.1.0
# @api private
JAVASCRIPT_EXT = ".js"
# @since 0.1.0
# @api private
STYLESHEET_EXT = ".css"
# @since 0.1.0
# @api private
JAVASCRIPT_MIME_TYPE = "text/javascript"
# @since 0.1.0
# @api private
STYLESHEET_MIME_TYPE = "text/css"
# @since 0.1.0
# @api private
FAVICON_MIME_TYPE = "image/x-icon"
# @since 0.1.0
# @api private
STYLESHEET_REL = "stylesheet"
# @since 0.1.0
# @api private
FAVICON_REL = "shortcut icon"
# @since 0.1.0
# @api private
DEFAULT_FAVICON = "favicon.ico"
# @since 0.3.0
# @api private
CROSSORIGIN_ANONYMOUS = "anonymous"
# @since 0.3.0
# @api private
ABSOLUTE_URL_MATCHER = URI::DEFAULT_PARSER.make_regexp
# @since 1.1.0
# @api private
QUERY_STRING_MATCHER = /\?/
include Hanami::View::Helpers::TagHelper
# Generate `script` tag for given source(s)
#
# It accepts one or more strings representing the name of the asset, if it
# comes from the application or third party gems. It also accepts strings
# representing absolute URLs in case of public CDN (eg. jQuery CDN).
#
# If the "fingerprint mode" is on, `src` is the fingerprinted
# version of the relative URL.
#
# If the "CDN mode" is on, the `src` is an absolute URL of the
# application CDN.
#
# If the "subresource integrity mode" is on, `integriy` is the
# name of the algorithm, then a hyphen, then the hash value of the file.
# If more than one algorithm is used, they"ll be separated by a space.
#
# @param sources [Array<String>] one or more assets by name or absolute URL
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the javascript file is missing
# from the manifest
#
# @since 0.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Single Asset
#
# <%= js "application" %>
#
# # <script src="/assets/application.js" type="text/javascript"></script>
#
# @example Multiple Assets
#
# <%= js "application", "dashboard" %>
#
# # <script src="/assets/application.js" type="text/javascript"></script>
# # <script src="/assets/dashboard.js" type="text/javascript"></script>
#
# @example Asynchronous Execution
#
# <%= js "application", async: true %>
#
# # <script src="/assets/application.js" type="text/javascript" async="async"></script>
#
# @example Subresource Integrity
#
# <%= js "application" %>
#
# # <script src="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
# # type="text/javascript" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
#
# @example Subresource Integrity for 3rd Party Scripts
#
# <%= js "https://example.com/assets/example.js", integrity: "sha384-oqVu...Y8wC" %>
#
# # <script src="https://example.com/assets/example.js" type="text/javascript"
# # integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
#
# @example Deferred Execution
#
# <%= js "application", defer: true %>
#
# # <script src="/assets/application.js" type="text/javascript" defer="defer"></script>
#
# @example Absolute URL
#
# <%= js "https://code.jquery.com/jquery-2.1.4.min.js" %>
#
# # <script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
#
# @example Fingerprint Mode
#
# <%= js "application" %>
#
# # <script src="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js" type="text/javascript"></script>
#
# @example CDN Mode
#
# <%= js "application" %>
#
# # <script src="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
# # type="text/javascript"></script>
def javascript_tag(*source_paths, **options)
options = options.reject { |k, _| k.to_sym == :src }
_safe_tags(*source_paths) do |source|
attributes = {
src: _typed_path(source, JAVASCRIPT_EXT),
type: JAVASCRIPT_MIME_TYPE
}
attributes.merge!(options)
if _context.assets.subresource_integrity? || attributes.include?(:integrity)
attributes[:integrity] ||= _subresource_integrity_value(source, JAVASCRIPT_EXT)
attributes[:crossorigin] ||= CROSSORIGIN_ANONYMOUS
end
tag.script(**attributes).to_s
end
end
# @api public
# @since 2.1.0
alias_method :js, :javascript_tag
# Generate `link` tag for given source(s)
#
# It accepts one or more strings representing the name of the asset, if it
# comes from the application or third party gems. It also accepts strings
# representing absolute URLs in case of public CDN (eg. Bootstrap CDN).
#
# If the "fingerprint mode" is on, `href` is the fingerprinted
# version of the relative URL.
#
# If the "CDN mode" is on, the `href` is an absolute URL of the
# application CDN.
#
# If the "subresource integrity mode" is on, `integriy` is the
# name of the algorithm, then a hyphen, then the hashed value of the file.
# If more than one algorithm is used, they"ll be separated by a space.
#
# @param sources [Array<String>] one or more assets by name or absolute URL
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the stylesheet file is missing
# from the manifest
#
# @since 0.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Single Asset
#
# <%= css "application" %>
#
# # <link href="/assets/application.css" type="text/css" rel="stylesheet">
#
# @example Multiple Assets
#
# <%= css "application", "dashboard" %>
#
# # <link href="/assets/application.css" type="text/css" rel="stylesheet">
# # <link href="/assets/dashboard.css" type="text/css" rel="stylesheet">
#
# @example Subresource Integrity
#
# <%= css "application" %>
#
# # <link href="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css"
# # type="text/css" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
#
# @example Subresource Integrity for 3rd Party Assets
#
# <%= css "https://example.com/assets/example.css", integrity: "sha384-oqVu...Y8wC" %>
#
# # <link href="https://example.com/assets/example.css"
# # type="text/css" rel="stylesheet" integrity="sha384-oqVu...Y8wC" crossorigin="anonymous"></script>
#
# @example Absolute URL
#
# <%= css "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" %>
#
# # <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
# # type="text/css" rel="stylesheet">
#
# @example Fingerprint Mode
#
# <%= css "application" %>
#
# # <link href="/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css" type="text/css" rel="stylesheet">
#
# @example CDN Mode
#
# <%= css "application" %>
#
# # <link href="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css"
# # type="text/css" rel="stylesheet">
def stylesheet_link_tag(*source_paths, **options)
options = options.reject { |k, _| k.to_sym == :href }
_safe_tags(*source_paths) do |source_path|
attributes = {
href: _typed_path(source_path, STYLESHEET_EXT),
type: STYLESHEET_MIME_TYPE,
rel: STYLESHEET_REL
}
attributes.merge!(options)
if _context.assets.subresource_integrity? || attributes.include?(:integrity)
attributes[:integrity] ||= _subresource_integrity_value(source_path, STYLESHEET_EXT)
attributes[:crossorigin] ||= CROSSORIGIN_ANONYMOUS
end
tag.link(**attributes).to_s
end
end
# @api public
# @since 2.1.0
alias_method :css, :stylesheet_link_tag
# Generate `img` tag for given source
#
# It accepts one string representing the name of the asset, if it comes
# from the application or third party gems. It also accepts string
# representing absolute URLs in case of public CDN (eg. Bootstrap CDN).
#
# `alt` Attribute is auto generated from `src`.
# You can specify a different value, by passing the `:src` option.
#
# If the "fingerprint mode" is on, `src` is the fingerprinted
# version of the relative URL.
#
# If the "CDN mode" is on, the `src` is an absolute URL of the
# application CDN.
#
# @param source [String] asset name or absolute URL
# @param options [Hash] HTML 5 attributes
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the image file is missing
# from the manifest
#
# @since 0.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Basic Usage
#
# <%= image_tag "logo.png" %>
#
# # <img src="/assets/logo.png" alt="Logo">
#
# @example Custom alt Attribute
#
# <%= image_tag "logo.png", alt: "Application Logo" %>
#
# # <img src="/assets/logo.png" alt="Application Logo">
#
# @example Custom HTML Attributes
#
# <%= image_tag "logo.png", id: "logo", class: "image" %>
#
# # <img src="/assets/logo.png" alt="Logo" id="logo" class="image">
#
# @example Absolute URL
#
# <%= image_tag "https://example-cdn.com/images/logo.png" %>
#
# # <img src="https://example-cdn.com/images/logo.png" alt="Logo">
#
# @example Fingerprint Mode
#
# <%= image_tag "logo.png" %>
#
# # <img src="/assets/logo-28a6b886de2372ee3922fcaf3f78f2d8.png" alt="Logo">
#
# @example CDN Mode
#
# <%= image_tag "logo.png" %>
#
# # <img src="https://assets.bookshelf.org/assets/logo-28a6b886de2372ee3922fcaf3f78f2d8.png" alt="Logo">
def image_tag(source, options = {})
options = options.reject { |k, _| k.to_sym == :src }
attributes = {
src: asset_url(source),
alt: _context.inflector.humanize(::File.basename(source, WILDCARD_EXT))
}
attributes.merge!(options)
tag.img(**attributes)
end
# Generate `link` tag application favicon.
#
# If no argument is given, it assumes `favico.ico` from the application.
#
# It accepts one string representing the name of the asset.
#
# If the "fingerprint mode" is on, `href` is the fingerprinted version
# of the relative URL.
#
# If the "CDN mode" is on, the `href` is an absolute URL of the
# application CDN.
#
# @param source [String] asset name
# @param options [Hash] HTML 5 attributes
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the favicon is file missing
# from the manifest
#
# @since 0.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Basic Usage
#
# <%= favicon_link_tag %>
#
# # <link href="/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">
#
# @example Custom Path
#
# <%= favicon_link_tag "fav.ico" %>
#
# # <link href="/assets/fav.ico" rel="shortcut icon" type="image/x-icon">
#
# @example Custom HTML Attributes
#
# <%= favicon_link_tag "favicon.ico", id: "fav" %>
#
# # <link id: "fav" href="/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">
#
# @example Fingerprint Mode
#
# <%= favicon_link_tag %>
#
# # <link href="/assets/favicon-28a6b886de2372ee3922fcaf3f78f2d8.ico" rel="shortcut icon" type="image/x-icon">
#
# @example CDN Mode
#
# <%= favicon_link_tag %>
#
# # <link href="https://assets.bookshelf.org/assets/favicon-28a6b886de2372ee3922fcaf3f78f2d8.ico"
# rel="shortcut icon" type="image/x-icon">
def favicon_link_tag(source = DEFAULT_FAVICON, options = {})
options = options.reject { |k, _| k.to_sym == :href }
attributes = {
href: asset_url(source),
rel: FAVICON_REL,
type: FAVICON_MIME_TYPE
}
attributes.merge!(options)
tag.link(**attributes)
end
# @api public
# @since 2.1.0
alias_method :favicon, :favicon_link_tag
# Generate `video` tag for given source
#
# It accepts one string representing the name of the asset, if it comes
# from the application or third party gems. It also accepts string
# representing absolute URLs in case of public CDN (eg. Bootstrap CDN).
#
# Alternatively, it accepts a block that allows to specify one or more
# sources via the `source` tag.
#
# If the "fingerprint mode" is on, `src` is the fingerprinted
# version of the relative URL.
#
# If the "CDN mode" is on, the `src` is an absolute URL of the
# application CDN.
#
# @param source [String] asset name or absolute URL
# @param options [Hash] HTML 5 attributes
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the video file is missing
# from the manifest
#
# @raise [ArgumentError] if source isn"t specified both as argument or
# tag inside the given block
#
# @since 0.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Basic Usage
#
# <%= video_tag "movie.mp4" %>
#
# # <video src="/assets/movie.mp4"></video>
#
# @example Absolute URL
#
# <%= video_tag "https://example-cdn.com/assets/movie.mp4" %>
#
# # <video src="https://example-cdn.com/assets/movie.mp4"></video>
#
# @example Custom HTML Attributes
#
# <%= video_tag("movie.mp4", autoplay: true, controls: true) %>
#
# # <video src="/assets/movie.mp4" autoplay="autoplay" controls="controls"></video>
#
# @example Fallback Content
#
# <%=
# video_tag("movie.mp4") do
# "Your browser does not support the video tag"
# end
# %>
#
# # <video src="/assets/movie.mp4">
# # Your browser does not support the video tag
# # </video>
#
# @example Tracks
#
# <%=
# video_tag("movie.mp4") do
# tag.track(kind: "captions", src: asset_url("movie.en.vtt"),
# srclang: "en", label: "English")
# end
# %>
#
# # <video src="/assets/movie.mp4">
# # <track kind="captions" src="/assets/movie.en.vtt" srclang="en" label="English">
# # </video>
#
# @example Without Any Argument
#
# <%= video_tag %>
#
# # ArgumentError
#
# @example Without src And Without Block
#
# <%= video_tag(content: true) %>
#
# # ArgumentError
#
# @example Fingerprint Mode
#
# <%= video_tag "movie.mp4" %>
#
# # <video src="/assets/movie-28a6b886de2372ee3922fcaf3f78f2d8.mp4"></video>
#
# @example CDN Mode
#
# <%= video_tag "movie.mp4" %>
#
# # <video src="https://assets.bookshelf.org/assets/movie-28a6b886de2372ee3922fcaf3f78f2d8.mp4"></video>
def video_tag(source = nil, options = {}, &blk)
options = _source_options(source, options, &blk)
tag.video(**options, &blk)
end
# Generate `audio` tag for given source
#
# It accepts one string representing the name of the asset, if it comes
# from the application or third party gems. It also accepts string
# representing absolute URLs in case of public CDN (eg. Bootstrap CDN).
#
# Alternatively, it accepts a block that allows to specify one or more
# sources via the `source` tag.
#
# If the "fingerprint mode" is on, `src` is the fingerprinted
# version of the relative URL.
#
# If the "CDN mode" is on, the `src` is an absolute URL of the
# application CDN.
#
# @param source [String] asset name or absolute URL
# @param options [Hash] HTML 5 attributes
#
# @return [Hanami::View::HTML::SafeString] the markup
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the audio file is missing
# from the manifest
#
# @raise [ArgumentError] if source isn"t specified both as argument or
# tag inside the given block
#
# @since 0.1.0
#
# @see Hanami::Assets::Helpers#path
#
# @example Basic Usage
#
# <%= audio_tag "song.ogg" %>
#
# # <audio src="/assets/song.ogg"></audio>
#
# @example Absolute URL
#
# <%= audio_tag "https://example-cdn.com/assets/song.ogg" %>
#
# # <audio src="https://example-cdn.com/assets/song.ogg"></audio>
#
# @example Custom HTML Attributes
#
# <%= audio_tag("song.ogg", autoplay: true, controls: true) %>
#
# # <audio src="/assets/song.ogg" autoplay="autoplay" controls="controls"></audio>
#
# @example Fallback Content
#
# <%=
# audio_tag("song.ogg") do
# "Your browser does not support the audio tag"
# end
# %>
#
# # <audio src="/assets/song.ogg">
# # Your browser does not support the audio tag
# # </audio>
#
# @example Tracks
#
# <%=
# audio_tag("song.ogg") do
# tag.track(kind: "captions", src: asset_url("song.pt-BR.vtt"),
# srclang: "pt-BR", label: "Portuguese")
# end
# %>
#
# # <audio src="/assets/song.ogg">
# # <track kind="captions" src="/assets/song.pt-BR.vtt" srclang="pt-BR" label="Portuguese">
# # </audio>
#
# @example Without Any Argument
#
# <%= audio_tag %>
#
# # ArgumentError
#
# @example Without src And Without Block
#
# <%= audio_tag(controls: true) %>
#
# # ArgumentError
#
# @example Fingerprint Mode
#
# <%= audio_tag "song.ogg" %>
#
# # <audio src="/assets/song-28a6b886de2372ee3922fcaf3f78f2d8.ogg"></audio>
#
# @example CDN Mode
#
# <%= audio_tag "song.ogg" %>
#
# # <audio src="https://assets.bookshelf.org/assets/song-28a6b886de2372ee3922fcaf3f78f2d8.ogg"></audio>
def audio_tag(source = nil, options = {}, &blk)
options = _source_options(source, options, &blk)
tag.audio(**options, &blk)
end
# It generates the relative or absolute URL for the given asset.
# It automatically decides if it has to use the relative or absolute
# depending on the configuration and current environment.
#
# Absolute URLs are returned as they are.
#
# It can be the name of the asset, coming from the sources or third party
# gems.
#
# If Fingerprint mode is on, it returns the fingerprinted path of the source
#
# If CDN mode is on, it returns the absolute URL of the asset.
#
# @param source [String] the asset name
#
# @return [String] the asset path
#
# @raise [Hanami::Assets::MissingManifestAssetError] if `fingerprint` or
# `subresource_integrity` modes are on and the asset is missing
# from the manifest
#
# @since 0.1.0
#
# @example Basic Usage
#
# <%= asset_url "application.js" %>
#
# # "/assets/application.js"
#
# @example Alias
#
# <%= asset_url "application.js" %>
#
# # "/assets/application.js"
#
# @example Absolute URL
#
# <%= asset_url "https://code.jquery.com/jquery-2.1.4.min.js" %>
#
# # "https://code.jquery.com/jquery-2.1.4.min.js"
#
# @example Fingerprint Mode
#
# <%= asset_url "application.js" %>
#
# # "/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
#
# @example CDN Mode
#
# <%= asset_url "application.js" %>
#
# # "https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
def asset_url(source_path)
return source_path if _absolute_url?(source_path)
_context.assets[source_path].url
end
private
# @since 0.1.0
# @api private
def _safe_tags(*source_paths, &blk)
::Hanami::View::HTML::SafeString.new(
source_paths.map(&blk).join(NEW_LINE_SEPARATOR)
)
end
# @since 2.1.0
# @api private
def _typed_path(source, ext)
source = "#{source}#{ext}" if _append_extension?(source, ext)
asset_url(source)
end
# @api private
def _subresource_integrity_value(source_path, ext)
return if _absolute_url?(source_path)
source_path = "#{source_path}#{ext}" unless /#{Regexp.escape(ext)}\z/.match?(source_path)
_context.assets[source_path].sri
end
# @since 0.1.0
# @api private
def _absolute_url?(source)
ABSOLUTE_URL_MATCHER.match(source)
end
# @since 1.2.0
# @api private
def _crossorigin?(source)
return false unless _absolute_url?(source)
_context.assets.crossorigin?(source)
end
# @since 0.1.0
# @api private
def _source_options(src, options, &blk)
options ||= {}
if src.respond_to?(:to_hash)
options = src.to_hash
elsif src
options[:src] = asset_url(src)
end
if !options[:src] && !blk
raise ArgumentError.new("You should provide a source via `src` option or with a `source` HTML tag")
end
options
end
# @since 1.1.0
# @api private
def _append_extension?(source, ext)
source !~ QUERY_STRING_MATCHER && source !~ /#{Regexp.escape(ext)}\z/
end
end
end
end
# rubocop:enable Metrics/ModuleLength