Show More
@@ -517,6 +517,9 class templateresources(templater.resour | |||||
517 | return None |
|
517 | return None | |
518 | return get(self, context, mapping, key) |
|
518 | return get(self, context, mapping, key) | |
519 |
|
519 | |||
|
520 | def populatemap(self, context, origmapping, newmapping): | |||
|
521 | return {} | |||
|
522 | ||||
520 | def _getsome(self, context, mapping, key): |
|
523 | def _getsome(self, context, mapping, key): | |
521 | v = mapping.get(key) |
|
524 | v = mapping.get(key) | |
522 | if v is not None: |
|
525 | if v is not None: |
@@ -577,6 +577,11 class resourcemapper(object): | |||||
577 | def lookup(self, context, mapping, key): |
|
577 | def lookup(self, context, mapping, key): | |
578 | """Return a resource for the key if available; otherwise None""" |
|
578 | """Return a resource for the key if available; otherwise None""" | |
579 |
|
579 | |||
|
580 | @abc.abstractmethod | |||
|
581 | def populatemap(self, context, origmapping, newmapping): | |||
|
582 | """Return a dict of additional mapping items which should be paired | |||
|
583 | with the given new mapping""" | |||
|
584 | ||||
580 | class nullresourcemapper(resourcemapper): |
|
585 | class nullresourcemapper(resourcemapper): | |
581 | def availablekeys(self, context, mapping): |
|
586 | def availablekeys(self, context, mapping): | |
582 | return set() |
|
587 | return set() | |
@@ -587,6 +592,9 class nullresourcemapper(resourcemapper) | |||||
587 | def lookup(self, context, mapping, key): |
|
592 | def lookup(self, context, mapping, key): | |
588 | return None |
|
593 | return None | |
589 |
|
594 | |||
|
595 | def populatemap(self, context, origmapping, newmapping): | |||
|
596 | return {} | |||
|
597 | ||||
590 | class engine(object): |
|
598 | class engine(object): | |
591 | '''template expansion engine. |
|
599 | '''template expansion engine. | |
592 |
|
600 | |||
@@ -634,6 +642,8 class engine(object): | |||||
634 | if (k in knownres # not a symbol per self.symbol() |
|
642 | if (k in knownres # not a symbol per self.symbol() | |
635 | or newres.isdisjoint(self._defaultrequires(k)))} |
|
643 | or newres.isdisjoint(self._defaultrequires(k)))} | |
636 | mapping.update(newmapping) |
|
644 | mapping.update(newmapping) | |
|
645 | mapping.update( | |||
|
646 | self._resources.populatemap(self, origmapping, newmapping)) | |||
637 | return mapping |
|
647 | return mapping | |
638 |
|
648 | |||
639 | def _defaultrequires(self, key): |
|
649 | def _defaultrequires(self, key): | |
@@ -689,6 +699,13 class engine(object): | |||||
689 | mapping contains added elements for use during expansion. Is a |
|
699 | mapping contains added elements for use during expansion. Is a | |
690 | generator.''' |
|
700 | generator.''' | |
691 | func, data = self._load(t) |
|
701 | func, data = self._load(t) | |
|
702 | # populate additional items only if they don't exist in the given | |||
|
703 | # mapping. this is slightly different from overlaymap() because the | |||
|
704 | # initial 'revcache' may contain pre-computed items. | |||
|
705 | extramapping = self._resources.populatemap(self, {}, mapping) | |||
|
706 | if extramapping: | |||
|
707 | extramapping.update(mapping) | |||
|
708 | mapping = extramapping | |||
692 | return _flatten(func(self, mapping, data)) |
|
709 | return _flatten(func(self, mapping, data)) | |
693 |
|
710 | |||
694 | engines = {'default': engine} |
|
711 | engines = {'default': engine} |
General Comments 0
You need to be logged in to leave comments.
Login now