HTML-Builder

 view release on metacpan or  search on metacpan

lib/HTML/Builder.pm  view on Meta::CPAN

use strict;
use warnings;

use Capture::Tiny 0.15 'capture_stdout';
use HTML::Tiny;
use Sub::Install;
use List::MoreUtils 'uniq';

# debugging...
#use Smart::Comments;

our $IN_TAG;


# HTML5 tags from:
# http://en.wikipedia.org/wiki/HTML5#Differences_from_HTML.C2.A04.01_and_XHTML.C2.A01.x
# 18 Feb 2012
#
# Other HTML tags from:
# http://www.w3schools.com/tags/default.asp
# 19 Feb 2012


# !--...--	Defines

sub html5_tags { qw{

    article aside audio bdo canvas command datalist details embed figcaption
    figure footer header hgroup keygen mark meter nav output progress rp rt
    ruby section source summary time video wbr

} }


sub html5_minimal_tags { q{ article aside footer header nav } }

# excl: s
sub deprecated_tags { qw{ applet basefont center dir font menu strike u xmp } }
sub depreciated_tags { deprecated_tags() }


sub conflicting_tags { {
    html_sub => 'sub',
    html_map => 'map',
    html_q   => 'q',
    html_tr  => 'tr',
} }

sub html_tags {

    # excl: sub map q tr

    return qw{

        a        abbr       acronym    address      area       b
        base     bdo        big        blockquote   body       br
        button   caption    cite       code         col        colgroup
        dd       del        dfn        div          dl         dt
        em       fieldset   form       frame        frameset   h1
        head     hr         html       i            iframe     img
        input    ins        kbd        label        legend     li
        link                meta       noframes     noscript   object
        ol       optgroup   option     p            param      pre
                 samp       script     select       small      span
                 strong     style                   sup        table
        tbody    td         textarea   tfoot        th         thead
        title               tt         ul           var

    };
}


sub form_tags { qw{

    form fieldset button input label optgroup option select textarea

}}


sub table_tags { qw{ table tr td th thead tbody tfoot } }


sub minimal_tags {
    return ('h1'..'h5', qw{
        div span p img script br ul ol li style a
    });
}


sub our_tags {
    my @tags = (
        html5_tags(),
        html_tags(),
        deprecated_tags(),
        (keys %{ conflicting_tags() }),
    );
    return uniq sort @tags;
}


sub _attr { die }

sub attr(&) {
    my $code = shift;

    ### in attr...
    _attr($code->());
}

sub _is_autoload_gen {
    my ($attr_href) = @_;

    return sub {
        shift;

        my $field = our $AUTOLOAD;
        $field =~ s/.*:://;

        # XXX
        $field =~ s/__/:/g;   # xml__lang  is 'foo' ====> xml:lang="foo"
        $field =~ s/_/-/g;    # http_equiv is 'bar' ====> http-equiv="bar"



( run in 1.656 second using v1.01-cache-2.11-cpan-39bf76dae61 )