On 3/3/2016 4:02 PM, RjOllos wrote:
>
>
> On Wednesday, January 6, 2016 at 3:58:33 PM UTC-8, RjOllos wrote:
>
> I recently noticed the html class in trac.util.html (1). The html
> class has been there since the initial merge of Genshi (2).
>
> It looks like this could be used in place of genshi.core.tag. That
> would provide a bit of insulation from the Genshi library,
> potentially making it a bit easier to port to a new templating library.
>
> I'm not going to make a big change to the codebase in the near
> future, but going forward, is it be better to use html() rather than
> tag() in Trac and plugins?
>
> (1)
> http://trac.edgewall.org/browser/tags/trac-1.0.9/trac/util/html.py?marks=291#L279
>
> <http://trac.edgewall.org/browser/tags/trac-1.0.9/trac/util/html.py?marks=291#L279>
> (2) http://trac.edgewall.org/browser/trunk/trac/util/html.py?rev=3832
> <http://trac.edgewall.org/browser/trunk/trac/util/html.py?rev=3832>
>
>
> I see the question has been addressed, and we will probably eventually
> start using html from trac.util.html for to make code more portable:
> https://trac.edgewall.org/wiki/TracDev/PortingFromGenshiToJinja#tag
>
Well, I kept the `html` symbol to be backward compatible, but I don't
really encourage people to use it. As everyone is already used to
writing `tag`, we could just continue that way. Also, that's one less
character to type ;-)
The only thing that will have to be changed is the import. Instead of
getting tag from genshi, you'll get it from trac.util.html.
>>> from trac.util.html import tag
What is nice with that import is that it *already* works, even with Trac
0.12:
>>> from trac import __version__
>>> __version__
'0.12.8.dev0'
>>> from trac.util.html import tag, Markup, Fragment, Element
>>> (tag, Markup, Fragment, Element)
(<genshi.builder.ElementFactory object at 0x0000000003FB5400>,
<type 'genshi._speedups.Markup'>,
<class 'genshi.builder.Fragment'>,
<class 'genshi.builder.Element'>)
>>> tag('Hello', tag.b('World'))
<Fragment>
>>> Markup(tag('Hello', tag.b('World')))
<Markup u'Hello<b>World</b>'>
Maybe it even works for 0.11, but I no longer have a checkout.
On the new jinja2 branch, only the types have changed, but the API
remains the same.
>>> from trac import __version__
>>> __version__
'1.3.dev0'
>>> from trac.util.html import tag, Markup, Fragment, Element
>>> (tag, Markup, Fragment, Element)
(<trac.util.html.ElementFactory object at 0x00000000043D9DD8>,
<class 'markupsafe.Markup'>,
<class 'trac.util.html.Fragment'>,
<class 'trac.util.html.Element'>)
>>> tag('Hello', tag.b('World'))
<trac.util.html.Fragment object at 0x00000000044939B0>
>>> Markup(tag('Hello', tag.b('World')))
Markup(u'Hello<b>World</b>')
(markupsafe is a dependency of Jinja2)
-- Christian
--
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.