Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 783673f94c
Fetching contributors…

Cannot retrieve contributors at this time

51 lines (42 sloc) 1.41 kb
use Hitomi::StreamEventKind;
sub escape($text, :$quotes = True) {
$text; # TODO
}
class Hitomi::XMLSerializer {
has @!filters;
method serialize($stream) {
return join '', [~] gather for $stream.llist {
my ($kind, $data, $pos) = @($_);
if ($kind ~~ Hitomi::StreamEventKind::start
| Hitomi::StreamEventKind::empty) {
my ($tag, $attribs) = @($data);
take '<';
take $tag;
for @($attribs) -> $attrib {
my ($attr, $value) = @($attrib);
take for ' ', $attr, q[="], escape($value), q["];
}
take $kind ~~ Hitomi::StreamEventKind::empty ?? '/>' !! '>';
}
elsif ($kind ~~ Hitomi::StreamEventKind::end) {
take sprintf '</%s>', $data;
}
else { # TODO More types
take escape($data, :!quotes);
}
}
}
}
class Hitomi::XHTMLSerializer is Hitomi::XMLSerializer {
}
class Hitomi::HTMLSerializer {
}
class Hitomi::TextSerializer {
}
sub get_serializer($method, *%_) {
my $class = ( :xml( Hitomi::XMLSerializer),
:xhtml( Hitomi::XHTMLSerializer),
:html( Hitomi::HTMLSerializer),
:text( Hitomi::TextSerializer) ){$method.lc};
return $class.new(|%_);
}
Jump to Line
Something went wrong with that request. Please try again.