January 30, 2004

Refactoring Erowid 3 HTML Lib

Things move slowly in mail archive land.

Against my better judgement initially, I was convinced to refactor a bunch of my codebase to make it easier for my HTML/CSS person to edit the output pages. After dragging my feet, it is now very very obvious to me that this is a worthwhile endeavor.

I don't know if there is a term for the type of design that I am moving to, where heavily CGI-driven pages have the display rendering (view) code explicitly in the target .. urm.. source code page?

Perhaps the style where the page rendering info is to be found in the file location where the URL says it is is called "sane" style ?

What I have had before is stuff no one else has to ever really edit directly... so a page in PHP might look like (in my old style, now renamed
"erowid 2.crazy" style):

http://www.erowid.org/references/refs.php

(click on that to see what a generic erowid table listing view looks like)

The code in the source file at that location might look a lot like:

<? .several include calls ..
require_once("library1.php"); require_once("...");
$HTMLLib = new HTMLLib_c();
$HTMLLib->Init();

$ViewObject = new ThisDataTypeViewClass_c();
PrintHeader();
if (! $HTMLLib->IsRunLive())
{
$HTMLLib->ShowCache();
}
else
{ $ViewObject->RenderPage();
}
PrintFooter();
Quit();
?>

obviously that's not really what an HTML person wants to see when they open up something to try to change something on a page's display.

The new "sane" style looks more like (I am still working on this refactoring):

<? require_once("refs_view_controller.php"); $View = new $DataTypeView(); ?>
<html>
<? virtual("refs_header_file.php"); ?>

<div class="thisorthat">whatever html stuff here...</div>

<? virtual("refs_search_interface.php"); ?>

Table Name
<table>
<tr><th>Field1 Header</th><th>Field2 Header</th></tr>
<?
$View->PrintRows();
function PrintRow($Data) {
?>
<tr class="whatever"><td class="blah2"><? print $Data['Field1'];?></td><td><? print $Data['Field2'];?></td></tr>
<? } /* end PrintRow function definition */ ?>
</table>


<? virtual("refs_list_paging_interface.php"); ?>

<? virtual("refs_footer_file.php"); ?>

</html>

Posted by Earth at January 30, 2004 12:13 PM
Comments

What does "virtual" mean in this context?

Posted by: Ethan Fremen on January 30, 2004 01:48 PM
Post a comment