hanami 2.1.0.beta2 → 2.1.0.beta2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06d7766d5bdb4f510945a2065cc15457acbf00f43970d691afda74219f0aeb02
4
- data.tar.gz: 58935ca7f23c3d3612a91b277827ed941c30839d04c9bf577e35a095fa667f6f
3
+ metadata.gz: 219f0622f399b1e3f94c77c5d7556b6bdd26122181929b444eb8fca436e9d0d2
4
+ data.tar.gz: 3dc2468f5561eb8d70fa62d3f5b7f755f096ab764cfbfd43fca93d6001061908
5
5
  SHA512:
6
- metadata.gz: 50a785250f4cf249c5721dd37a5e5a7a240282e5d3820fe848a53c133b1727ea57e5beb351429e636bb4a7d89812bfc53794b5357865b134598a5d54e60666db
7
- data.tar.gz: 677f40136e0477c57e493e41ed9a25666d9b53d6dd4ae4c23ee6e61d062f9537c39d86eb16d264f194eda4209e5eb0e38fa0554fd3efaf2d39ea23afa1ead27b
6
+ metadata.gz: f38c4b54000182e7ab4fb63be367131c6580df35519f97d5fd171de016b4ec96590c5f7c0822044421e0efec64813a492d4e106a803ea6028ba6d6d105db2ee6
7
+ data.tar.gz: 8648d6b907fbc4a600a4561184631b2868a577a2280c6bade34af1726d3bd6458045268c8517956e52bc4e6b2a6dfc78b0bee938e254563cac3fbbae91afc6d2
data/CHANGELOG.md CHANGED
@@ -2,26 +2,33 @@
2
2
 
3
3
  The web, with simplicity.
4
4
 
