NAME

DSL::HTML::Compiler - Compile HTML into DSL::HTML templates

DESCRIPTION

This module provides functions that let you take HTML files or strings and convert them into DSL::HTML templates. This is particularily useful if you have a designer build your page layout in HTML and need to convert it to a template before adding logic.

SYNOPSYS

use strict;
use warnings;
use utf8;
use DSL::HTML::Compiler;

my $tc = compile_from_file( 'bar', "/path/to/file.html" );

my $template_code = compile_from_html( 'foo', <<EOT );
<html>
    <head>
        <title>foo</title>
        <link href="b.css" rel="stylesheet" type="text/css" />
        <script src="a.js"></script>
    </head>

    <body>
        <div id="foo" class="bar baz">
            xxx
        </div>
        <p>
        yyyy
        <div id="foo" class="bar baz">
            xxx
        </div>
    </body>
</html>
EOT

# Only necessary if your html contains utf8, or in some cases when no ascii
# character can be used as a delimiter due to text content.
binmode STDOUT, ":utf8";
print $template_code;

This will print the following that can be inserted into a perl module:

use strict;
use warnings;
use utf8;
use DSL::HTML;

template foo {
    tag head {
        tag title {
            text q'foo';
        }

        css q'b.css';

        js q'a.js';
    }

    tag div('class' => q'bar baz', 'id' => q'foo') {
        text q' xxx ';
    }

    tag p {
        text q' yyyy ';

        tag div('class' => q'bar baz', 'id' => q'foo') {
            text q' xxx ';
        }
    }
}

1;

Delimiter for qX...X is chosen via a fall-through (see delimiters)

DELIMITERS

Delimiter is chosen from this list, the first delimiter not found in the string being quoted is used. If no valid delimiter can be found then an exception is thrown.

'
"
`
/
|
:
~
!
-

This one is unicode

a..z A..Z

If all else fails try a-z and A-Z.

EXPORTS

my $perl_code = compile_from_html( $name, $html )

Build perl code from html text.

my $perl_code = compile_from_file( $name, $file )

Build perl code from an html file.

AUTHORS

Chad Granum exodist7@gmail.com

COPYRIGHT

Copyright (C) 2013 Chad Granum

DSL-HTML is free software; Standard perl license (GPL and Artistic).

DSL-HTML is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.