Show More
@@ -517,6 +517,9 b' class templateresources(templater.resour' | |||
|
517 | 517 | return None |
|
518 | 518 | return get(self, context, mapping, key) |
|
519 | 519 | |
|
520 | def populatemap(self, context, origmapping, newmapping): | |
|
521 | return {} | |
|
522 | ||
|
520 | 523 | def _getsome(self, context, mapping, key): |
|
521 | 524 | v = mapping.get(key) |
|
522 | 525 | if v is not None: |
@@ -577,6 +577,11 b' class resourcemapper(object):' | |||
|
577 | 577 | def lookup(self, context, mapping, key): |
|
578 | 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 | 585 | class nullresourcemapper(resourcemapper): |
|
581 | 586 | def availablekeys(self, context, mapping): |
|
582 | 587 | return set() |
@@ -587,6 +592,9 b' class nullresourcemapper(resourcemapper)' | |||
|
587 | 592 | def lookup(self, context, mapping, key): |
|
588 | 593 | return None |
|
589 | 594 | |
|
595 | def populatemap(self, context, origmapping, newmapping): | |
|
596 | return {} | |
|
597 | ||
|
590 | 598 | class engine(object): |
|
591 | 599 | '''template expansion engine. |
|
592 | 600 | |
@@ -634,6 +642,8 b' class engine(object):' | |||
|
634 | 642 | if (k in knownres # not a symbol per self.symbol() |
|
635 | 643 | or newres.isdisjoint(self._defaultrequires(k)))} |
|
636 | 644 | mapping.update(newmapping) |
|
645 | mapping.update( | |
|
646 | self._resources.populatemap(self, origmapping, newmapping)) | |
|
637 | 647 | return mapping |
|
638 | 648 | |
|
639 | 649 | def _defaultrequires(self, key): |
@@ -689,6 +699,13 b' class engine(object):' | |||
|
689 | 699 | mapping contains added elements for use during expansion. Is a |
|
690 | 700 | generator.''' |
|
691 | 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 | 709 | return _flatten(func(self, mapping, data)) |
|
693 | 710 | |
|
694 | 711 | engines = {'default': engine} |
General Comments 0
You need to be logged in to leave comments.
Login now