TG2 mako templates and preprocessor

20 views
Skip to first unread message

jj.galvez

unread,
Dec 16, 2009, 7:34:28 PM12/16/09
to TurboGears
hi I wasn't sure where to post this so I'm putting it here. I really
like Mako, however the <% syntax doesn't seem to play nicely with html
editors, or IDE's like eclipse, so I though I would apply a mako
preprocessor to change the mako syntax a little so essentually
replacing <%something with <mako:something . Its a very simple
preprocessor. Now to use the preprocoessor I had to subclass
AppConfig to override setup_mako_render to add the preprocessor to the
DottedTemplateLookup method. However to do that I either had to
subclass DottedTemplateLookup or change the default one. I opted to
change the default one because I think being able to supply mako with
a preprocessor is an important mako function that's currently not
supported well in tg2.
My changes to dottednamesupport.py are as follows (which do not seem
to change the default behavior)

I hope this or something like it makes it into the next version of tg2

*** dottednamesupport - old.py 2009-12-16 16:14:31.000000000 -0800
--- dottednamesupport.py 2009-12-16 16:34:08.000000000 -0800
***************
*** 36,42 ****
"""

def __init__(self, input_encoding, output_encoding,
! imports, default_filters):

self.input_encoding = input_encoding
self.output_encoding = output_encoding
--- 36,42 ----
"""

def __init__(self, input_encoding, output_encoding,
! imports, default_filters, preprocessor=None):

self.input_encoding = input_encoding
self.output_encoding = output_encoding
***************
*** 46,51 ****
--- 46,52 ----
self.template_cache = dict()
# implement a cache for the filename lookups
self.template_filenames_cache = dict()
+ self.preprocessor=preprocessor

# a mutex to ensure thread safeness during template loading
self._mutex = threading.Lock()
***************
*** 138,144 ****
output_encoding=self.output_encoding,
default_filters=self.default_filters,
imports=self.imports,
! lookup=self)

return self.template_cache[filename]

--- 139,146 ----
output_encoding=self.output_encoding,
default_filters=self.default_filters,
imports=self.imports,
! lookup=self,
! preprocessor=self.preprocessor)

return self.template_cache[filename]


Jose Galvez

unread,
Dec 20, 2009, 2:09:11 AM12/20/09
to turbo...@googlegroups.com
anyone considering adding these changes to make tg2 mako preprocessor
friendly?

> --
>
> You received this message because you are subscribed to the Google Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.
>
>
>
>

Christoph Zwerschke

unread,
Dec 20, 2009, 5:43:21 AM12/20/09
to turbo...@googlegroups.com
Jose, you should create a trac ticket for this.

Btw, why don't you use Genshi in the first place if you want to have
something that plays well with html editors and IDEs? If performance is
really an issue, I wouldn't use a preprocessor.

-- Christoph

Jose Galvez

unread,
Dec 21, 2009, 2:26:23 AM12/21/09
to turbo...@googlegroups.com
Thanks I'll create a ticket, as for Genshi, don't know I've not looked into it all that much, I just like Mako, but I'll take a look at Genshi and see how it compares
Jose

Christoph Zwerschke wrote:
--

You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbo...@googlegroups.com.
To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.



  
Reply all
Reply to author
Forward
0 new messages