Just read this thread and thought maybe our very simple tag generator in yafowil could be of interest - even if it does not meet the all the expectations you wrote about.

Its plays nice with json in data tags and also has a plugin point for a simple translation system (used currently with Zope and Pyramid message ids).

https://github.com/bluedynamics/yafowil/blob/master/src/yafowil/utils.py#L68

see also some basic testing in utils.rst

hth Jens

On 2013-06-28 23:04, Mike Orr wrote:
I'm thinking about rewriting the low-level HTML tag generator in
WebHelpers2, and wondering if there's an existing library that would be
worth using in this HTML 5/Python 2.6+ world. Something to reimplement
the low-level make_tag function:

     make_tag("a", "Click here", href="foo.html")  =>
     "<a href="foo.html">Click here.</a>"

The stdlib seems to only have ElementTree, which is overkill and not
that suited to making individual tags in isolation. The libraries on
PyPI seem to be very old, older than the WebHelpers implementation. So
I'm looking for something that's:

- In the stdlib, or small and with no esoteric dependencies.
- Fast.
- Without ancient HTML 4/3 clutter.
- Compatible with MarkupSafe and the ''.__html__()`` protocol.

Other desirable features:

- Knows about HTML 5's empty tags, boolean attributes, data attributes, etc.
- Can set characteristics at the class level, and is subclassable.
- Has a Tag class or equivalent for lazy stringification. This would
allow you to build up the attributes piecemeal, pass the tag to a
template, and it would stringify itself when str() or .__html__() is
called.  Possibly caching the string.

Is there a library that does this or should I write it myself?

I'd also like feedback on another idea. I'm thinking about adding
arguments to build up the class attribute and style attribute piecemeal:

     make_tag(..., classes=["foo", "bar"])  => ' ... class="foo bar"'

     make_tag(..., styles=["margin:0", "padding: 1ex"]) => '...
style="margin:0; padding: 1ex")

Would this be useful to others? Would the names collide with any other
potential attributes? (I don't think so since HTML doesn't define
"styles" and "classes", and is unlikely to because of user confusion.)
Is there a better API? Are there any other attributes where this would
be useful on?

Are there any other syntactic sugar patterns that would be helpful in a
Javascript-rich or HTML 5 application?

--
Mike Orr <sluggos...@gmail.com
<mailto:sluggos...@gmail.com>>

--
You received this message because you are subscribed to the Google
Groups "pylons-devel" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to
pylons-devel+unsubscr...@googlegroups.com.
To post to this group, send email to
pylons-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-devel.
For more options, visit https://groups.google.com/groups/opt_out.




--
Klein & Partner KG, member of BlueDynamics Alliance

--
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to pylons-devel+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-devel.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to