ANN: Yats 0.1 
Author Message
 ANN: Yats 0.1

Yats is Yet Another Template System primarily for use to output dynamic
HTML documents.

http://www.*-*-*.com/

It is designed to allow separation of logic from presentation and was
written to be
used with modpython's modpublisher module (www.modpython.org) though should
work fine with cgi scripts.

It is derived heavily from HTMLgen's TemplateDocuments and has similar
usage.
It supports:
    - Simple substitutions
    - Conditional Extraction/Inserts
    - Loops

Usage:
The user designs their web document in their favourite web design
tool and embeds tags,  "{ tags}" within the document to be substituted.
Loops and Conditional Inserts are flagged by simple comment tags
"<!--{tag}-->" that designate blocks to be iterated over or removed
depending on the python logic. Tags are removed from the output page
if there is no data to be substituted, but Conditional Inserts will be left
unless extracted.

Thats basically it..
regards,

Brett Haydon



Wed, 05 Nov 2003 18:27:29 GMT  
 ANN: Yats 0.1
There is a list of (mostly) Python template systems at:

    http://webware.sourceforge.net/Papers/Templates/

Both YATS and DTML (from Zope) should be added to that list.

Python certainly is rich in this area.  Does anyone have any
comments on how these different systems solve slightly different
problems or are better and worse for slightly different tasks?

  - Dave

Quote:

> Yats is Yet Another Template System primarily for use to output dynamic
> HTML documents.

> http://www.users.bigpond.com/bbhaydon/yats.html

[snip]

Quote:

> Brett Haydon


--
Dave Kuhlman



Fri, 07 Nov 2003 02:48:38 GMT  
 ANN: Yats 0.1

Quote:
> There is a list of (mostly) Python template systems at:

>     http://webware.sourceforge.net/Papers/Templates/

> Both YATS and DTML (from Zope) should be added to that list.

...and maybe yaptu (says he hopefully), see:
http://aspn.activestate.com/ASPN/Python/Cookbook/Recipe/52305

Quote:
> Python certainly is rich in this area.  Does anyone have any
> comments on how these different systems solve slightly different
> problems or are better and worse for slightly different tasks?

YAPTU serves the purpose of offering a general text-templating
(aka text-embedded Python) in a few dozen lines...:-).  [OK, so it
IS _slightly_ kludgey, but, hey, it IS general and tiny...:-)].

Alex



Fri, 07 Nov 2003 06:05:50 GMT  
 ANN: Yats 0.1

Quote:

> YAPTU serves the purpose of offering a general text-templating
> (aka text-embedded Python) in a few dozen lines...:-).  [OK, so it
> IS _slightly_ kludgey, but, hey, it IS general and tiny...:-)].

Hmm, if I'd seen yours I probably wouldn't have bothered to post
mine up.. but actually they do seem a bit different.

I looked at evaluating expressions and executing arbitrary code,
but outside of the local namespace ie in the calling scripts globals().
So a tag {!sometag="Something") would return a string (or not) from
function sometag("Something") in the globals() of the script that is
using yats.

The idea being that some tags in a given page are likely to be repeated
in every page and it seems silly to have to specifically code for them
each time..

But, for that to happen I need to pass gobals() each time I instantiate
a TemplateDocument class ie page=TemplateDocument("somedoc.html',globals())

Does anyone know a way that a class can receive the calling functions
globals() or locals() without it being explicitly passed in each instance.

Or maybe there's another way of looking at it

Cheers,

Brett Haydon



Fri, 07 Nov 2003 12:10:16 GMT  
 ANN: Yats 0.1


Quote:
> > YAPTU serves the purpose of offering a general text-templating
> > (aka text-embedded Python) in a few dozen lines...:-).  [OK, so it
> > IS _slightly_ kludgey, but, hey, it IS general and tiny...:-)].

> Hmm, if I'd seen yours I probably wouldn't have bothered to post
> mine up.. but actually they do seem a bit different.

Good thing you *didn't* see Yaptu earlier, then, because "the more
the better":-).  Yep, there ARE differences!  YATS and YAPTU both
have worth, and studying and comparing/contrasting them might be
an interesting exercise, if nothing else:-).

