NAME
HTML::Builder - A declarative approach to HTML generation
VERSION
This document describes 0.003 of HTML::Builder - released February 18,
2012 as part of HTML-Builder.
SYNOPSIS
use HTML::Builder ':minimal';
# $html is:
my $html = div { id gets 'main'; p { 'Something, huh?' } };
DESCRIPTION
A quick and dirty set of helper functions to make generating small bits
of HTML a little less tedious.
FUNCTIONS
our_tags
A unique, sorted list of the HTML tags we know about (and handle).
tag($tag_name, $code_ref)
The actual function responsible for handling the tagging. All of the
helper functions pass off to tag() (e.g. "div()" is "sub div(&) {
unshift 'div'; goto \&tag }").
html5_tags()
The list of tags we think are HTML5.
html_tags()
The list of tags we think are HTML ( < HTML5, that is).
our_tags()
The unique, sorted list of all tags returned by html5_tags() and
html_tags().
USAGE
Each supported HTML tag takes a coderef, executes it, and returns the
output the coderef writes to STDOUT with the return value appended.
That is:
div { say h1 { 'Hi there! }; p { "Nice day, isn't it?" } }
Generates:
Hi there!
Nice day, isn't it?
Element attributes are handled by specifying them with "gets". e.g.:
div { id gets 'main'; 'Hi!' }
Generates:
Hi!
gets may be specified multiple times, for multiple attributes.
Nested Tags
When one tag function is called from within another, the nested tag will
print its output to STDOUT rather than returning it. That means that
this:
div { print h1 { 'Hi there! }; p { "Nice day, isn't it?" } }
...and this:
div { h1 { 'Hi there! }; p { "Nice day, isn't it?" } }
Behave identically, from the perspective of the caller.
EXPORTED FUNCTIONS
Each tag we handle is capable of being exported, and called with a
coderef. This coderef is executed, and the return is wrapped in the tag.
Attributes on the tag can be set from within the coderef by using gets,
a la "id gets 'foo'".
Export Groups
:all
Everything.
Well, what @CGI::EXPORT_TAGS{qw{ :html2 :html3 :html4 }} thinks is
everything, at any rate.
This isn't, perhaps, optimal, but I haven't run into any issues with it
yet. That being said, I'm open to changing our tags list, and where it's
generated from.
:minimal
A basic set of the most commonly used tags:
h1..h4 div p img span script br ul ol li style a
:html5
HTML5 tags ("article", "header", "nav", etc) -- or at least what
Wikipedia thinks are HTML5 tags.
:moose_safe
Everything, except tags that would conflict with Moose sugar (currently
"meta").
ACKNOWLEDGMENTS
This package was inspired by Template::Declare::Tags... In particular,
our "gets::AUTOLOAD" is pretty much a straight-up copy of
Template::Declare::Tags' "is::AUTOLOAD", with some modifications. We
also pass off to HTML::Tiny, and allow it to do the work of actually
generating the output. Thanks! :)
SEE ALSO
Please see those modules/websites for more information related to this
module.
* CGI (in particular, %CGI::EXPORT_TAGS)
* HTML::Tiny
* Template::Declare::Tags
SOURCE
The development version is on github at
and may be cloned from
BUGS
Please report any bugs or feature requests on the bugtracker website
https://github.com/RsrchBoy/html-builder/issues
When submitting a bug or request, please include a test-file or a patch
to an existing test-file that illustrates the bug or desired feature.
AUTHOR
Chris Weyl
COPYRIGHT AND LICENSE
This software is Copyright (c) 2012 by Chris Weyl.
This is free software, licensed under:
The GNU Lesser General Public License, Version 2.1, February 1999