##// END OF EJS Templates
templater: introduce templatepaths for getting paths searched for templates...
Mads Kiilerich -
r22634:e48a5d39 default
parent child Browse files
Show More
@@ -2256,7 +2256,7 b' def debuginstall(ui):'
2256
2256
2257 # templates
2257 # templates
2258 import templater
2258 import templater
2259 p = templater.templatepath()
2259 p = templater.templatepaths()
2260 ui.status(_("checking templates (%s)...\n") % ' '.join(p))
2260 ui.status(_("checking templates (%s)...\n") % ' '.join(p))
2261 if p:
2261 if p:
2262 m = templater.templatepath("map-cmdline.default")
2262 m = templater.templatepath("map-cmdline.default")
@@ -193,7 +193,7 b' class hgwebdir(object):'
193 static = self.ui.config("web", "static", None,
193 static = self.ui.config("web", "static", None,
194 untrusted=False)
194 untrusted=False)
195 if not static:
195 if not static:
196 tp = self.templatepath or templater.templatepath()
196 tp = self.templatepath or templater.templatepaths()
197 if isinstance(tp, str):
197 if isinstance(tp, str):
198 tp = [tp]
198 tp = [tp]
199 static = [os.path.join(p, 'static') for p in tp]
199 static = [os.path.join(p, 'static') for p in tp]
@@ -933,7 +933,7 b' def static(web, req, tmpl):'
933 # readable by the user running the CGI script
933 # readable by the user running the CGI script
934 static = web.config("web", "static", None, untrusted=False)
934 static = web.config("web", "static", None, untrusted=False)
935 if not static:
935 if not static:
936 tp = web.templatepath or templater.templatepath()
936 tp = web.templatepath or templater.templatepaths()
937 if isinstance(tp, str):
937 if isinstance(tp, str):
938 tp = [tp]
938 tp = [tp]
939 static = [os.path.join(p, 'static') for p in tp]
939 static = [os.path.join(p, 'static') for p in tp]
@@ -625,7 +625,7 b' class engine(object):'
625 engines = {'default': engine}
625 engines = {'default': engine}
626
626
627 def stylelist():
627 def stylelist():
628 paths = templatepath()
628 paths = templatepaths()
629 if not paths:
629 if not paths:
630 return _('no templates found, try `hg debuginstall` for more info')
630 return _('no templates found, try `hg debuginstall` for more info')
631 dirlist = os.listdir(paths[0])
631 dirlist = os.listdir(paths[0])
@@ -710,25 +710,26 b' class templater(object):'
710 max=self.maxchunk)
710 max=self.maxchunk)
711 return stream
711 return stream
712
712
713 def templatepath(name=None):
713 def templatepaths():
714 '''return location of template file or directory (if no name).
714 '''return locations used for template files.'''
715 returns None if not found.'''
716 normpaths = []
715 normpaths = []
717
718 for f in path:
716 for f in path:
719 if f.startswith('/'):
717 if f.startswith('/'):
720 p = f
718 p = f
721 else:
719 else:
722 fl = f.split('/')
720 fl = f.split('/')
723 p = os.path.join(util.datapath, *fl)
721 p = os.path.join(util.datapath, *fl)
724 if name:
722 if os.path.isdir(p):
725 p = os.path.join(p, name)
726 if name and os.path.exists(p):
727 return os.path.normpath(p)
728 elif os.path.isdir(p):
729 normpaths.append(os.path.normpath(p))
723 normpaths.append(os.path.normpath(p))
724 return normpaths
730
725
731 return normpaths
726 def templatepath(name):
727 '''return location of template file. returns None if not found.'''
728 for p in templatepaths():
729 f = os.path.join(p, name)
730 if os.path.exists(f):
731 return f
732 return None
732
733
733 def stylemap(styles, paths=None):
734 def stylemap(styles, paths=None):
734 """Return path to mapfile for a given style.
735 """Return path to mapfile for a given style.
@@ -740,7 +741,7 b' def stylemap(styles, paths=None):'
740 """
741 """
741
742
742 if paths is None:
743 if paths is None:
743 paths = templatepath()
744 paths = templatepaths()
744 elif isinstance(paths, str):
745 elif isinstance(paths, str):
745 paths = [paths]
746 paths = [paths]
746
747
General Comments 0
You need to be logged in to leave comments. Login now