diff --git a/README.md b/README.md index 46c3e77..50f50f5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,70 @@ Contributions welcome - by PR please if possible. -See [Issues](https://github.com/librasteve/raku-HTMX/issues/1) for active feature dicsussions. +See [Issues](https://github.com/librasteve/raku-HTMX/issues/1) for active feature discussions. + +NAME +==== + +This module provides a programmatic style for HTML and HTMX ([htmx.org]) web content. + +For now it's missing the server side piece, likely will start with Hummingbird. + +SYNOPSIS +======== + +```raku +use HTMX; + +my $head = head [ + meta( :charset ), + meta( :name, :content ), + meta( :name, :content ), + + title( "Raku HTMX" ), + + script( src => "https://unpkg.com/htmx.org@1.7.0", ), + + link( rel => "stylesheet", + href => "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", + ), + style( + q:to/END/; + .jumbotron { + background-color: #e6ffe6; + text-align: center; + } + END + ), +]; + +my $body = body [ + div( :class, [ + h1("Welcome to Dunder Mifflin!"), #use parens to stop

slurping

+ p "Dunder Mifflin Inc. (stock symbol {strong 'DMI'}) " ~ + q:to/END/; + is a micro-cap regional paper and office + supply distributor with an emphasis on servicing + small-business clients. + END + ]), + + p :hx-get, + "Click Me", +]; + +my $html = html :lang, [ + $head, + $body, +]; + +say "$html"; +``` + +DESCRIPTION +=========== + +HTMX is ... TODOS ===== @@ -12,10 +75,9 @@ TODOS - [x] Get a definitive list of HTML tags - [x] Export them so that `h1("text")` makes `

text

` and so on - [x] Pass and format the HTMX attributes -- [ ] Bring in synopsis from design -- [ ] Do the ¶ term +- [x] Bring in synopsis from design - [ ] Make a parse script (& instructions how to watch a dir) -- [ ] Write some tests +- [x] Write some tests - [ ] Write some docs in POD6 - [ ] Release with App::Mi6 - [ ] Publish as raku-htmx on the htmx Discord @@ -28,22 +90,8 @@ TODOS - [ ] Hummingbird - ditto for HB - [ ] Attribute checking (need deeper list of attr names and set of types) -NAME -==== - -This module provides a programmatic style for HTML and HTMX ([htmx.org]) web content. - -SYNOPSIS -======== - -```raku -use HTMX; -``` - -DESCRIPTION -=========== - -HTMX is ... +#### Rejected +- [ ] Do the ¶ term - NOPE this messes with editor code preview AUTHOR ====== diff --git a/bin/synopsis-rahx b/bin/synopsis-rahx index f09552b..0222929 100755 --- a/bin/synopsis-rahx +++ b/bin/synopsis-rahx @@ -3,33 +3,46 @@ use v6.d; use HTMX; - -say list-regulars; - -say h1('text', :class); -say h1 :class; - -say div :class, 'xx'; - -say br; - - - - - - -#my $page = -# -# div (:class,); -# [ -# h1 "Welcome to Dunder Mifflin!", -# -# p "Dunder Mifflin Inc. (stock symbol {strong 'DMI'}" ~ -# q:to/END/; -# is a micro-cap regional paper and office -# supply distributor with an emphasis on servicing -# small-business clients. -# END -# ] -# ); -# +my $head = head [ + meta( :charset ), + meta( :name, :content ), + meta( :name, :content ), + + title( "Raku HTMX" ), + + script( src => "https://unpkg.com/htmx.org@1.7.0", ), + + link( rel => "stylesheet", + href => "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", + ), + style( + q:to/END/; + .jumbotron { + background-color: #e6ffe6; + text-align: center; + } + END + ), +]; + +my $body = body [ + div( :class, [ + h1("Welcome to Dunder Mifflin!"), #use parens to stop

slurping

+ p "Dunder Mifflin Inc. (stock symbol {strong 'DMI'}) " ~ + q:to/END/; + is a micro-cap regional paper and office + supply distributor with an emphasis on servicing + small-business clients. + END + ]), + + p :hx-get, + "Click Me", +]; + +my $html = html :lang, [ + $head, + $body, +]; + +say "$html"; \ No newline at end of file diff --git a/dist.ini b/dist.ini index f2e6caf..de01113 100644 --- a/dist.ini +++ b/dist.ini @@ -1,9 +1,10 @@ name = HTMX -[ReadmeFromPod] -filename = lib/HTMX.rakumod - [UploadToZef] +;FIXME uncomment after README.md is moved to HTMX.rakumod POD6 +;[ReadmeFromPod] +;filename = lib/HTMX.rakumod + [Badges] provider = github-actions/test.yml diff --git a/index.html b/index.html deleted file mode 100644 index f2da0c3..0000000 --- a/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - -

-

Welcome to Dunder Mifflin!

-

- Dunder Mifflin Inc. (stock symbol DMI) is - a micro-cap regional paper and office supply distributor with - an emphasis on servicing small-business clients. -

-
- - \ No newline at end of file diff --git a/lib/HTMX.rakumod b/lib/HTMX.rakumod index e745f41..8e2f934 100644 --- a/lib/HTMX.rakumod +++ b/lib/HTMX.rakumod @@ -1,11 +1,8 @@ unit class HTMX; -constant term:<¶> = $?NL; - -##### HTMX Tag Export ##### - -#viz. https://www.w3schools.com/tags/default.asp +##### Declare Constants ##### +#| viz. https://www.w3schools.com/tags/default.asp constant @all-tags = ; -#of which "empty" / "singular" tags from https://www.tutsinsider.com/html/html-empty-elements/ +#| of which "empty" / "singular" tags from https://www.tutsinsider.com/html/html-empty-elements/ constant @singular-tags = ; -my @regular-tags = (@all-tags.Set (-) @singular-tags.Set).keys; +##### HTMX Tag Export ##### -sub list-tags is export {@all-tags.sort } -sub list-singulars is export { @singular-tags.sort } -sub list-regulars is export { @regular-tags } +my @regular-tags = (@all-tags.Set (-) @singular-tags.Set).keys; # Export them so that `h1("text")` makes `

