Updated: 11/5/2005; 6:06:16 PM.
Chris Double's Radio Weblog
        

Wednesday, June 30, 2004

For the Factor web server I want to have a way of generating HTML that looks HTML-ish and is easy to use. I've tried various approaches and the one I've settled with at the moment is in cont-html.factor. Loading this into Factor 0.60.3 will you let use it interactively:

  "cont-html.factor" run-file
  USE: cont-html

Once loaded you can write HTML to stdout by embedding HTML looking code:

 
  <a href="http://www.double.co.nz/factor/cont-html.factor" a> [
     "Link Text" write 
   ] </a> 
 => <a href="http://www.double.co.nz/factor/cont-html.factor">Link Text</a>

( action-url -- ) <form method="post" action="rot" form> [ <p> [ "Enter Some Text" write ] </p> <input type="text" size="20" name="input1" input> <input type="submit" value="Ok" input> ] </form> => <form> <p>Enter Some Text</p> <input type="text" size="20" name="input1"> <input type="submit" value="Ok"> </form>

This is actual Factor code that looks very HTML like and generates the HTML you'd expect. The code can also generate attribute tags dynamically instead of 'inline' as above. Things like '<input=' and 'size=' are words in Factor that set attributes, generate tags, etc as expected. The closing tags like </form> write the output to standard out. This gives you some of the functionality that JSP's would giv you.

Prior to this I had code like '[ [ "text" write ] input ] form' which became a bit unreadable once definitions got fairly nested - mainly due to the tag name coming after the code block. I don't know if the above will work for more 'real world' stuff but it has a nice feel to it and so far works reasonably well. I think it's a nice test of an 'embedded language' inside of Factor anyway.


1:50:30 PM      

© Copyright 2005 Chris Double.
 
June 2004
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
May   Jul



Click here to visit the Radio UserLand website.

Listed on BlogShares

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.