Discussion:
[Trac-dev] "html" class in trac.util.html
RjOllos
2016-01-06 23:58:32 UTC
Permalink
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
(2) http://trac.edgewall.org/browser/trunk/trac/util/html.py?rev=3832
--
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 trac-dev+***@googlegroups.com.
To post to this group, send email to trac-***@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.
RjOllos
2016-01-18 20:46:00 UTC
Permalink
Post by RjOllos
It looks like this could be used in place of genshi.core.tag.
Correction: that should be genshi.builder.tag
--
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 trac-dev+***@googlegroups.com.
To post to this group, send email to trac-***@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.
RjOllos
2016-03-03 15:02:12 UTC
Permalink
Post by RjOllos
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
(2) 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
--
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 trac-dev+***@googlegroups.com.
To post to this group, send email to trac-***@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.
Christian Boos
2016-03-03 21:50:30 UTC
Permalink
Post by RjOllos
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
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.
Post by RjOllos
from trac.util.html import tag
What is nice with that import is that it *already* works, even with Trac
Post by RjOllos
from trac import __version__
__version__
'0.12.8.dev0'
Post by RjOllos
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'>)
Post by RjOllos
tag('Hello', tag.b('World'))
<Fragment>
Post by RjOllos
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.
Post by RjOllos
from trac import __version__
__version__
'1.3.dev0'
Post by RjOllos
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'>)
Post by RjOllos
tag('Hello', tag.b('World'))
<trac.util.html.Fragment object at 0x00000000044939B0>
Post by RjOllos
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 trac-dev+***@googlegroups.com.
To post to this group, send email to trac-***@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.
Patrick Schaaf
2016-03-04 06:42:21 UTC
Permalink
Post by Christian Boos
from trac.util.html import tag, Markup, Fragment, Element
Maybe it even works for 0.11, but I no longer have a checkout.
Doesn't work for 0.11 (we are still running 0.11.7 and will do so for
a long time, internally).

Doesn't matter, though. I'm sure that if needed, I could easily patch
that in from 0.12

best regards
Patrick
--
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 trac-dev+***@googlegroups.com.
To post to this group, send email to trac-***@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.
Loading...