Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gfldex/perl6-typesafe-xhtml-writer
Generate XHTML1.1 with subs using Typesafe::HTML
https://github.com/gfldex/perl6-typesafe-xhtml-writer
Last synced: 13 days ago
JSON representation
Generate XHTML1.1 with subs using Typesafe::HTML
- Host: GitHub
- URL: https://github.com/gfldex/perl6-typesafe-xhtml-writer
- Owner: gfldex
- License: artistic-2.0
- Created: 2016-01-12T13:45:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-21T11:04:23.000Z (almost 8 years ago)
- Last Synced: 2024-11-06T05:44:06.720Z (2 months ago)
- Language: Perl6
- Size: 157 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Typesafe::XHTML::Writer
[![Build Status](https://travis-ci.org/gfldex/perl6-typesafe-xhtml-writer.svg?branch=master)](https://travis-ci.org/gfldex/perl6-typesafe-xhtml-writer)Write XHTML elements utilising named arguments to guard against typos. Colons
in names of XHTML attributes are replaced with a hyphen (e.g. `xml:lang`). Use
the html element names as an import tag or `:ALL` to get them all. Please
note that there is a `dd`-tag what will overwrite `dd` from the settings.The actual module is generated form the official XHTML 1.1 Schema. There is no
offical XML Schema for HTML5 (because it isn't XML), if you happen to come
across one that works please let me know.It uses [Typesafe::HTML](https://github.com/gfldex/perl6-typesafe-xhtml-writer)
to guard against lack of quoting of HTML-tags. As a dropin-replacement of
`HTML::Writer`, it's about 5% slower then the former. See below how to "overload"
that module, see below.
[`Typesafe::HTML::Skeleton`](https://raw.githubusercontent.com/gfldex/perl6-typesafe-xhtml-writer/master/lib/Typesafe/XHTML/Skeleton.pm6)
provides the routine `xhtml-skeleton` that takes instances of `HTML` (the type)
as parameters and returns `HTML`. The named arguments takes a single or a list
of tags of type `HTML` to be added to the header of the resulting XHTML
document. `HTML` is a flat eager string that is about 5% slower then without
typesafety. If you need a DOM use a module that does not focus on speed.## Usage:
```
use v6;
use Typesafe::XHTML::Writer :ALL;put html( xml-lang=>'de',
body(
div( id=>"uniq",
p( class=>"abc", 'your text here'),
p( 'more text' ),
'this will be quoted with < and &
'
)
));put span('this will also be quoted with HTML-entities');
```With skeleton:
```
use v6;
use Typesafe::XHTML::Writer :p, :title, :style;
use Typesafe::XHTML::Skeleton;put xhtml-skeleton(
p('Hello Camelia!', class=>'foo'),
'Camelia can quote all the <<<< and &&&&.',
header=>(title('Hello Camelia'), style('p.foo { color: #fff; }' ))
);
```
## Enable typesafe concatenation```
use v6;
use Typesafe::HTML;
use Typesafe::XHTML::Writer :p;
use Typesafe::XHTML::Skeleton;my $inject = 'Hello Camelia!</span>");
# OUTPUT:
# <span id="foo">
# <span>Hello Camelia!</span>
# </span>
```## Enable indentation
```
use Typesafe::XHTML::Writer :writer-shall-indent; # :ALL will work too
writer-shall-indent True;
```## License
(c) Wenzel P. P. Peppmeyer, Released under Artistic License 2.0.