HTML::TagTree(3pm)

πŸ“¦
version 1.03 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– HTML::TagTree β€” the HTML::TagTree(3pm) manual, but make it cute ✨

okay bestie, sit down, hydrate, because this one is genuinely iconic. it's an HTML generator that works off a whole tree of tag objects πŸŒ³πŸ’…


✨ NAME ✨

HTML::TagTree β€” an HTML generator via a tree of 'tag' objects. no cap, that's the whole pitch 🫢


🌸 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();

like??? look at that chaining. $body->div->h1('Hello Dolly') is main character energy and it's literally one line πŸ”₯


πŸ¦‹ DESCRIPTION πŸ¦‹

so HTML::TagTree lets you build a tree of objects where each object represents three things, and yes there are exactly three:

  1. a tag
  2. its value
  3. any tag attributes

and then valid HTML gets built out of that tree just by calling a method. that's it. that's the vibe. πŸ’«


πŸŽ€ FEATURES πŸŽ€

Smart quoting of tag parameters β€” it just knows, bestie:

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")' \>

not it fixing your quote chaos for you 😭 iconic.

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);

pretty output when you want it, zero padding when you don't. πŸ’…


🌈 INITIALIZATION 🌈

  • HTML::TagTree->new(tag_name,[value],[attributes]) β€” Returns a TagTree object 🫢

πŸ‘‘ METHODS πŸ‘‘

Every HTML tag type is an object method. every. single. one. 🧚

  • $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 πŸ’œ

okay this part is lowkey the philosophy and it slaps:

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. ✨ NO MORE UNCLOSED TAGS ✨ we love to see it πŸ™ˆ


🌟 VERSION 🌟

HTML::TagTree version 1.03. πŸ’…


πŸ“ PREREQUISITES πŸ“

No prerequisites. none. zero. it just works. πŸŽ€


πŸ’– AUTHOR πŸ’–

Dan DeBrito (<ddebrito@gmail.com>) 🫢


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.


okay that's the whole page, you're officially a HTML::TagTree girlie now πŸ’…πŸŒ³βœ¨ this was HTML::TagTree version 1.03, docs generated by perl v5.36.0, dated 2022-10-15 β€” now go build a tree and print it, bestie, periodt πŸŽ€πŸ«Ά

πŸ“¦ where this page comes from