Greetings monks,

I've been working on an interesting task and decided to ask for comments about it. I don't know if I have specific questions exactly, but I'm trying to do things as maintenance-friendly as possible and am willing to listen to suggestions.

The fuzzy picture is:

Given: a perl structure (hashrefs of hashrefs).

Produce: a suite of web pages.

No, I haven't fully fleshed out the solution, but I have completed several parts and I know how I need to finish it. I'm just wondering if I'm overlooking something useful.

As an example, here's a sample structure in YAML (the actual config file will be XML, but YAML is easy for me to develop with, and the config format is not the issue here):

--- Benefits: Desc: your benefits Subcategories: Employee Recognition: Url: http://blah.com/recognition/index.html topics: Employee Service Awards: Url: http://blah.com/recognition/employee_service.html General Recognition and Performance-based Awards: Url: http://blah.com/recognition/awards.html Equity Plans: Url: Overridden Regional Content URL! topics: Incentive Plan: Url: http://blah.com/equity_plans/incentive/override.html Url: http://blah.com/index.html Compensation: Subcategories: {} Url: http://blah.com/comp/index.html Corporate Policies: Subcategories: {} Url: http://blah.com/corp_policies/index.html Early Retirement: Subcategories: {} Url: http://blah.com/ero/index.html
The structure above is actually the output of a process I've written that merges in regional content to default content (using Hash::Merge to great effect), which is the main purpose of generating HTML in the first place -- to route the employee automatically to regional content, rather than forcing her to navigate her way between multiple default and regional content pages.

However, there is still a heirarchy of pages to be built: the user will see a page of category links, with subcategory links subordinated under them. Clicking on a category or subcategory will route that person to static content, so maybe I'm making the problem out to be harder than it really is.

Anyway, in order to make the pages edit-friendly, I'm also looking at using Text::Template or TTT, so that dynamic content is encapsulated within a template. This way, our non-technical folks can edit static content on the template.

For the curious, the subs I've been working on to create the HTML pages are here. This is absolutely Code In Progress, and is not the finished product by any means.

sub createPages { my $filename = shift; my $content = shift; my $desc = $content->{Desc}; my $url = $content->{Url}; my $subcontent = $content->{Regions} || $content->{Categories} || $content->{Subcategories} || $content->{Topics}; open OUT, ">$filename.html"; foreach my $key ( sort keys %$subcontent ) { print OUT buildSubject( $filename, $key, $subcontent->{$key} ); } close OUT; } sub buildSubject { my $filename = shift; my $name = shift; my $content = shift; my $desc = $content->{Desc}; my $url = $content->{Url}; my $subcontent = $content->{Regions} || $content->{Categories} || $content->{Subcategories} || $content->{Topics}; my @out = (); foreach my $key ( sort keys %$subcontent ) { my $url = $subcontent->{$key}->{Url}; push @out, "<a href='$url'>$key</a>\n" if $url; push @out, $key unless $url; } my $header = "<a href='$filename.$name.html'>$name</a>"; $header = "<a href='$url'>$name</a>" if $subcontent; print $subcontent; return "<h2>$header</h2>\n<h3>$desc</h3>\n", join ' | ', @out; }

UPDATE Per Holli's suggestion, here is a Template Toolkit prototype I'm working on for the main display page.
<html> <body> # INTERPOLATE => 1 [% FOREACH name = Categories.keys %] <h2><a href="[% Categories.$name.Url %]">$name</a></h2> <h3>[% Categories.$name.Desc %]</h3> [% FOREACH subname = Categories.$name.Subcategories.keys %] <a href="[% Categories.$name.$subname.Url %]">$subname</a> [% END %] [% END %] </body> </html>

In reply to Generating HTML from a Hashref of Hashrefs by rje

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.