From cf3d74aa716d1916209c4bcd7985e99aa7aae20e Mon Sep 17 00:00:00 2001 From: librasteve Date: Mon, 22 Jul 2024 21:42:51 +0100 Subject: [PATCH] ok no inner --- bin/synopsis-rahx | 7 +++---- lib/HTMX.rakumod | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bin/synopsis-rahx b/bin/synopsis-rahx index ceccd87..8f776ed 100755 --- a/bin/synopsis-rahx +++ b/bin/synopsis-rahx @@ -3,14 +3,13 @@ use v6.d; use HTMX; -put +list-tags; -put +list-singulars; -put +list-regulars; + say h1('text', :class); +say h1 :class; -say div (:class, ); +say div :class, 'xx'; diff --git a/lib/HTMX.rakumod b/lib/HTMX.rakumod index 90f078e..35d7bd2 100644 --- a/lib/HTMX.rakumod +++ b/lib/HTMX.rakumod @@ -6,7 +6,7 @@ constant term:<ΒΆ> = $?NL; #viz. https://www.w3schools.com/tags/default.asp -constant @tags = ; -my @regular-tags = ( @tags.Set (-) @singular-tags.Set ).List; +my @regular-tags = (@all-tags.Set (-) @singular-tags.Set ).List; -sub list-tags is export { @tags.sort } +sub list-tags is export {@all-tags.sort } sub list-singulars is export { @singular-tags.sort } sub list-regulars is export { @regular-tags.sort } # Export them so that `h1("text")` makes `

text

` and so on # eg sub h1(Str $inner) {do-tag 'h1', $inner} -sub do-tag( $tag, $inner, *%h ) { +sub do-tag( $tag, $inner?, *%h ) { - my Str $attrs = (+%h ?? ' ' !! '') ~ %h.map({ .key ~ '="' ~ .value ~ '"' }).join(' '); + my $attrs = +%h ?? (' ' ~ %h.map({.key ~ '="' ~ .value ~ '"'}).join(' ') ) !! ''; - '<' ~ $tag ~ $attrs ~ '>' ~ $inner ~ '' + '<' ~ $tag ~ $attrs ~ '>' ~ ($inner // '') ~ '' } # put in all the tags programmatically # viz. https://docs.raku.org/language/modules#Exporting_and_selective_importing my package EXPORT::DEFAULT { - for @tags -> $tag { - OUR::{'&' ~ $tag} := sub ($inner, *%h) { do-tag( "$tag", $inner, |%h ) } + for @all-tags -> $tag { + OUR::{'&' ~ $tag} := sub ($inner?, *%h) { do-tag( "$tag", $inner, |%h ) } } }