diff options
| author | Paul Buetow <paul@buetow.org> | 2022-04-19 22:54:11 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2022-04-19 22:54:11 +0100 |
| commit | c6a252b79db57f3480221cf25213fb8c0993ac3a (patch) | |
| tree | b73a2674976c58272c3acda9062d354ed59271ac /lib | |
| parent | 2d6c6743b66935442c16efcda624f954bc176b8c (diff) | |
Tag is in a module
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Katana/Tag.rakumod | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Katana/Tag.rakumod b/lib/Katana/Tag.rakumod new file mode 100644 index 0000000..c1b6204 --- /dev/null +++ b/lib/Katana/Tag.rakumod @@ -0,0 +1,44 @@ +use v6.d; + +unit module Katana:api<0>; + +class Tag is export { + has Str $.name; + has Str $.text; + has Str %.params; + has Tag @.succ; + + method has-text returns Bool { defined $.text } + method has-succ returns Bool { defined $.succ } + + method open returns Str {"<{$.name}{self.params}>" } + method close returns Str { "</{$.name}>" } + + method params returns Str { + return '' unless defined %!params; + my @params; + for %!params.kv -> $key, $val { + push @params, " $key='$val'"; + } + return @params.join; + } +} + +multi sub recurse-tags(Str $doctype, @open-stack) is export { + say $doctype; + recurse-tags @open-stack; +} + +multi sub recurse-tags(@open-stack) is export { + my @close-stack; + for @open-stack -> $tag { + say $tag.open; + say $tag.text if $tag.has-text; + unshift @close-stack, $tag; + } + for @close-stack -> $tag { + say $tag.close; + recurse-tags $tag.succ if $tag.has-succ; + } +} + |
