mercurial/templater.py
changeset 37102 638a241202a3
parent 37084 f0b6fbea00cf
child 37157 888507ec655e
equal deleted inserted replaced
37101:656ac240f392 37102:638a241202a3
   575 
   575 
   576     @abc.abstractmethod
   576     @abc.abstractmethod
   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()
   583 
   588 
   584     def knownkeys(self):
   589     def knownkeys(self):
   585         return set()
   590         return set()
   586 
   591 
   587     def lookup(self, context, mapping, key):
   592     def lookup(self, context, mapping, key):
   588         return None
   593         return None
       
   594 
       
   595     def populatemap(self, context, origmapping, newmapping):
       
   596         return {}
   589 
   597 
   590 class engine(object):
   598 class engine(object):
   591     '''template expansion engine.
   599     '''template expansion engine.
   592 
   600 
   593     template expansion works like this. a map file contains key=value
   601     template expansion works like this. a map file contains key=value
   632         newres = self._resources.availablekeys(self, newmapping)
   640         newres = self._resources.availablekeys(self, newmapping)
   633         mapping = {k: v for k, v in origmapping.iteritems()
   641         mapping = {k: v for k, v in origmapping.iteritems()
   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):
   640         """Resource keys required by the specified default symbol function"""
   650         """Resource keys required by the specified default symbol function"""
   641         v = self._defaults.get(key)
   651         v = self._defaults.get(key)
   687     def process(self, t, mapping):
   697     def process(self, t, mapping):
   688         '''Perform expansion. t is name of map element to expand.
   698         '''Perform expansion. t is name of map element to expand.
   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}
   695 
   712 
   696 def stylelist():
   713 def stylelist():