summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Katana/HTML/Page.rakumod39
-rw-r--r--lib/Katana/HTML/Tag.rakumod26
2 files changed, 65 insertions, 0 deletions
diff --git a/lib/Katana/HTML/Page.rakumod b/lib/Katana/HTML/Page.rakumod
new file mode 100644
index 0000000..9026731
--- /dev/null
+++ b/lib/Katana/HTML/Page.rakumod
@@ -0,0 +1,39 @@
+use v6.d;
+use Katana::HTML::Tag;
+unit class Katana::HTML::Page:api<1> is export;
+
+has Str $!doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
+has @!body-tags is required;
+has Str $!title is required;
+
+submethod BUILD(:@!body-tags where *.elems > 0, Str :$!title where * ne '') { }
+
+method generate {
+ my @tags;
+ push @tags, Tag.new: name => 'html',
+ params => (
+ xmlns => 'http://www.w3.org/1999/xhtml',
+ lang => 'en',
+ 'xml:lang' => 'en'
+ );
+
+ push @tags, Tag.new: name => 'head', succ => @!body-tags;
+ push @tags, Tag.new: name => 'title', text => $!title;
+
+ say $!doctype;
+ self.recurse(@tags);
+}
+
+method recurse(@tags) {
+ my @sgat; # tags spelled in reverse.
+ for @tags -> $tag {
+ say $tag.open;
+ say $tag.text if $tag.has-text;
+ unshift @sgat, $tag;
+ }
+ for @sgat -> $tag {
+ say $tag.close unless $tag.is-mono;
+ self.recurse($tag.succ) if $tag.has-succ;
+ }
+}
+
diff --git a/lib/Katana/HTML/Tag.rakumod b/lib/Katana/HTML/Tag.rakumod
new file mode 100644
index 0000000..50d5585
--- /dev/null
+++ b/lib/Katana/HTML/Tag.rakumod
@@ -0,0 +1,26 @@
+use v6.d;
+unit class Katana::HTML::Tag is export;
+
+has Str $.name;
+has Str $.text;
+has Str %.params;
+has Bool $.is-mono = False;
+has Katana::HTML::Tag @.succ;
+
+method has-text returns Bool { defined $.text }
+method has-succ returns Bool { defined $.succ }
+
+method open returns Str {
+ return "<{$.name}{self.params} />" if $!is-mono;
+ return "<{$.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;
+}