Hello list,

I'm currently trying to embed/include Jade code inside a Mako
template,via the pyjade module. My currently working solution is a bunch
of ugly hacks, so I'm wondering if there would be a cleaner way.

==

As per pyjade's documentation, I could define a .jade renderer inside
Pyramid and never use Mako directly:

  config.add_renrerer('.jade', PyjadeRenderer)

Pyjade define constructs which are translated as Mako tags (e.g.:
"extends" for <%inherit>,"mixin" for <%def>, etc.) But this solution is
not satisfactory, as all dependent rendering (e.g. the rendering of the
<%def> blocks defined in other Mako templates) is done
by Jade, and results in a syntax error.

==

A similar problem occurs if I use the render() function inside a view:


from pyramid.renderers import render

@view_config(route_name='...', renderer="page.mako")
def myView(request):

  fragment = render('fragment.jade', {}, request=request)
  return dict(fragment=fragment)


The original request object is modifier by the render() call, and tries
to render page.mako via pyjade's renderer...

==

In understand I could try to pass a clone of the original request, e.g.:

  fragment = render('fragment.jade', {}, request=request.copy())

Unfortunately request.copy() doesn't seem to include the required
information and Jade rendering fails again...

==

So, for the time being, I'm stuck at a lower level, i.e.:


from pyramid.path    import AssetResolver
from mako.template   import Template
from pyjade.ext.mako import preprocessor as mako_preprocessor

ar = AssetResolver('myPackage')

@view_config( route_name='...', renderer='page.mako' )
def myView(request):

    asset ="myPackage:templates/fragment.jade"
    tp = Template( filename=ar.resolve(asset).abspath(),
                   input_encoding='utf-8',
                   preprocessor=mako_preprocessor
                   )
    fragment = tp.render(request = request, _ = request.translate)
    return dict(fragment=fragment)


As I said, a bunch of ugly hacks... :-(


As usual, any suggestions welcome!

Many thanks,

Laurent.

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


Reply via email to