Quote:
> I looked at evaluating expressions and executing arbitrary code,
> but outside of the local namespace ie in the calling scripts globals().
> So a tag {!sometag="Something") would return a string (or not) from
> function sometag("Something") in the globals() of the script that is
> using yats.

> The idea being that some tags in a given page are likely to be repeated
> in every page and it seems silly to have to specifically code for them
> each time..

> But, for that to happen I need to pass gobals() each time I instantiate
> a TemplateDocument class ie

page=TemplateDocument("somedoc.html',globals())

Exactly.  This is the tack I took in YAPTU -- minimize black magick,
let the caller EXPLICITLY pass the dictionaries in which the execution
and evaluation of Python code "embedded in text" is to occur.

Quote:
> Does anyone know a way that a class can receive the calling functions
> globals() or locals() without it being explicitly passed in each instance.

Yep -- as far as black-magic goes, these are fairly well-known spells:-).
To the point that, in Python 2.1, a built-in function that helps with this
even made it all the way to the sys module, albeit suitably hedged with
leading-underscore name and warnings...:
"""
_getframe([depth])
Return a frame object from the call stack. If optional integer depth
is given, return the frame object that many calls below the top of the
stack. If that is deeper than the call stack, ValueError is raised. The
default for depth is zero, returning the frame at the top of the call
stack.
This function should be used for internal and specialized purposes only.
"""

You can get a similar effect in earlier Python versions by raising and
catching an exception and walking the resulting traceback yourself:

def caller_frame():
    try: raise "boo"
    except: return sys.exc_traceback.tb_frame.f_back.f_back

In either case, you end up with a stackframe object, which among its
attributes has f_globals and f_locals.  If you treat those as read-only,
I think the magic involved can fairly be described as "darkish-gray"
rather than black -- it wouldn't be TOO terrible to use it in production
code, although the need for such use should IMHO be carefully vetted.

Anyway, a usage example might be:

Quote:
>>> import sys
>>> def f(a, b=23):

...     c=45
...     g()
...
Quote:
>>> def g():

...     x=sys._getframe(1)
...     print x.f_locals
...
Quote:
>>> f(99)

{'b': 23, 'c': 45, 'a': 99}

or, similarly,

Quote:
>>> def g():

...     x=caller_frame()
...     print x.f_locals

Et voila -- you have (read-only, pls:-) access to the locals of
the function calling you.  globals work similarly, of course.

Quote:
> Or maybe there's another way of looking at it

"Explicit is better than implicit" and "don't do black magick
behind my back please" might be these "other ways":-).  Python
gives you A LOT of access to the kind of things that most other
languages keep carefully hidden behind smoke and mirrors, and
this empowers you, as a designer and programmer, to decide how
"normal" or "magical" you want your libraries/modules/programs
to be.  However, my personal opinion, for what it's worth, is
that such tools are mostly to be used in developing frameworks
and tools for debugging, experimentation, etc -- production code
being (again IMHO) cleaner and more readable and maintainable
if tricks are systematically eschewed in favour of simplicity,
explicitness, straightforwardhood (yep, I know the latter is not
a word:-).  It's *SO* much fun to play with the black-magic
(introspection/reflection/metaprogramming) possibilities, that
being carried away with it is a risk -- it's exactly to counter
this risk (in myself first of all:-) that I keep harping on it:-).

Alex



Fri, 07 Nov 2003 16:15:53 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. ANN: Minotaur 0.1 - bridging Tcl, Python, and Perl

2. ANN: Qish 0.1 - a copying generational GC for C

3. ANN: Minotaur 0.1 - bridging Tcl, Python, and Perl

4. ANN: pyUnRAR 0.1

5. ANN: matplotlib 0.1

6. ANN: Capon 0.1 - a software build framework

7. ANN: Pyacc 0.1 -- Python Yacc Parser

8. ANN: PyTables 0.1 released

9. ANN: PySQLite 0.1 released

10. ANN: Madeleine 0.1

11. ANN: vcard 0.1 - a vCard decoding library

12. ANN: pcre 0.1

 

 
Powered by phpBB® Forum Software