def get_source(self, environment, template):

        if "redraw:" in template:
            template, redraw_compo = template.split(" redraw:") # ugly dirty hack: 
                                                                # if we need to redraw a component, we simply
                                                                # pick the component-definition from the template-source
                                                                # and parse it was a normal template
                                                                # this works! better than other ugly hacks!
        else:
            redraw_compo = None

        source, filename, uptodate = SmartAssetSpecLoader.get_source(self, environment, template)

        if redraw_compo:
            source = self.crop_compo_definiton(source, redraw_compo)
            if not source:
                raise TemplateNotFound, "Redraw-template for component '" + redraw_compo + "' in template '" + template + "'"

#        text_dict = epfli18n.get_text_dict()
#        keys = sorted([(len(key), key) for key in text_dict.keys()], reverse=True) # sorts all keys of the translation-dict by length in reverse order
#
#        for sort, txt in keys:
#            trans_txt = text_dict[txt]
#            source = source.replace("$" + txt, trans_txt) # because its ordered by length, no partial/wrong replacement can occur!

        return (source, filename, uptodate)
Exemple #2
0
    def get_source(self, environment, template):

        if "redraw:" in template:
            template, redraw_compo = template.split(
                " redraw:")  # ugly dirty hack:
            # if we need to redraw a component, we simply
            # pick the component-definition from the template-source
            # and parse it was a normal template
            # this works! better than other ugly hacks!
        else:
            redraw_compo = None

        source, filename, uptodate = SmartAssetSpecLoader.get_source(
            self, environment, template)

        if redraw_compo:
            source = self.crop_compo_definiton(source, redraw_compo)
            if not source:
                raise TemplateNotFound, "Redraw-template for component '" + redraw_compo + "' in template '" + template + "'"


#        text_dict = epfli18n.get_text_dict()
#        keys = sorted([(len(key), key) for key in text_dict.keys()], reverse=True) # sorts all keys of the translation-dict by length in reverse order
#
#        for sort, txt in keys:
#            trans_txt = text_dict[txt]
#            source = source.replace("$" + txt, trans_txt) # because its ordered by length, no partial/wrong replacement can occur!

        return (source, filename, uptodate)
Exemple #3
0
    def test_get_source(self):
        from pyramid_jinja2 import SmartAssetSpecLoader
        from jinja2.exceptions import TemplateNotFound

        loader = SmartAssetSpecLoader()

        self.assertRaises(TemplateNotFound,
                          loader.get_source, None, 'asset:foobar.jinja2')
        asset = 'asset:pyramid_jinja2.tests:templates/helloworld.jinja2'
        self.assertNotEqual(loader.get_source(None, asset), None)

        # make sure new non-prefixed asset spec based loading works
        asset = 'pyramid_jinja2.tests:templates/helloworld.jinja2'
        self.assertNotEqual(loader.get_source(None, asset), None)

        # make sure new non-prefixed asset spec based loading works
        # without the leading package name
        asset = 'templates/helloworld.jinja2'
        env = Mock(_default_package='pyramid_jinja2.tests')
        self.assertNotEqual(loader.get_source(env, asset), None)
Exemple #4
0
    def test_get_source(self):
        from pyramid_jinja2 import SmartAssetSpecLoader
        from jinja2.exceptions import TemplateNotFound

        loader = SmartAssetSpecLoader()

        self.assertRaises(TemplateNotFound, loader.get_source, None,
                          'asset:foobar.jinja2')
        asset = 'asset:pyramid_jinja2.tests:templates/helloworld.jinja2'
        self.assertNotEqual(loader.get_source(None, asset), None)

        # make sure new non-prefixed asset spec based loading works
        asset = 'pyramid_jinja2.tests:templates/helloworld.jinja2'
        self.assertNotEqual(loader.get_source(None, asset), None)

        # make sure new non-prefixed asset spec based loading works
        # without the leading package name
        asset = 'templates/helloworld.jinja2'
        env = Mock(_default_package='pyramid_jinja2.tests')
        self.assertNotEqual(loader.get_source(env, asset), None)
Exemple #5
0
 def test_list_templates(self):
     from pyramid_jinja2 import SmartAssetSpecLoader
     loader = SmartAssetSpecLoader()
     self.assertRaises(TypeError, loader.list_templates)
Exemple #6
0
 def _makeOne(self, **kw):
     from pyramid_jinja2 import SmartAssetSpecLoader
     return SmartAssetSpecLoader(**kw)