text

` and so on # eg sub h1(Str $inner) {do-tag 'h1', $inner} +# inners are already Str + +sub attrs(%h) { + +%h ?? (' ' ~ %h.map({.key ~ '="' ~ .value ~ '"'}).join(' ') ) !! '' +} -sub do-regular-tag( $tag, $inner?, *%h ) { +sub do-regular-tag( $tag, *@inners, *%h ) { - my $attrs = +%h ?? (' ' ~ %h.map({.key ~ '="' ~ .value ~ '"'}).join(' ') ) !! ''; + my $opener = '<' ~ $tag ~ attrs(%h) ~ '>'; + my $closer = ''; + + given @inners { + when * <= 1 { + $opener ~ @inners.join ~ $closer + } + when * >= 2 { + $opener ~ "\n " ~ @inners.join("\n ") ~ "\n" ~ $closer + } + } - '<' ~ $tag ~ $attrs ~ '>' ~ ($inner // '') ~ '' } sub do-singular-tag( $tag, *%h ) { - my $attrs = +%h ?? (' ' ~ %h.map({.key ~ '="' ~ .value ~ '"'}).join(' ') ) !! ''; + '<' ~ $tag ~ attrs(%h) ~ ' />' - '<' ~ $tag ~ $attrs ~ ' />' } # put in all the tags programmatically @@ -45,7 +53,7 @@ sub do-singular-tag( $tag, *%h ) { my package EXPORT::DEFAULT { for @regular-tags -> $tag { - OUR::{'&' ~ $tag} := sub ($inner?, *%h) { do-regular-tag( "$tag", $inner, |%h ) } + OUR::{'&' ~ $tag} := sub (*@inners, *%h) { do-regular-tag( "$tag", @inners, |%h ) } } for @singular-tags -> $tag { diff --git a/t/01-basic.rakutest b/t/01-basic.rakutest index fd35f5d..04d4fd3 100644 --- a/t/01-basic.rakutest +++ b/t/01-basic.rakutest @@ -1,6 +1,13 @@ use Test; use HTMX; -pass "replace me"; +is h1('text', :class), '

text

', 'h1'; + +is h1(:class), '

', 'empty'; + +is div(:class, 'xx'), '
xx
', 'regular'; + +is hr, '
', 'singluar'; + done-testing;