Skip to content

Commit

Permalink
Merge pull request #2 from librasteve/steve-01
Browse files Browse the repository at this point in the history
Basic Tag Load and Export
  • Loading branch information
librasteve authored Jul 22, 2024
2 parents 8e3ce07 + c05d26c commit 5d609dc
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 21 deletions.
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
.precomp/
/HTMX-*
.DS_Store
.precomp
.lib/precomp
.swp
.ipynb_checkpoints/*
.log
.p6.swp
.pm6.swp
.Dockerfile.swp
.json.swp
.yaml.swp
.pem
.iml
18 changes: 18 additions & 0 deletions Build.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use v6.d;

class Build {
method build($dist-path) {

#| also specified in en_SI.rakumod
my $rahx = '.rahx-config';
my $file = 'html5-tags-list.csv';

#| mkdir will use existing if present
mkdir "$*HOME/$rahx";

copy "resources/$file", "$*HOME/$rahx/$file";

exit 0
}
}

30 changes: 14 additions & 16 deletions META6.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
"auth": "zef:librasteve",
"name": "HTMX",
"description": "blah blah blah",
"version": "0.0.1",
"perl": "6.d",
"authors": [
"librasteve"
],
"build-depends": [
],
"depends": [
],
"description": "blah blah blah",
"license": "Artistic-2.0",
"name": "HTMX",
"perl": "6.d",
"auth": "zef:librasteve",
"depends": [],
"build-depends": [],
"test-depends": [],
"provides": {
"HTMX": "lib/HTMX.rakumod"
},
"resources": [
"html5-tags-w3schools.csv",
"html5-tags-list.csv"
],
"source-url": "",
"tags": [
],
"test-depends": [
],
"version": "0.0.1"
}
"license": "Artistic-2.0",
"tags": [],
"source-url": ""
}
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ TODOS

#### Minimum Lovable Product (`MLP`)

- [ ] Get a definitive list of HTML tags
- [ ] Export them so that `h1("text")` makes `<h1>text</h1>` and so on
- [x] Get a definitive list of HTML tags
- [x] Export them so that `h1("text")` makes `<h1>text</h1>` and so on
- [x] Pass and format the HTMX attributes
- [ ] Bring in synopsis from design
- [ ] Do the ¶ term
- [ ] Make a parse script (& instructions how to watch a dir)
- [ ] Write some tests
- [ ] Write some docs in POD6
- [ ] Release with App::Mi6
- [ ] Publish as raku-htmx on the htmx Discord
Expand Down
18 changes: 18 additions & 0 deletions bin/html5-tags-extract.raku
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env/raku

# This script extracts HTML5 tag names from the table at
# https://www.w3schools.com/tags/default.asp

my @lines = "../resources/html5-tags-w3schools.csv".IO.lines;

@lines.shift; # remove header row
@lines.shift; # remove !-- --
@lines.shift; # remove !DOCTYPE
@lines .= grep: {! /'Not supported in HTML5'/}; # remove deprecated
@lines .= map: *.split(",")[0]; # take column 1
@lines .= map: *.subst('<', ''); # \ rm angle brackets
@lines .= map: *.subst('>', ''); # /
@lines .= grep: {! /'h1'/}; # remove '<h1> to <h6>' row
for ^6 { @lines.append: 'h' ~ ++$ }; # put in h1..h6 rows

spurt "../resources/html5-tags-list.csv", @lines.sort.join: "\n";
7 changes: 7 additions & 0 deletions bin/synopsis-rahx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env raku
use v6.d;

use HTMX;


say h1('text', :class<jumbotron>);
29 changes: 28 additions & 1 deletion lib/HTMX.rakumod
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
unit class HTMX;

constant term:<> = $?NL;


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

my Str @tags = "$*HOME/.rahx-config/html5-tags-list.csv".IO.lines;

# 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 ) {

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

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

# 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 ) }
}
}



=begin pod
Expand All @@ -25,7 +52,7 @@ librasteve <[email protected]>
=head1 COPYRIGHT AND LICENSE
Copyright 2024 librasteve
Copyright (c) 2024 Henley Cloud Consulting Ltd.
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
Expand Down
113 changes: 113 additions & 0 deletions resources/html5-tags-list.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
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
Loading

0 comments on commit 5d609dc

Please sign in to comment.