NAME

HTML::TagTree - An HTML generator via a tree of 'tag' objects.

SYNOPSIS

use HTML::TagTree;

my $html = HTML::TagTree->new('html');   # Define the top of the tree of objects.
my $head = $html->head();                # Put a 'head' branch on the tree.
my $body = $html->body();                # Put a 'body' branch on the tree
$head->title("This is the Title of Gary's Page, the opening title...");
$head->meta('', 'name=author CONTENT="Dan DeBrito"');
$body->div->h1('Hello Dolly');           # Example of method chaining to create
                                         # a long branch.
my $table = $body->table('', 'width=100% border=1');
my $row1 = $table->tr();
$row1->td('cell a');
$row1->td('cell b');
$table->tr->td('This is a new row with new cell');  
$table->tr->td('This is a another new row with new data');

# Print to STDOUT the actual HTML representation of the tree
$html->print_html();

# Put HTML into a scalar variable
my $html_source = $html->get_html_text();

# Force destruction of object tree
$html->release();

DESCRIPTION

HTLM::TagTrees allows easy building of a tree objects where
each object represents: 1) a tag 2) its value and 3) any
tag attributes. Valid HTML is build of the tree via a method call.

FEATURES

Smart quoting of tag parameters:
Doing something like this:
   $body->div('','id=nav onclick="alert(\"Hello World\"');
the HTML module will render HTML that looks like:
   <div id="nav" onclick='alert("Hello World")' \>

Reduce whitespace in your HTML rendering by turning
on the no_whitespace_flag.
my $no_whitespace_html_text = $html->get_html_text('',1);

# Or..
my $indent_level = 0;
my $no_whitespace_flag = 1;
print $html_obj->get_html_text($indent_level, $no_whitespace_flag); 

INITIALIZATION

HTML::TagTree->new(tag_name,[value],[attributes])
   Returns a TagTree object

METHODS

Every HTML tag type is an object method.
$obj->tag_name(content,attributes);
   Returns:
      object for valid creation
      undef if tag_name is not a valid name;
   Arguments:
      content:
         Untagged data that goes in between open and close tag. eg
            <b>content</b>
         Content my be a Perl scalar, a ref to a scalar, 
         or ref to a subroutine. Dereferencing occurs at the
         time of HTML rendering (via print_html()
         or get_html_text() methods).
      attributes:
         Attributes of this HTML tag.
         Attributes argument may be a Perl scalar, a ref to a scalar,
         or a ref to a subroutine. Dereferencing occurs at the
         time of HTML rendering.
         Example of attributes:
            'id=first_name name=fn class=str_cl'
get_html_text(indent_level, no_whitespace_flag)
   Returns valid HTML representation of tag tree starting at the object.
   Arguments:
      indent_level:
         Starting amount of indentation. Typically leave undef or 0.
      no_whitespace_flag:
         Set to '1' to prevent insertion of linefeeds and whitespace padding
         for legibility.
print_html()
   Prints the valid HTML to STDOUT
release()
   Destroys all children objects so no objects reference
   this object (and it can be destroyed when it goes out of scope).
set_valid_tags( tag_names )
   Clears and sets what the valid tag names are for which
   objects can be created.

FUNCTIONS

HTML::TagTree::get_http_header();
   Returns the generic HTTP header:
      "Content-type: text/html\nStatus: 200  OK\n\n";

ABSTRACT

The philosophy of HTML::TagTree is to let you create
one region of code with lots of business logic 
for rendering many possible resulting HTML files/output.
This differs from the approach of using business logic code
to decide which HTML template (of many) to render.
So rather than maintaining many HTML templates, you
maintain a Perl file that does all possible customizations
of HTML generation.

This module strives to minimize typing. Object treeing is
just a simple method call, eg:
   $body->h1->b->i('This is a bold, italic heading');

HTML::TagTree removes the worries of making simple HTML syntax
errors such as no matching closing tag for an open tag.

VERSION

HTML::TagTree version 1.03.

PREREQUISITES

No prerequisites.

AUTHOR

Dan DeBrito (<ddebrito@gmail.com>)

COPYRIGHT

Copyright (c) 2007 - 2011 by Dan DeBrito. All rights reserved.

LICENSE

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".

Please refer to the files "Artistic.txt", "GNU_GPL.txt" and "GNU_LGPL.txt" in this distribution for details!

DISCLAIMER

This package 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 "GNU General Public License" for more details.