Skip to content

Commit

Permalink
Add new UL4 tags that can be used to either render a template or prin…
Browse files Browse the repository at this point in the history
…t an object.
  • Loading branch information
doerwalter committed Mar 10, 2022
1 parent 45fb98f commit 9491e80
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 51 deletions.
4 changes: 4 additions & 0 deletions docs/NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Changes in HEAD (released 01/??/2022)
starts with a valid prefix as a valid tag name, although it shouldn't
(i.e. it treated ``<?printe?>`` as ``<?print e?>``).

* Added new UL4 AST classes: :class:`~ll.ul4c.RenderOrPrintAST`,
:class:`~ll.ul4c.RenderOrPrintXAST`, :class:`~ll.ul4c.RenderXOrPrintAST` and
:class:`~ll.ul4c.RenderXOrPrintXAST`.


Changes in 5.69 (released 11/17/2021)
-------------------------------------
Expand Down
75 changes: 75 additions & 0 deletions docs/UL4_Tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,81 @@ This will output:
The ``<?renderx?>`` tag is implemented by :class:`ll.ul4c.RenderXAST`.


``<?render_or_print?>``
=======================

The ``render_or_print`` tag combines the functionality of the ``render`` and
the ``print`` tag, so for example

.. sourcecode:: ul4

<?render_or_print foo(bar)?>

is more or less equivalent to

.. sourcecode:: ul4

<?if istemplate(foo)?>
<?render foo(bar)?>
<?else?>
<?print foo?>
<?end if?>

i.e. if ``foo`` is renderable, it will be rendered, otherwise it will be
printed. Furthermore the arguments to the call will always be evaluated even
if ``foo`` isn't renderable, so for example:

.. sourcecode:: ul4

<?render_or_print 'foo'(None+None)?>

will fail with::

<?render_or_print 'foo'(None+None)?>
‴‴‴‴‴‴‴‴‴
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

.. hint::
The ``<?render_or_print?>`` tag is implemented by
:class:`ll.ul4c.RenderOrPrintAST`.


``<?render_or_printx?>``
========================

The ``render_or_printx`` tag is similar to ``render_or_print`` except that
the object will be output via ``<?printx?>`` instead of ``<?print?>`` if
it isn't renderable.

.. hint::
The ``<?render_or_printx?>`` tag is implemented by
:class:`ll.ul4c.RenderOrPrintXAST`.


``<?renderx_or_print?>``
========================

The ``renderx_or_print`` tag is similar to ``render_or_print`` except that
the object will be rendered via ``<?renderx?>`` instead of ``<?render?>`` if
it is renderable.

.. hint::
The ``<?renderx_or_print?>`` tag is implemented by
:class:`ll.ul4c.RenderXOrPrintAST`.


``<?renderx_or_printx?>``
=========================

The ``renderx_or_printx`` tag is similar to ``renderx_or_print`` except that
the object will be output via ``<?printx?>`` instead of ``<?print?>`` if
it isn't renderable.

.. hint::
The ``<?renderx_or_printx?>`` tag is implemented by
:class:`ll.ul4c.RenderXOrPrintXAST`.


``<?def?>``
===========

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class UL4Lexer(RegexLexer):
),
(
# The rest of the supported tags
r"(<\?)(\s*)(printx|print|for|if|elif|else|while|code|renderblocks?|render)\b",
r"(<\?)(\s*)(printx|print|for|if|elif|else|while|code|renderblocks?|renderx?|renderx?_or_printx?)\b",
bygroups(Comment.Preproc, Text.Whitespace, Keyword),
"ul4", # Switch to "expression" mode
),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@

args = dict(
name="ll-xist",
version="5.69.1",
version="5.70",
description="Extensible HTML/XML generator, cross-platform templating language, Oracle utilities and various other tools",
long_description=description,
author="Walter Doerwald",
Expand Down

0 comments on commit 9491e80

Please sign in to comment.