Skip to content

Commit

Permalink
Merge pull request #4 from librasteve/steve-01
Browse files Browse the repository at this point in the history
OK Singular & Regular Tags
  • Loading branch information
librasteve authored Jul 22, 2024
2 parents 5d609dc + e868190 commit 2fd7700
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 284 deletions.
18 changes: 0 additions & 18 deletions Build.rakumod

This file was deleted.

5 changes: 1 addition & 4 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
"provides": {
"HTMX": "lib/HTMX.rakumod"
},
"resources": [
"html5-tags-w3schools.csv",
"html5-tags-list.csv"
],
"resources": [],
"license": "Artistic-2.0",
"tags": [],
"source-url": ""
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ TODOS

#### Follow On

- [ ] consider adding back end template to this module (like this https://github.com/Konfuzian/htmx-examples-with-flask/tree/main)
- [ ] CSS - try some alternatives, read some stuff, make a plan
- [ ] Cro - how to integrate HTMX Static pages with Cro backend
- [ ] Hummingbird - ditto for HB
Expand Down
18 changes: 0 additions & 18 deletions bin/html5-tags-extract.raku

This file was deleted.

30 changes: 29 additions & 1 deletion bin/synopsis-rahx
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,32 @@ use v6.d;
use HTMX;


say h1('text', :class<jumbotron>);
say list-regulars;

say h1('text', :class<jumbotron>);
say h1 :class<doobie>;

say div :class<jumbotron>, 'xx';

say br;






#my $page =
#
# div (:class<jumbotron>,);
# [
# 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
# ]
# );
#
28 changes: 28 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/[email protected]" integrity="sha384-QWGpdj554B4ETpJJC9z+ZHJcA/i59TyjxEPXiiUgN2WmTyV5OEZWCD6gQhgkdpB/"
crossorigin="anonymous"></script>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<style>
.jumbotron {
background-color: #e6ffe6;
text-align: center;
}
</style>
<meta>
</head>

<body>
<div class="jumbotron">
<h1>Welcome to Dunder Mifflin!</h1>
<p>
Dunder Mifflin Inc. (stock symbol <strong>DMI</strong>) is
a micro-cap regional paper and office supply distributor with
an emphasis on servicing small-business clients.
</p>
</div>
</body>
</html>
41 changes: 34 additions & 7 deletions lib/HTMX.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,54 @@ unit class HTMX;

constant term:<> = $?NL;


##### HTMX Tag Export #####

my Str @tags = "$*HOME/.rahx-config/html5-tags-list.csv".IO.lines;
#viz. https://www.w3schools.com/tags/default.asp

constant @all-tags = <a abbr address area article aside audio b base bdi bdo blockquote body br
button canvas caption cite code col colgroup data datalist dd del details dfn dialog div
dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup
hr html i iframe img input ins kbd label legend li link main map mark menu meta meter nav
noscript object ol optgroup option output p param picture pre progress q rp rt ruby s samp
script search section select small source span strong style sub summary sup svg table tbody
td template textarea tfoot th thead time title tr track u ul var video wbr>;

#of which "empty" / "singular" tags from https://www.tutsinsider.com/html/html-empty-elements/
constant @singular-tags = <area base br col embed hr img input link meta param source track wbr>;

my @regular-tags = (@all-tags.Set (-) @singular-tags.Set).keys;

sub list-tags is export {@all-tags.sort }
sub list-singulars is export { @singular-tags.sort }
sub list-regulars is export { @regular-tags }

# Export them so that `h1("text")` makes `<h1>text</h1>` and so on
# eg sub h1(Str $inner) {do-tag 'h1', $inner}

sub do-tag( $tag, $inner, *%h ) {
sub do-regular-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 ~ '>'
'<' ~ $tag ~ $attrs ~ '>' ~ ($inner // '') ~ '</' ~ $tag ~ '>'
}

sub do-singular-tag( $tag, *%h ) {

my $attrs = +%h ?? (' ' ~ %h.map({.key ~ '="' ~ .value ~ '"'}).join(' ') ) !! '';

'<' ~ $tag ~ $attrs ~ ' />'
}

# 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 @regular-tags -> $tag {
OUR::{'&' ~ $tag} := sub ($inner?, *%h) { do-regular-tag( "$tag", $inner, |%h ) }
}

for @singular-tags -> $tag {
OUR::{'&' ~ $tag} := sub (*%h) { do-singular-tag( "$tag", |%h ) }
}
}

Expand Down
113 changes: 0 additions & 113 deletions resources/html5-tags-list.csv

This file was deleted.

Loading

0 comments on commit 2fd7700

Please sign in to comment.