(no subject)

Jun 21, 2006 15:59

Babies and porn: They both drive adoption of new technology. And I suppose they're linked on a more fundamental level too...

Anyway: During the most recent redesign of Isabel's web-site, I obtained some insight: Web development is freaky easy. caffeine_girl found CSS code to render something like a tab select control. But a static implementation means you have to have a full HTML file for each tab, and each file would be mostly duplicated markup. That's too lame to attach my name too!

So...



...the solution (I chose) is to dynamically generate just the tabbed portion of the page.

Apache web server has this "server side include" feature which scans your HTML file and adds new content before sending it to the client. One thing you can have it "include" is the output of a CGI script. So I wrote a script in Perl that scans the directory for specially named "tab" files, generates html for the tabs, and then pulls in the "active" tab content from the appropriate file. How cool is that? (A: very).

What was amazing to me wasn't the technical merits of the solution (and I've already got ideas for a better system), but how easy it was for guy who knew only a little HTML to get a CSS, SSI, CGI, and Perl based solution up and running and looking good. I got tripped up a bit on Apache configuration and Perl syntax, but other than that it was a one evening job. It can take a month at work to perfect some arcane aspect of the RIO diver. Web development is the clearly the crack cocaine of programming.

I guess driver development would be the...K?

I'm sure you're all clamoring to see it, and we're in an lj-cut, so here's my script:

#!/usr/bin/perl -wT
use CGI qw(:standard);

print header;

@active_content=("");

opendir(IMD, ".");
@tabfiles = sort(grep(/__tab[0-9]_.*\.html$/, readdir(IMD)));
closedir(IMD);

print "
    \n";

    $activetab = $ENV{QUERY_STRING_UNESCAPED};

    foreach $tabfile (@tabfiles)
    {
    $tabfile =~ /__tab[0-9]_(.*)\.html$/;
    $tabname = $1;

    if( ($activetab eq "") || ($activetab eq $tabname) )
    {
    $activetab = $tabname;

    print "
  • $tabname
  • \n";

    open(TABFILE, $tabfile);
    @active_content = ;
    close(TABFILE);
    }
    else
    {
    print "
  • $tabname
  • \n";
    }
    }

    print "
\n";
print "
\n";
print @active_content;
print "\n";

Previous post Next post
Up