Building a Web Framework My Way
Published: 12/03/2006
In my last job I built a web framework from the ground up, but now that I am working for myself, I need a framework that meets my needs. So I am building a framework called Fiche that has everything I've learned or wanted over the last 9 years of building web apps.
The most radical (if you can to call it that) concept is to punt on HTML completely. I've tried all the various ways of binding html with code, and basically all have limitations I find irritating. No matter what style of binding you use, you always wind up with something not quite HTML/XHTML. Wicket comes the closest with a single attribute (a pattern I used in my framework) but its not very convenient in many circumstances, where you have to do all sorts of gyrations when the single attribute fails (like trying to loop over two rows in a table). In the end I decided for my framework I will go pure xml, and build my schema (ok dtd, I still don't like schemas) a little more framework-friendly. The drawback of course (which eventually is a drawback for the other approaches that try to cram non web information into html) is I can't edit and preview without an application running. The big advantage is the language perfectly fits into both xml (for validation and processing) and the needs of a web framework, ie binding. So far it has only one day of thought behind it (more or less) but so far it looks like this.
<?xml version="1.0" encoding="UTF-8" ?>
<fiche id="main">
<page id="home">
<head>
<javascript import="scripts.js,prototype.js,scriptaculous.js"/>
<css import="my.css"/>
</head>
<body>
<part id="pagestuff" import="#stuff"/>
</body>
</page>
<fragment id="stuff">
<section id="title" flavor="h1">My Blog!</section>
<anchor name="topofpage"></anchor>
<link to="http://apple.com">Apple Computer</link>
<form id="demo">
<text id="name">Your Name Here</text>
<menu id="country">
<item>United Stated</item>
<item>Germany</item>
<item>Japan</item>
</menu>
<select id="colors">
<item>Red</item>
<item>Green</item>
<item>Blue</item>
</select>
<checkbox id="agree">Agree</checkbox>
<radio group="1" id="x">X</radio>
<radio group="1" id="y">Y</radio>
<button id="submit">Submit To Me!</button>
</form>
<img>dancingwillie.gif</img>
<list>
<item>One</item>
<item>Two</item>
<item>Three</item>
</list>
<table id="mytable">
<top>
<row>
<column>Comment</column>
<column>Pants</column>
</row>
</top>
<middle>
<loop var="i" on="{pantlist}">
<row>
<column>{i.comment}</column>
<column><if>{i.comment lt 0}
<do>({-i.quantity})</do>
<else>{i.quantity}</else>
</if></column>
</row>
</loop>
</middle>
<bottom>
<row>
<column>Sum</column>
<column>{pantlist.quantity.sum}</column>
</row>
</bottom>
</table>
</fragment>
</fiche>
Notice it looks somewhat html like, however the framework may generate more than 1 html tag for each fml tag (fiche markup language). Some of the tags that are a single tag in html have different names here, like menu and select. Naming is heirarchical, so the framework will generate nested names if needed, such as in forms or loops. Context access is contained inside {}. As a fan of Stringtemplate (http://stringtemplate.org) I also view putting too much code like things into html as a bad idea, but a little is sneaking in. There are if and loop tags which handle most of the control logic, and most tags and attributes will accept {}-based references. There are no legacy presentation features since I will only use css for presentation.
The logical question is "why the heck are you building yet another web framework"? The answer is "because I hate them all". I really don't but I am building this for me, not anyone else, and I know what my needs are so I'd rather have full confidence that I can make it do what I want.
More as time goes by...
Tag: web