OOPS! I did not update the example code in the synopsis. It has been updated now.
For the other issues, here goes.
- You are basically asking for the history of how all of this began about six years ago. You might want to read my home node for the history.
- Most other HTML modules use OO. I am a function oriented person and wrote this so I could have easier to use (for me) functions.
Do you know how big my files would be if I statically produced HTML? My site menu alone is 41.2 kb. Keeping it updated across approximately 300 pages would cripple me. When I first started, without being able to produce my site menu with programming, I would have had to quit after only a few pages (since at the time I had a space cap of 10 Mb). Perl has allowed me to keep my file sizes extremely small in some places.
Another bit of history, some did not like seeing me printing HTML directly in my code, and others loathe my line subroutine. So a few months ago, I decided to see if I could start hiding both. One serendipitous side effect of writing this was I was separating my logic from my display, which many here have been telling me to do all along, I just had not seen how to do it. (One script I wrote was three screens long, with this module I was able to reduce it to less than one.)
I can not speak for the other authors, so I will only speak of my own work with head and body.
- The head of an HTML document is not printed to the screen, so the order of the elements inside it do not have to be in any particular order, so I came up with an arbitrary order for them to appear and was able to have their values assigned in a hashref.
- The body of an HTML document is printed to the screen, so the order of the elements inside it does matter, so I could not make any arbitrary order for them to appear meaning I have to use coderefs so the elements appear on the order I (or the user) wish them to appear. body and other structural elements can have almost anything inside them. An aside could contain a ramble which includes several paragraphs and a table. A section could include several paragraphs with a list between the third and fourth paragraphs.
Here is the template I wrote for my pages using the module...
sub my_html_template {
my (%opt) = @_;
my $heading = textify(basename($0)) !~ /index/ ? textify(basename($0
+)) : 'My '.lc((split(/\//,cwd))[-1]);
my $title = textify(join(' - ',($root_name,map(ucfirst,split(/\//,$r
+elative_path)))));
$title .= textify(" - $opt{heading}") if $opt{heading};
my $page_heading = $opt{heading} ? $opt{heading} : $heading;
my $page_heading_id = idify($page_heading);
$page_heading =~ s/_/ /g;
html(0, {
head => {
title => $title,
links => [map {{ rel => 'stylesheet', type => 'text/css', href =
+> $_ }} get_styles($root_path.'/files/css')],
scripts => [{ type => 'text/javascript', src => "$root_link/file
+s/javascript/list.js" }]
},
body => [ sub {
nav(2, sub {
heading(3,1,'Site menu', { id => 'Site_menu' });
list(4,'u',get_menu( directory => $root_path, tab => 2, color
+=> 0, full => 0 ), { onclick => 'list_onclick(event)' });
link_list(3,qq($root_user off-site),%other_sites);
link_list(3,qq(Reciprocated links),%reciprocated_links);
});
article(2, sub {
heading(3,1,$page_heading, { id => $page_heading_id });
&{$opt{code}};
paragraph(4,"Contact $link{mail}!", { class => 'address' }); #
+ I should use the address tag here.
paragraph(4,'I am against the Internet Blacklist Legislation .
+..', { class => 'address' });
});
}],
});
}
I went one step further for a lot of my pages with this...
sub story {
my ($source) = @_;
my $tab = 3;
while (my $line = <$source>) {
chomp($line);
if ($line =~ m/^</) {
line($tab,$line);
}
elsif ($line =~ /^[1-6]\s/) {
my ($heading,$text) = split(/ /,$line,2);
heading($tab,$heading,$text);
}
elsif ($line =~ /^[bh]r$/) {
line($tab,"<$line>");
}
else {
paragraph($tab,$line);
}
}
}
So, when I go to display the page, I can do this...
my_html_template( code => sub { story(*DATA) });
Did that cover everything?
Have a cookie and a very nice day!
Lady Aleena
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.