Ejemplo n.º 1
0
 def _parse(self, filename, contents):
     # parse the template for asset nodes
     try:
         t = template.Template(contents)
     except template.TemplateSyntaxError as e:
         raise LoaderError('Django parser failed: %s' % e)
     else:
         result = []
         def _recurse_node(node):
             # depending on whether the template tag is added to
             # builtins, or loaded via {% load %}, it will be
             # available in a different module
             if node is not None and \
                isinstance(node, AssetsNodeClasses):
                 # try to resolve this node's data; if we fail,
                 # then it depends on view data and we cannot
                 # manually rebuild it.
                 try:
                     bundle = node.resolve()
                 except template.VariableDoesNotExist:
                     raise LoaderError('skipping bundle %s, depends on runtime data' % node.output)
                 else:
                     result.append(bundle)
             # see Django #7430
             for subnode in hasattr(node, 'nodelist') \
                 and node.nodelist\
                 or []:
                     _recurse_node(subnode)
         for node in t:  # don't move into _recurse_node, ``Template`` has a .nodelist attribute
             _recurse_node(node)
         return result
Ejemplo n.º 2
0
    def _parse(self, filename, contents):
        for i, env in enumerate(self.jinja2_envs):
            try:
                t = env.parse(contents.decode(self.charset))
            except jinja2.exceptions.TemplateSyntaxError as e:
                #print ('jinja parser (env %d) failed: %s'% (i, e))
                pass
            else:
                result = []

                def _recurse_node(node_to_search):
                    for node in node_to_search.iter_child_nodes():
                        if isinstance(node, jinja2.nodes.Call):
                            if isinstance(node.node, jinja2.nodes.ExtensionAttribute)\
                               and node.node.identifier == AssetsExtension.identifier:
                                filter, output, dbg, depends, files = node.args
                                bundle = Bundle(
                                    *AssetsExtension.resolve_contents(
                                        files.as_const(), self.asset_env), **{
                                            'output': output.as_const(),
                                            'depends': depends.as_const(),
                                            'filters': filter.as_const()
                                        })
                                result.append(bundle)
                        else:
                            _recurse_node(node)

                for node in t.iter_child_nodes():
                    _recurse_node(node)
                return result
        else:
            raise LoaderError(
                'Jinja parser failed on %s, tried %d environments' %
                (filename, len(self.jinja2_envs)))
        return False
Ejemplo n.º 3
0
 def _recurse_node(node):
     # depending on whether the template tag is added to
     # builtins, or loaded via {% load %}, it will be
     # available in a different module
     if node is not None and \
        isinstance(node, AssetsNodeClasses):
         # try to resolve this node's data; if we fail,
         # then it depends on view data and we cannot
         # manually rebuild it.
         try:
             bundle = node.resolve()
         except template.VariableDoesNotExist:
             raise LoaderError('skipping bundle %s, depends on runtime data' % node.output)
         else:
             result.append(bundle)
     # see Django #7430
     for subnode in hasattr(node, 'nodelist') \
         and node.nodelist\
         or []:
             _recurse_node(subnode)
Ejemplo n.º 4
0
        for i, env in enumerate(self.jinja2_envs):
            try:
                t = env.parse(contents.decode(self.charset))
            except jinja2.exceptions.TemplateSyntaxError, e:
                #print ('jinja parser (env %d) failed: %s'% (i, e))
                pass
            else:
                result = []
                def _recurse_node(node_to_search):
                    for node in node_to_search.iter_child_nodes():
                        if isinstance(node, jinja2.nodes.Call):
                            if isinstance(node.node, jinja2.nodes.ExtensionAttribute)\
                               and node.node.identifier == AssetsExtension.identifier:
                                filter, output, dbg, depends, files = node.args
                                bundle = Bundle(
                                    *AssetsExtension.resolve_contents(files.as_const(), self.asset_env),
                                    **{
                                        'output': output.as_const(),
                                        'depends': depends.as_const(),
                                        'filters': filter.as_const()})
                                result.append(bundle)
                        else:
                            _recurse_node(node)
                for node in t.iter_child_nodes():
                    _recurse_node(node)
                return result
        else:
            raise LoaderError('Jinja parser failed on %s, tried %d environments' % (
                filename, len(self.jinja2_envs)))
        return False
Ejemplo n.º 5
0
 def _parse(self, filename, contents):
     # parse the template for asset nodes
     try:
         t = template.Template(contents)
     except template.TemplateSyntaxError, e:
         raise LoaderError('Django parser failed: %s' % e)