class PreprocessLoaderTestCase(unittest.TestCase):
    """ Test the ``PreprocessLoader``.
    """
    def setUp(self):
        from wheezy.template.loader import PreprocessLoader
        from wheezy.template.loader import DictLoader

        class Engine(object):
            def render(self, name, ctx, d1, d2):
                assert {'x': 1} == ctx
                return 'x'

        engine = Engine()
        engine.loader = DictLoader(templates={
            'tmpl1.html': 'x1',
            'shared/master.html': 'x2'
        })
        self.loader = PreprocessLoader(engine, {'x': 1})

    def test_list_names(self):
        """ Tests list_names.
        """
        assert ('shared/master.html', 'tmpl1.html') == self.loader.list_names()

    def test_load_existing(self):
        """ Tests load existing.
        """
        assert 'x' == self.loader.load('tmpl1.html')
 def setUp(self) -> None:
     templates = {"tmpl1.html": "x1", "shared/master.html": "x2"}
     engine = Engine(
         loader=DictLoader(templates=templates),
         extensions=[CoreExtension()],
     )
     self.loader = PreprocessLoader(engine, {"x": 1})
    def setUp(self):
        from wheezy.template.loader import PreprocessLoader
        from wheezy.template.loader import DictLoader

        class Engine(object):
            def render(self, name, ctx, d1, d2):
                assert {'x': 1} == ctx
                return 'x'

        engine = Engine()
        engine.loader = DictLoader(templates={
            'tmpl1.html': 'x1',
            'shared/master.html': 'x2'
        })
        self.loader = PreprocessLoader(engine, {'x': 1})
class PreprocessLoaderTestCase(unittest.TestCase):
    """Test the ``PreprocessLoader``."""
    def setUp(self) -> None:
        templates = {"tmpl1.html": "x1", "shared/master.html": "x2"}
        engine = Engine(
            loader=DictLoader(templates=templates),
            extensions=[CoreExtension()],
        )
        self.loader = PreprocessLoader(engine, {"x": 1})

    def test_list_names(self) -> None:
        """Tests list_names."""
        assert ("shared/master.html", "tmpl1.html") == self.loader.list_names()

    def test_load_existing(self) -> None:
        """Tests load existing."""
        assert "x1" == self.loader.load("tmpl1.html")
Exemple #5
0
def main(name):
    searchpath = [name]
    engine = Engine(loader=FileLoader(searchpath),
                    extensions=[CoreExtension(token_start='#')])
    engine = Engine(loader=PreprocessLoader(engine),
                    extensions=[CoreExtension()])
    engine.global_vars.update({'h': escape})

    template = engine.get_template('welcome.html')
    return template.render
Exemple #6
0
            403: 'http403',
            404: 'http404',
            500: 'http500',
        }),
    'http_errors_logger':
    unhandled_logger,
    'http_errors_extra_provider':
    error_report_extra_provider
})

# Template Engine
searchpath = ['content/templates']
engine = Engine(loader=FileLoader(searchpath),
                extensions=[CoreExtension(token_start='#')])
engine.global_vars.update({'__version__': __version__})
engine = Engine(loader=PreprocessLoader(engine),
                extensions=[
                    CoreExtension(),
                    WidgetExtension(),
                    WhitespaceExtension(),
                ])
engine.global_vars.update({'format_value': format_value, 'h': html_escape})
options.update({'render_template': WheezyTemplate(engine)})

# Security
options.update({
    'ticket':
    Ticket(max_age=config.getint('crypto', 'ticket-max-age'),
           salt=config.get('crypto', 'ticket-salt'),
           cypher=aes128,
           digestmod=ripemd160 or sha256 or sha1,