chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] More thoughts on Ersatz


From: Ivan Shmakov
Subject: Re: [Chicken-users] More thoughts on Ersatz
Date: Tue, 12 Mar 2013 20:15:14 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

>>>>> Peter Bex <address@hidden> writes:
>>>>> On Tue, Mar 12, 2013 at 07:04:54PM +0100, Moritz Heidkamp wrote:

[…]

 >> This doesn't seem like a very good idea to me.  You might generate
 >> invalid JSON if the values you pass into the template don't happen
 >> to have textual representations which also happen to be valid JSON
 >> values (if I understand the way Jinja works correctly here).  I'd
 >> suggest using a proper JSON emitter like the one contained in medea
 >> (http://wiki.call-cc.org/eggref/4/medea) instead.

 > Not to sound like a broken record, but I'd add that this applies 100%
 > to HTML/XML as well.  I would suggest using SXML or something similar
 > over a string-based templating language.  This allows you to prevent
 > injection bugs as well as accidental mismatching of opening/closing
 > tags.

        Yet another idea is to prepare an XML document (using either
        notation) holding the “mostly static” part of the result, and
        also an XML document holding all the “repeated” (or “optional”)
        subtrees.  Both the “insertion points” in the former, and such
        subtrees, are then marked, one way or another (e. g., I opted to
        use the HTML ‘class’ attribute), and the code simply composes
        the result by attaching such pieces to each other.

        For the most part, the algorithm boils down to searching for
        some “insertion point” and appending a child to it — either a
        text node, or a subtree (typically prepared beforehand.)  The
        whole process is recursive, starting from the lesser pieces, and
        up to the resulting DOM.  (But then, the resulting DOM may be
        walked over for post-processing rather easily.)

        There's a minor convenience in the use of the “XML” notation for
        the templates, too: such templates may be constructed in a way
        that allows for them to be viewed with the target application
        itself (such as a Web browser, should XHTML be considered.)

        Obviously, there's one more convenience of having the templates
        separated from the application's code proper, irrespective of
        the notation chosen.

-- 
FSF associate member #7257



reply via email to

[Prev in Thread] Current Thread [Next in Thread]