New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to specify a mako preprocessor #183

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@epegzz

epegzz commented May 5, 2011

You can now create your own Renderer which uses the default Mako renderer combined with your own preprocessor.
For example you can create a Renderer that understands pyHAML syntax:

  import haml
  from pyramid import mako_templating

  class HamlRenderer(object):
      def __init__(self, info):
          setattr(info, 'preprocessor', haml.preprocessor)
          self.makoRenderer = mako_templating.renderer_factory(info)

      def __call__(self, value, system):
          return self.makoRenderer(value, system)

And then in YOURPROJECT/init.py you can tell pyramid to use your brand new Haml-Renderer for all mako templates:

    config.add_renderer(".mako", HamlRenderer)
Add possibility to specify a mako preprocessor
You can now create your own Renderer which uses the default Mako renderer combined with your own preprocessor.
For example you can create a Renderer that understands pyHAML syntax:

  import haml
  from pyramid import mako_templating

  class HamlRenderer(object):
      def __init__(self, info):
          setattr(info, 'preprocessor', haml.preprocessor)
          self.makoRenderer = mako_templating.renderer_factory(info)

      def __call__(self, value, system):
          return self.makoRenderer(value, system)

And then in YOURPROJECT/__init__.py you can tell pyramid to use your brand new Haml-Renderer for all mako templates:

    config.add_renderer(".mako", HamlRenderer)

@mcdonc mcdonc closed this in 8bd6cf2 Jun 26, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment