expand-string

For the Compleat Fan

expand-string

Postby ralph.ronnquist » Wed Apr 01, 2015 11:22 pm

The other day I took a moment to device an expand-string functionality so that I could author HTML pages more easily by using HTML page templates with keys that get replaced by content somewhat similar to the expand function, but for keys in strings (and wihtout tokenization).

Eventually I realised I needed both the plain expansion of keys replaced by values, and something more complex, that maps an expansion fragment from the template over a range of key values. This would be for creating a section of a repeated HTML fragment, where its keys take on successive values from a programatically defined range.

And, just for the fun of it, I also included the ability of embedding newlisp code into the template, as an alternative to the key replacement. This gives more control to the template authoring, to decide on which data is fitted into it.

I've made it available here as it may possibly be a quite useful utility.

I'm also quite interested in learning other good approaches to the HTML authoring problem with newlisp CGI handlers. My approach typically results in that files come in pairs, with a CGI script that, following its computations, ends by expanding a template as its response. The template may of course be an inline string, but I find the mixing of HTML and newlisp code difficult to read, and therefore cumbersome to maintain. So I end up having separate HTML template files, with almost only HTML code apart from the special <MAP>..</MAP> construct for repeated expansion.

Edit: I suppose with a special interpreter, which skips the first line and then treats the rest as a template, one can do reponse authoring in the style of PHP (etc). That's the reason I've included the "<newlisp ... ?>" eval construct in addition to the "<EVAL> .. </EVAL>" construct. Though, this still suffers from the mixing of newlisp code and HTML code, which I think makes a less maintanable solution.
ralph.ronnquist
 
Posts: 178
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: expand-string

Postby Lutz » Thu Apr 02, 2015 8:58 am

Thanks Ralph, expand-string.lsp now also in the various section of:
http://www.newlisp.org/modules/
Lutz
 
Posts: 5258
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to Anything else we might add?

Who is online

Users browsing this forum: No registered users and 3 guests

cron