expand-string

Started by rrq, April 01, 2015, 04:22:21 PM

Previous topic - Next topic

rrq

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 http://www.realthing.com.au/files/newlisp/expand-string.lsp">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.

Lutz

#1
Thanks Ralph, expand-string.lsp now also in the various section of:

http://www.newlisp.org/modules/">http://www.newlisp.org/modules/