5
+ ## v2.1.0.beta2.1 - 2023-10-04
6
+
7
+ ### Added
8
+
9
+ - [Tim Riley, Luca Guidi] Added assets helpers aliases (#1319, #1339):
10
+ - Added `#js` and `#javascript_tag` as alias for `#javascript`
11
+ - Added `#css` and `#stylesheet_link_tag` as alias for `#stylesheet`
12
+ - Added `#image_tag` as alias for `#image`
13
+ - Added `#favicon_link_tag` as alias for `#favicon`
14
+ - Added `#video_tag` as alias for `#video`
15
+ - Added `#audio_tag` as alias for `#audio`
16
+
5
17
  ## v2.1.0.beta2 - 2023-10-04
6
18
 
7
19
  ### Added
8
20
 
9
21
  - [Luca Guidi, Tim Riley] Reimplement assets integration (#1319, #1332, #1333, #1336)
10
22
  - [Tim Riley] Introduce `Hanami::Helpers::AssetsHelper`, automatically included in view templates, scopes and parts when hanami-assets is bundled (#1319)
11
- - [Tim Riley] Renamed assets helpers (#1319):
12
- - Removed `#asset_path` in favour of `#asset_url` only
13
- - Renamed `#javascript` to `#javascript_tag`, retaining `#js` alias
14
- - Renamed `#stylesheet` to `#stylesheet_link_tag`, retaining `#css` alias
15
- - Renamed `#image` to `#image_tag`
16
- - Renamed `#favicon` to `#favicon_link_tag`, with `#favicon` retained as an alias
17
- - Renamed `#video` to `#video_tag`
18
- - Renamed `#audio` to `#audio_tag`
19
-
20
23
 
21
24
  ### Fixed
22
25
 
23
26
  - [Tim Riley] Return appropriate response statuses based on error type (#1330)
24
27
 
28
+ ### Changed
29
+
30
+ - [Tim Riley] Removed `#asset_path` in favour of `#asset_url` only (#1319)
31
+
25
32
  ## v2.1.0.beta1 - 2023-06-29
26
33
 
27
34
  ### Added
@@ -154,7 +154,7 @@ module Hanami
154
154
  #
155
155
  # # <script src="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.js"
156
156
  # # type="text/javascript"></script>
157
- def javascript_tag(*source_paths, **options)
157
+ def javascript(*source_paths, **options)
158
158
  options = options.reject { |k, _| k.to_sym == :src }
159
159
 
160
160
  _safe_tags(*source_paths) do |source|
@@ -175,7 +175,11 @@ module Hanami
175
175
 
176
176
  # @api public
177
177
  # @since 2.1.0
178
- alias_method :js, :javascript_tag
178
+ alias_method :js, :javascript
179
+
180
+ # @api public
181
+ # @since 2.1.0
182
+ alias_method :javascript_tag, :javascript
179
183
 
180
184
  # Generate `link` tag for given source(s)
181
185
  #
@@ -251,7 +255,7 @@ module Hanami
251
255
  #
252
256
  # # <link href="https://assets.bookshelf.org/assets/application-28a6b886de2372ee3922fcaf3f78f2d8.css"
253
257
  # # type="text/css" rel="stylesheet">
254
- def stylesheet_link_tag(*source_paths, **options)
258
+ def stylesheet(*source_paths, **options)
255
259
  options = options.reject { |k, _| k.to_sym == :href }
256
260
 
257
261
  _safe_tags(*source_paths) do |source_path|
@@ -273,7 +277,11 @@ module Hanami
273
277
 
274
278
  # @api public
275
279
  # @since 2.1.0
276
- alias_method :css, :stylesheet_link_tag
280
+ alias_method :css, :stylesheet
281
+
282
+ # @api public
283
+ # @since 2.1.0
284
+ alias_method :stylesheet_link_tag, :stylesheet
277
285
 
278
286
  # Generate `img` tag for given source
279
287
  #
@@ -305,40 +313,40 @@ module Hanami
305
313
  #
306
314
  # @example Basic Usage
307
315
  #
308
- # <%= image_tag "logo.png" %>
316
+ # <%= image "logo.png" %>
309
317
  #
310
318
  # # <img src="/assets/logo.png" alt="Logo">
311
319
  #
312
320
  # @example Custom alt Attribute
313
321
  #
314
- # <%= image_tag "logo.png", alt: "Application Logo" %>
322
+ # <%= image "logo.png", alt: "Application Logo" %>
315
323
  #
316
324
  # # <img src="/assets/logo.png" alt="Application Logo">
317
325
  #
318
326
  # @example Custom HTML Attributes
319
327
  #
320
- # <%= image_tag "logo.png", id: "logo", class: "image" %>
328
+ # <%= image "logo.png", id: "logo", class: "image" %>
321
329
  #
322
330
  # # <img src="/assets/logo.png" alt="Logo" id="logo" class="image">
323
331
  #
324
332
  # @example Absolute URL
325
333
  #
326
- # <%= image_tag "https://example-cdn.com/images/logo.png" %>
334
+ # <%= image "https://example-cdn.com/images/logo.png" %>
327
335
  #
328
336
  # # <img src="https://example-cdn.com/images/logo.png" alt="Logo">
329
337
  #
330
338
  # @example Fingerprint Mode
331
339
  #
332
- # <%= image_tag "logo.png" %>
340
+ # <%= image "logo.png" %>
333
341
  #
334
342
  # # <img src="/assets/logo-28a6b886de2372ee3922fcaf3f78f2d8.png" alt="Logo">
335
343
  #
336
344
  # @example CDN Mode
337
345
  #
338
- # <%= image_tag "logo.png" %>
346
+ # <%= image "logo.png" %>
339
347
  #
340
348
  # # <img src="https://assets.bookshelf.org/assets/logo-28a6b886de2372ee3922fcaf3f78f2d8.png" alt="Logo">
341
- def image_tag(source, options = {})
349
+ def image(source, options = {})
342
350
  options = options.reject { |k, _| k.to_sym == :src }
343
351
  attributes = {
344
352
  src: asset_url(source),
@@ -349,6 +357,10 @@ module Hanami
349
357
  tag.img(**attributes)
350
358
  end
351
359
 
360
+ # @api public
361
+ # @since 2.1.0
362
+ alias_method :image_tag, :image
363
+
352
364
  # Generate `link` tag application favicon.
353
365
  #
354
366
  # If no argument is given, it assumes `favico.ico` from the application.
@@ -376,35 +388,35 @@ module Hanami
376
388
  #
377
389
  # @example Basic Usage
378
390
  #
379
- # <%= favicon_link_tag %>
391
+ # <%= favicon %>
380
392
  #
381
393
  # # <link href="/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">
382
394
  #
383
395
  # @example Custom Path
384
396
  #
385
- # <%= favicon_link_tag "fav.ico" %>
397
+ # <%= favicon "fav.ico" %>
386
398
  #
387
399
  # # <link href="/assets/fav.ico" rel="shortcut icon" type="image/x-icon">
388
400
  #
389
401
  # @example Custom HTML Attributes
390
402
  #
391
- # <%= favicon_link_tag "favicon.ico", id: "fav" %>
403
+ # <%= favicon "favicon.ico", id: "fav" %>
392
404
  #
393
405
  # # <link id: "fav" href="/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">
394
406
  #
395
407
  # @example Fingerprint Mode
396
408
  #
397
- # <%= favicon_link_tag %>
409
+ # <%= favicon %>
398
410
  #
399
411
  # # <link href="/assets/favicon-28a6b886de2372ee3922fcaf3f78f2d8.ico" rel="shortcut icon" type="image/x-icon">
400
412
  #
401
413
  # @example CDN Mode
402
414
  #
403
- # <%= favicon_link_tag %>
415
+ # <%= favicon %>
404
416
  #
405
417
  # # <link href="https://assets.bookshelf.org/assets/favicon-28a6b886de2372ee3922fcaf3f78f2d8.ico"
406
418
  # rel="shortcut icon" type="image/x-icon">
407
- def favicon_link_tag(source = DEFAULT_FAVICON, options = {})
419
+ def favicon(source = DEFAULT_FAVICON, options = {})
408
420
  options = options.reject { |k, _| k.to_sym == :href }
409
421
 
410
422
  attributes = {
@@ -419,7 +431,7 @@ module Hanami
419
431
 
420
432
  # @api public
421
433
  # @since 2.1.0
422
- alias_method :favicon, :favicon_link_tag
434
+ alias_method :favicon_link_tag, :favicon
423
435
 
424
436
  # Generate `video` tag for given source
425
437
  #
@@ -454,26 +466,26 @@ module Hanami
454
466
  #
455
467
  # @example Basic Usage
456
468
  #
457
- # <%= video_tag "movie.mp4" %>
469
+ # <%= video "movie.mp4" %>
458
470
  #
459
471
  # # <video src="/assets/movie.mp4"></video>
460
472
  #
461
473
  # @example Absolute URL
462
474
  #
463
- # <%= video_tag "https://example-cdn.com/assets/movie.mp4" %>
475
+ # <%= video "https://example-cdn.com/assets/movie.mp4" %>
464
476
  #
465
477
  # # <video src="https://example-cdn.com/assets/movie.mp4"></video>
466
478
  #
467
479
  # @example Custom HTML Attributes
468
480
  #
469
- # <%= video_tag("movie.mp4", autoplay: true, controls: true) %>
481
+ # <%= video("movie.mp4", autoplay: true, controls: true) %>
470
482
  #
471
483
  # # <video src="/assets/movie.mp4" autoplay="autoplay" controls="controls"></video>
472
484
  #
473
485
  # @example Fallback Content
474
486
  #
475
487
  # <%=
476
- # video_tag("movie.mp4") do
488
+ # video("movie.mp4") do
477
489
  # "Your browser does not support the video tag"
478
490
  # end
479
491
  # %>
@@ -485,7 +497,7 @@ module Hanami
485
497
  # @example Tracks
486
498
  #
487
499
  # <%=
488
- # video_tag("movie.mp4") do
500
+ # video("movie.mp4") do
489
501
  # tag.track(kind: "captions", src: asset_url("movie.en.vtt"),
490
502
  # srclang: "en", label: "English")
491
503
  # end
@@ -497,32 +509,36 @@ module Hanami
497
509
  #
498
510
  # @example Without Any Argument
499
511
  #
500
- # <%= video_tag %>
512
+ # <%= video %>
501
513
  #
502
514
  # # ArgumentError
503
515
  #
504
516
  # @example Without src And Without Block
505
517
  #
506
- # <%= video_tag(content: true) %>
518
+ # <%= video(content: true) %>
507
519
  #
508
520
  # # ArgumentError
509
521
  #
510
522
  # @example Fingerprint Mode
511
523
  #
512
- # <%= video_tag "movie.mp4" %>
524
+ # <%= video "movie.mp4" %>
513
525
  #
514
526
  # # <video src="/assets/movie-28a6b886de2372ee3922fcaf3f78f2d8.mp4"></video>
515
527
  #
516
528
  # @example CDN Mode
517
529
  #
518
- # <%= video_tag "movie.mp4" %>
530
+ # <%= video "movie.mp4" %>
519
531
  #
520
532
  # # <video src="https://assets.bookshelf.org/assets/movie-28a6b886de2372ee3922fcaf3f78f2d8.mp4"></video>
521
- def video_tag(source = nil, options = {}, &blk)
533
+ def video(source = nil, options = {}, &blk)
522
534
  options = _source_options(source, options, &blk)
523
535
  tag.video(**options, &blk)
524
536
  end
525
537
 
538
+ # @api public
539
+ # @since 2.1.0
540
+ alias_method :video_tag, :video
541
+
526
542
  # Generate `audio` tag for given source
527
543
  #
528
544
  # It accepts one string representing the name of the asset, if it comes
@@ -556,26 +572,26 @@ module Hanami
556
572
  #
557
573
  # @example Basic Usage
558
574
  #
559
- # <%= audio_tag "song.ogg" %>
575
+ # <%= audio "song.ogg" %>
560
576
  #
561
577
  # # <audio src="/assets/song.ogg"></audio>
562
578
  #
563
579
  # @example Absolute URL
564
580
  #
565
- # <%= audio_tag "https://example-cdn.com/assets/song.ogg" %>
581
+ # <%= audio "https://example-cdn.com/assets/song.ogg" %>
566
582
  #
567
583
  # # <audio src="https://example-cdn.com/assets/song.ogg"></audio>
568
584
  #
569
585
  # @example Custom HTML Attributes
570
586
  #
571
- # <%= audio_tag("song.ogg", autoplay: true, controls: true) %>
587
+ # <%= audio("song.ogg", autoplay: true, controls: true) %>
572
588
  #
573
589
  # # <audio src="/assets/song.ogg" autoplay="autoplay" controls="controls"></audio>
574
590
  #
575
591
  # @example Fallback Content
576
592
  #
577
593
  # <%=
578
- # audio_tag("song.ogg") do
594
+ # audio("song.ogg") do
579
595
  # "Your browser does not support the audio tag"
580
596
  # end
581
597
  # %>
@@ -587,7 +603,7 @@ module Hanami
587
603
  # @example Tracks
588
604
  #
589
605
  # <%=
590
- # audio_tag("song.ogg") do
606
+ # audio("song.ogg") do
591
607
  # tag.track(kind: "captions", src: asset_url("song.pt-BR.vtt"),
592
608
  # srclang: "pt-BR", label: "Portuguese")
593
609
  # end
@@ -599,32 +615,36 @@ module Hanami
599
615
  #
600
616
  # @example Without Any Argument
601
617
  #
602
- # <%= audio_tag %>
618
+ # <%= audio %>
603
619
  #
604
620
  # # ArgumentError
605
621
  #
606
622
  # @example Without src And Without Block
607
623
  #
608
- # <%= audio_tag(controls: true) %>
624
+ # <%= audio(controls: true) %>
609
625
  #
610
626
  # # ArgumentError
611
627
  #
612
628
  # @example Fingerprint Mode
613
629
  #
614
- # <%= audio_tag "song.ogg" %>
630
+ # <%= audio "song.ogg" %>
615
631
  #
616
632
  # # <audio src="/assets/song-28a6b886de2372ee3922fcaf3f78f2d8.ogg"></audio>
617
633
  #
618
634
  # @example CDN Mode
619
635
  #
620
- # <%= audio_tag "song.ogg" %>
636
+ # <%= audio "song.ogg" %>
621
637
  #
622
638
  # # <audio src="https://assets.bookshelf.org/assets/song-28a6b886de2372ee3922fcaf3f78f2d8.ogg"></audio>
623
- def audio_tag(source = nil, options = {}, &blk)
639
+ def audio(source = nil, options = {}, &blk)
624
640
  options = _source_options(source, options, &blk)
625
641
  tag.audio(**options, &blk)
626
642
  end
627
643
 
644
+ # @api public
645
+ # @since 2.1.0
646
+ alias_method :audio_tag, :audio
647
+
628
648
  # It generates the relative or absolute URL for the given asset.
629
649
  # It automatically decides if it has to use the relative or absolute
630
650
  # depending on the configuration and current environment.
@@ -7,7 +7,7 @@ module Hanami
7
7
  # @api private
8
8
  module Version
9
9
  # @api public
10
- VERSION = "2.1.0.beta2"
10
+ VERSION = "2.1.0.beta2.1"
11
11
 
12
12
  # @since 0.9.0
13
13
  # @api private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Hanami::Helpers::AssetsHelper, "#audio_tag", :app_integration do
3
+ RSpec.describe Hanami::Helpers::AssetsHelper, "#audio", :app_integration do
4
4
  subject(:obj) {
5
5
  helpers = described_class
6
6
  Class.new {
@@ -14,8 +14,8 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#audio_tag", :app_integration do
14
14
  }.new(context)
15
15
  }
16
16
 
17
- def audio_tag(...)
18
- subject.audio_tag(...)
17
+ def audio(...)
18
+ subject.audio(...)
19
19
  end
20
20
 
21
21
  let(:context) { TestApp::Views::Context.new }
@@ -53,22 +53,26 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#audio_tag", :app_integration do
53
53
  end
54
54
 
55
55
  it "returns an instance of HtmlBuilder" do
56
- actual = audio_tag("song.ogg")
56
+ actual = audio("song.ogg")
57
57
  expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
58
58
  end
59
59
 
60
60
  it "renders <audio> tag" do
61
- actual = audio_tag("song.ogg").to_s
61
+ actual = audio("song.ogg").to_s
62
62
  expect(actual).to eq(%(<audio src="/assets/song.ogg"></audio>))
63
63
  end
64
64
 
65
+ it "is aliased as #audio_tag" do
66
+ expect(subject.audio_tag("song.ogg")).to eq(audio("song.ogg"))
67
+ end
68
+
65
69
  it "renders with html attributes" do
66
- actual = audio_tag("song.ogg", autoplay: true, controls: true).to_s
70
+ actual = audio("song.ogg", autoplay: true, controls: true).to_s
67
71
  expect(actual).to eq(%(<audio autoplay="autoplay" controls="controls" src="/assets/song.ogg"></audio>))
68
72
  end
69
73
 
70
74
  it "renders with fallback content" do
71
- actual = audio_tag("song.ogg") do
75
+ actual = audio("song.ogg") do
72
76
  "Your browser does not support the audio tag"
73
77
  end.to_s
74
78
 
@@ -76,7 +80,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#audio_tag", :app_integration do
76
80
  end
77
81
 
78
82
  it "renders with tracks" do
79
- actual = audio_tag("song.ogg") do
83
+ actual = audio("song.ogg") do
80
84
  tag.track kind: "captions", src: subject.asset_url("song.pt-BR.vtt"), srclang: "pt-BR", label: "Portuguese"
81
85
  end.to_s
82
86
 
@@ -84,7 +88,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#audio_tag", :app_integration do
84
88
  end
85
89
 
86
90
  xit "renders with sources" do
87
- actual = audio_tag do
91
+ actual = audio do
88
92
  tag.text "Your browser does not support the audio tag"
89
93
  tag.source src: subject.asset_url("song.ogg"), type: "audio/ogg"
90
94
  tag.source src: subject.asset_url("song.wav"), type: "audio/wav"
@@ -95,7 +99,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#audio_tag", :app_integration do
95
99
 
96
100
  it "raises an exception when no arguments" do
97
101
  expect do
98
- audio_tag
102
+ audio
99
103
  end.to raise_error(
100
104
  ArgumentError,
101
105
  "You should provide a source via `src` option or with a `source` HTML tag"
@@ -104,7 +108,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#audio_tag", :app_integration do
104
108
 
105
109
  it "raises an exception when no src and no block" do
106
110
  expect do
107
- audio_tag(controls: true)
111
+ audio(controls: true)
108
112
  end.to raise_error(
109
113
  ArgumentError,
110
114
  "You should provide a source via `src` option or with a `source` HTML tag"
@@ -119,7 +123,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#audio_tag", :app_integration do
119
123
  end
120
124
 
121
125
  it "returns absolute url for src attribute" do
122
- actual = audio_tag("song.ogg").to_s
126
+ actual = audio("song.ogg").to_s
123
127
  expect(actual).to eq(%(<audio src="#{base_url}/assets/song.ogg"></audio>))
124
128
  end
125
129
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Hanami::Helpers::AssetsHelper, "#favicon_link_tag", :app_integration do
3
+ RSpec.describe Hanami::Helpers::AssetsHelper, "#favicon", :app_integration do
4
4
  subject(:obj) {
5
5
  helpers = described_class
6
6
  Class.new {
@@ -14,8 +14,8 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#favicon_link_tag", :app_integrat
14
14
  }.new(context)
15
15
  }
16
16
 
17
- def favicon_link_tag(...)
18
- obj.instance_eval { favicon_link_tag(...) }
17
+ def favicon(...)
18
+ obj.instance_eval { favicon(...) }
19
19
  end
20
20
 
21
21
  let(:root) { make_tmp_directory }
@@ -53,26 +53,26 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#favicon_link_tag", :app_integrat
53
53
  end
54
54
 
55
55
  it "returns an instance of SafeString" do
56
- actual = favicon_link_tag
56
+ actual = favicon
57
57
  expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
58
58
  end
59
59
 
60
- it "is aliased as `favicon`" do
61
- expect(subject.favicon).to eq favicon_link_tag
60
+ it "is aliased as #favicon_link_tag" do
61
+ expect(subject.favicon_link_tag).to eq(favicon)
62
62
  end
63
63
 
64
64
  it "renders <link> tag" do
65
- actual = favicon_link_tag.to_s
65
+ actual = favicon.to_s
66
66
  expect(actual).to eq(%(<link href="/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">))
67
67
  end
68
68
 
69
69
  it "renders with HTML attributes" do
70
- actual = favicon_link_tag("favicon.png", rel: "icon", type: "image/png").to_s
70
+ actual = favicon("favicon.png", rel: "icon", type: "image/png").to_s
71
71
  expect(actual).to eq(%(<link href="/assets/favicon.png" rel="icon" type="image/png">))
72
72
  end
73
73
 
74
74
  it "ignores href passed as an option" do
75
- actual = favicon_link_tag("favicon.png", href: "wrong").to_s
75
+ actual = favicon("favicon.png", href: "wrong").to_s
76
76
  expect(actual).to eq(%(<link href="/assets/favicon.png" rel="shortcut icon" type="image/x-icon">))
77
77
  end
78
78
 
@@ -84,7 +84,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#favicon_link_tag", :app_integrat
84
84
  end
85
85
 
86
86
  it "returns absolute url for href attribute" do
87
- actual = favicon_link_tag.to_s
87
+ actual = favicon.to_s
88
88
  expect(actual).to eq(%(<link href="#{base_url}/assets/favicon.ico" rel="shortcut icon" type="image/x-icon">))
89
89
  end
90
90
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Hanami::Helpers::AssetsHelper, "#image_tag", :app_integration do
3
+ RSpec.describe Hanami::Helpers::AssetsHelper, "#image", :app_integration do
4
4
  subject(:obj) {
5
5
  helpers = described_class
6
6
  Class.new {
@@ -14,8 +14,8 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#image_tag", :app_integration do
14
14
  }.new(context)
15
15
  }
16
16
 
17
- def image_tag(...)
18
- subject.image_tag(...)
17
+ def image(...)
18
+ subject.image(...)
19
19
  end
20
20
 
21
21
  let(:root) { make_tmp_directory }
@@ -53,27 +53,31 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#image_tag", :app_integration do
53
53
  end
54
54
 
55
55
  it "returns an instance of HtmlBuilder" do
56
- actual = image_tag("application.jpg")
56
+ actual = image("application.jpg")
57
57
  expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
58
58
  end
59
59
 
60
60
  it "renders an <img> tag" do
61
- actual = image_tag("application.jpg").to_s
61
+ actual = image("application.jpg").to_s
62
62
  expect(actual).to eq(%(<img src="/assets/application.jpg" alt="Application">))
63
63
  end
64
64
 
65
+ it "is aliased as #image_tag" do
66
+ expect(subject.image_tag("application.jpg")).to eq image("application.jpg")
67
+ end
68
+
65
69
  it "custom alt" do
66
- actual = image_tag("application.jpg", alt: "My Alt").to_s
70
+ actual = image("application.jpg", alt: "My Alt").to_s
67
71
  expect(actual).to eq(%(<img src="/assets/application.jpg" alt="My Alt">))
68
72
  end
69
73
 
70
74
  it "custom data attribute" do
71
- actual = image_tag("application.jpg", "data-user-id" => 5).to_s
75
+ actual = image("application.jpg", "data-user-id" => 5).to_s
72
76
  expect(actual).to eq(%(<img src="/assets/application.jpg" alt="Application" data-user-id="5">))
73
77
  end
74
78
 
75
79
  it "ignores src passed as an option" do
76
- actual = image_tag("application.jpg", src: "wrong").to_s
80
+ actual = image("application.jpg", src: "wrong").to_s
77
81
  expect(actual).to eq(%(<img src="/assets/application.jpg" alt="Application">))
78
82
  end
79
83
 
@@ -85,7 +89,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#image_tag", :app_integration do
85
89
  end
86
90
 
87
91
  it "returns absolute url for src attribute" do
88
- actual = image_tag("application.jpg").to_s
92
+ actual = image("application.jpg").to_s
89
93
  expect(actual).to eq(%(<img src="#{base_url}/assets/application.jpg" alt="Application">))
90
94
  end
91
95
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Hanami::Helpers::AssetsHelper, "#javascript_tag", :app_integration do
3
+ RSpec.describe Hanami::Helpers::AssetsHelper, "#javascript", :app_integration do
4
4
  subject(:obj) {
5
5
  helpers = described_class
6
6
  Class.new {
@@ -14,8 +14,8 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#javascript_tag", :app_integratio
14
14
  }.new(context)
15
15
  }
16
16
 
17
- def javascript_tag(...)
18
- subject.javascript_tag(...)
17
+ def javascript(...)
18
+ subject.javascript(...)
19
19
  end
20
20
 
21
21
  let(:context) { TestApp::Views::Context.new }
@@ -65,52 +65,56 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#javascript_tag", :app_integratio
65
65
  end
66
66
 
67
67
  it "returns an instance of SafeString" do
68
- actual = javascript_tag("feature-a")
68
+ actual = javascript("feature-a")
69
69
  expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
70
70
  end
71
71
 
72
- it "is aliased as `js`" do
73
- expect(subject.js("feature-a")).to eq javascript_tag("feature-a")
72
+ it "is aliased as #js" do
73
+ expect(subject.js("feature-a")).to eq javascript("feature-a")
74
+ end
75
+
76
+ it "is aliased as #javascript_tag" do
77
+ expect(subject.javascript_tag("feature-a")).to eq javascript("feature-a")
74
78
  end
75
79
 
76
80
  it "renders <script> tag" do
77
- actual = javascript_tag("feature-a")
81
+ actual = javascript("feature-a")
78
82
  expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript"></script>))
79
83
  end
80
84
 
81
85
  xit "renders <script> tag without appending ext after query string" do
82
- actual = javascript_tag("feature-x?callback=init")
86
+ actual = javascript("feature-x?callback=init")
83
87
  expect(actual).to eq(%(<script src="/assets/feature-x?callback=init" type="text/javascript"></script>))
84
88
  end
85
89
 
86
90
  it "renders <script> tag with a defer attribute" do
87
- actual = javascript_tag("feature-a", defer: true)
91
+ actual = javascript("feature-a", defer: true)
88
92
  expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript" defer="defer"></script>))
89
93
  end
90
94
 
91
95
  it "renders <script> tag with an integrity attribute" do
92
- actual = javascript_tag("feature-a", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
96
+ actual = javascript("feature-a", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
93
97
  expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="anonymous"></script>))
94
98
  end
95
99
 
96
100
  it "renders <script> tag with a crossorigin attribute" do
97
- actual = javascript_tag("feature-a", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC", crossorigin: "use-credentials")
101
+ actual = javascript("feature-a", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC", crossorigin: "use-credentials")
98
102
  expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="use-credentials"></script>))
99
103
  end
100
104
 
101
105
  it "ignores src passed as an option" do
102
- actual = javascript_tag("feature-a", src: "wrong")
106
+ actual = javascript("feature-a", src: "wrong")
103
107
  expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript"></script>))
104
108
  end
105
109
 
106
110
  describe "async option" do
107
111
  it "renders <script> tag with an async=true if async option is true" do
108
- actual = javascript_tag("feature-a", async: true)
112
+ actual = javascript("feature-a", async: true)
109
113
  expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript" async="async"></script>))
110
114
  end
111
115
 
112
116
  it "renders <script> tag without an async=true if async option is false" do
113
- actual = javascript_tag("feature-a", async: false)
117
+ actual = javascript("feature-a", async: false)
114
118
  expect(actual).to eq(%(<script src="/assets/feature-a.js" type="text/javascript"></script>))
115
119
  end
116
120
  end
@@ -123,7 +127,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#javascript_tag", :app_integratio
123
127
  before { compile_assets! }
124
128
 
125
129
  it "includes subresource_integrity and crossorigin attributes" do
126
- actual = javascript_tag("app")
130
+ actual = javascript("app")
127
131
  expect(actual).to match(%r{<script src="/assets/app-[A-Z0-9]{8}.js" type="text/javascript" integrity="sha384-[A-Za-z0-9+/]{64}" crossorigin="anonymous"></script>})
128
132
  end
129
133
  end
@@ -136,7 +140,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#javascript_tag", :app_integratio
136
140
  end
137
141
 
138
142
  it "returns absolute url for src attribute" do
139
- actual = javascript_tag("feature-a")
143
+ actual = javascript("feature-a")
140
144
  expect(actual).to eq(%(<script src="#{base_url}/assets/feature-a.js" type="text/javascript"></script>))
141
145
  end
142
146
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Hanami::Helpers::AssetsHelper, "#stylesheet_link_tag", :app_integration do
3
+ RSpec.describe Hanami::Helpers::AssetsHelper, "#stylesheet", :app_integration do
4
4
  subject(:obj) {
5
5
  helpers = described_class
6
6
  Class.new {
@@ -14,8 +14,8 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#stylesheet_link_tag", :app_integ
14
14
  }.new(context)
15
15
  }
16
16
 
17
- def stylesheet_link_tag(...)
18
- subject.stylesheet_link_tag(...)
17
+ def stylesheet(...)
18
+ subject.stylesheet(...)
19
19
  end
20
20
 
21
21
  let(:context) { TestApp::Views::Context.new }
@@ -65,36 +65,40 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#stylesheet_link_tag", :app_integ
65
65
  end
66
66
 
67
67
  it "returns an instance of SafeString" do
68
- actual = stylesheet_link_tag("main")
68
+ actual = stylesheet("main")
69
69
  expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
70
70
  end
71
71
 
72
- it "is aliased as `css`" do
73
- expect(subject.css("main")).to eq stylesheet_link_tag("main")
72
+ it "is aliased as #css" do
73
+ expect(subject.css("main")).to eq stylesheet("main")
74
+ end
75
+
76
+ it "is aliased as #stylesheet_link_tag" do
77
+ expect(subject.stylesheet_link_tag("main")).to eq stylesheet("main")
74
78
  end
75
79
 
76
80
  it "renders <link> tag" do
77
- actual = stylesheet_link_tag("main")
81
+ actual = stylesheet("main")
78
82
  expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet">))
79
83
  end
80
84
 
81
85
  xit "renders <link> tag without appending ext after query string" do
82
- actual = stylesheet_link_tag("fonts?font=Helvetica")
86
+ actual = stylesheet("fonts?font=Helvetica")
83
87
  expect(actual).to eq(%(<link href="/assets/fonts?font=Helvetica" type="text/css" rel="stylesheet">))
84
88
  end
85
89
 
86
90
  it "renders <link> tag with an integrity attribute" do
87
- actual = stylesheet_link_tag("main", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
91
+ actual = stylesheet("main", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC")
88
92
  expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="anonymous">))
89
93
  end
90
94
 
91
95
  it "renders <link> tag with a crossorigin attribute" do
92
- actual = stylesheet_link_tag("main", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC", crossorigin: "use-credentials")
96
+ actual = stylesheet("main", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC", crossorigin: "use-credentials")
93
97
  expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="use-credentials">))
94
98
  end
95
99
 
96
100
  it "ignores href passed as an option" do
97
- actual = stylesheet_link_tag("main", href: "wrong")
101
+ actual = stylesheet("main", href: "wrong")
98
102
  expect(actual).to eq(%(<link href="/assets/main.css" type="text/css" rel="stylesheet">))
99
103
  end
100
104
 
@@ -106,7 +110,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#stylesheet_link_tag", :app_integ
106
110
  before { compile_assets! }
107
111
 
108
112
  it "includes subresource_integrity and crossorigin attributes" do
109
- actual = stylesheet_link_tag("app")
113
+ actual = stylesheet("app")
110
114
  expect(actual).to match(%r{<link href="/assets/app-[A-Z0-9]{8}.css" type="text/css" rel="stylesheet" integrity="sha384-[A-Za-z0-9+/]{64}" crossorigin="anonymous">})
111
115
  end
112
116
  end
@@ -119,7 +123,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#stylesheet_link_tag", :app_integ
119
123
  end
120
124
 
121
125
  it "returns absolute url for href attribute" do
122
- actual = stylesheet_link_tag("main")
126
+ actual = stylesheet("main")
123
127
  expect(actual).to eq(%(<link href="#{base_url}/assets/main.css" type="text/css" rel="stylesheet">))
124
128
  end
125
129
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Hanami::Helpers::AssetsHelper, "#video_tag", :app_integration do
3
+ RSpec.describe Hanami::Helpers::AssetsHelper, "#video", :app_integration do
4
4
  subject(:obj) {
5
5
  helpers = described_class
6
6
  Class.new {
@@ -14,8 +14,8 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#video_tag", :app_integration do
14
14
  }.new(context)
15
15
  }
16
16
 
17
- def video_tag(...)
18
- subject.video_tag(...)
17
+ def video(...)
18
+ subject.video(...)
19
19
  end
20
20
 
21
21
  let(:context) { TestApp::Views::Context.new }
@@ -53,22 +53,26 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#video_tag", :app_integration do
53
53
  end
54
54
 
55
55
  it "returns an instance of HtmlBuilder" do
56
- actual = video_tag("movie.mp4")
56
+ actual = video("movie.mp4")
57
57
  expect(actual).to be_instance_of(::Hanami::View::HTML::SafeString)
58
58
  end
59
59
 
60
60
  it "renders <video> tag" do
61
- actual = video_tag("movie.mp4").to_s
61
+ actual = video("movie.mp4").to_s
62
62
  expect(actual).to eq(%(<video src="/assets/movie.mp4"></video>))
63
63
  end
64
64
 
65
+ it "is aliased as #video_tag" do
66
+ expect(video("movie.mp4")).to eq(subject.video_tag("movie.mp4"))
67
+ end
68
+
65
69
  it "renders with html attributes" do
66
- actual = video_tag("movie.mp4", autoplay: true, controls: true).to_s
70
+ actual = video("movie.mp4", autoplay: true, controls: true).to_s
67
71
  expect(actual).to eq(%(<video autoplay="autoplay" controls="controls" src="/assets/movie.mp4"></video>))
68
72
  end
69
73
 
70
74
  it "renders with fallback content" do
71
- actual = video_tag("movie.mp4") do
75
+ actual = video("movie.mp4") do
72
76
  "Your browser does not support the video tag"
73
77
  end.to_s
74
78
 
@@ -76,7 +80,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#video_tag", :app_integration do
76
80
  end
77
81
 
78
82
  it "renders with tracks" do
79
- actual = video_tag("movie.mp4") do
83
+ actual = video("movie.mp4") do
80
84
  tag.track kind: "captions", src: subject.asset_url("movie.en.vtt"), srclang: "en", label: "English"
81
85
  end.to_s
82
86
 
@@ -95,7 +99,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#video_tag", :app_integration do
95
99
 
96
100
  it "raises an exception when no arguments" do
97
101
  expect do
98
- video_tag
102
+ video
99
103
  end.to raise_error(
100
104
  ArgumentError,
101
105
  "You should provide a source via `src` option or with a `source` HTML tag"
@@ -104,7 +108,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#video_tag", :app_integration do
104
108
 
105
109
  it "raises an exception when no src and no block" do
106
110
  expect do
107
- video_tag(content: true)
111
+ video(content: true)
108
112
  end.to raise_error(
109
113
  ArgumentError,
110
114
  "You should provide a source via `src` option or with a `source` HTML tag"
@@ -119,7 +123,7 @@ RSpec.describe Hanami::Helpers::AssetsHelper, "#video_tag", :app_integration do
119
123
  end
120
124
 
121
125
  it "returns absolute url for src attribute" do
122
- actual = video_tag("movie.mp4").to_s
126
+ actual = video("movie.mp4").to_s
123
127
  expect(actual).to eq(%(<video src="#{base_url}/assets/movie.mp4"></video>))
124
128
  end
125
129
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  RSpec.describe "Hanami::VERSION" do
4
4
  it "returns current version" do
5
- expect(Hanami::VERSION).to eq("2.1.0.beta2")
5
+ expect(Hanami::VERSION).to eq("2.1.0.beta2.1")
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.beta2
4
+ version: 2.1.0.beta2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -406,12 +406,12 @@ files:
406
406
  - spec/unit/hanami/env_spec.rb
407
407
  - spec/unit/hanami/extensions/view/context_spec.rb
408
408
  - spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb
409
- - spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb
410
- - spec/unit/hanami/helpers/assets_helper/favicon_link_tag_spec.rb
411
- - spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb
412
- - spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb
413
- - spec/unit/hanami/helpers/assets_helper/stylesheet_link_tag_spec.rb
414
- - spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb
409
+ - spec/unit/hanami/helpers/assets_helper/audio_spec.rb
410
+ - spec/unit/hanami/helpers/assets_helper/favicon_spec.rb
411
+ - spec/unit/hanami/helpers/assets_helper/image_spec.rb
412
+ - spec/unit/hanami/helpers/assets_helper/javascript_spec.rb
413
+ - spec/unit/hanami/helpers/assets_helper/stylesheet_spec.rb
414
+ - spec/unit/hanami/helpers/assets_helper/video_spec.rb
415
415
  - spec/unit/hanami/helpers/form_helper_spec.rb
416
416
  - spec/unit/hanami/port_spec.rb
417
417
  - spec/unit/hanami/router/errors/not_allowed_error_spec.rb
@@ -544,12 +544,12 @@ test_files:
544
544
  - spec/unit/hanami/env_spec.rb
545
545
  - spec/unit/hanami/extensions/view/context_spec.rb
546
546
  - spec/unit/hanami/helpers/assets_helper/asset_url_spec.rb
547
- - spec/unit/hanami/helpers/assets_helper/audio_tag_spec.rb
548
- - spec/unit/hanami/helpers/assets_helper/favicon_link_tag_spec.rb
549
- - spec/unit/hanami/helpers/assets_helper/image_tag_spec.rb
550
- - spec/unit/hanami/helpers/assets_helper/javascript_tag_spec.rb
551
- - spec/unit/hanami/helpers/assets_helper/stylesheet_link_tag_spec.rb
552
- - spec/unit/hanami/helpers/assets_helper/video_tag_spec.rb
547
+ - spec/unit/hanami/helpers/assets_helper/audio_spec.rb
548
+ - spec/unit/hanami/helpers/assets_helper/favicon_spec.rb
549
+ - spec/unit/hanami/helpers/assets_helper/image_spec.rb
550
+ - spec/unit/hanami/helpers/assets_helper/javascript_spec.rb
551
+ - spec/unit/hanami/helpers/assets_helper/stylesheet_spec.rb
552
+ - spec/unit/hanami/helpers/assets_helper/video_spec.rb
553
553
  - spec/unit/hanami/helpers/form_helper_spec.rb
554
554
  - spec/unit/hanami/port_spec.rb
555
555
  - spec/unit/hanami/router/errors/not_allowed_error_spec.rb