diff options
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; + } +} + |
