Qpy is only used when quoting="xml"
, thus if you run with
quoting="str"
you will not need to have Qpy installed, but you
will need to take care of quoting yourself.
As an example, let’s use the code from the the evoque_mq
benchmark that is included in the distribution:
First, make quoting="str"
the domain-wide default, and
we can also set, on the domain’s globals, the quoting function we want
to use:
from evoque.domain import Domain domain = Domain(/path/to/evoque/bench/evoque, quoting="str") import cgi domain.set_on_globals("quote", cgi.escape)
In the template itself template_mq.html
then specify explicitly the values that need to be quoted:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <title>${quote(title)}</title> </head> <body> $evoque{header_mq.html} $begin{greeting}<p>Hello, ${quote(you)}!</p>$end{greeting} $evoque{#greeting, you=user} $evoque{#greeting, you="me"} $evoque{#greeting, you="world"} <h2>Loop</h2> $if{items} <ul> $for{idx, item in enumerate(items)} <li${idx+1==len(items) and " class='last'" or ""}>${quote(item)}</li> $rof </ul> $fi $evoque{footer.html} $test{ title='Just a test', user='joe', items=['a', '<b/>', 'c'] } </body> </html>
Rendering is as usual, for example:
data = dict(title="Just a test", user="joe", items=["<n>%d</n>" % (num) for num in range(1, 15)]) domain.get_template("template_mq.html").evoque(data)