##// END OF EJS Templates
templater: move stylemap() to hgweb_mod, since that's its only user...
Martin von Zweigbergk -
r45867:ba50c8a9 default
parent child Browse files
Show More
@@ -53,7 +53,41 b' def getstyle(req, configfn, templatepath'
53 configfn(b'web', b'style'),
53 configfn(b'web', b'style'),
54 b'paper',
54 b'paper',
55 )
55 )
56 return styles, templater.stylemap(styles, templatepath)
56 return styles, _stylemap(styles, templatepath)
57
58
59 def _stylemap(styles, path=None):
60 """Return path to mapfile for a given style.
61
62 Searches mapfile in the following locations:
63 1. templatepath/style/map
64 2. templatepath/map-style
65 3. templatepath/map
66 """
67
68 if path is None:
69 path = templater.templatedir()
70
71 if path is not None:
72 for style in styles:
73 # only plain name is allowed to honor template paths
74 if (
75 not style
76 or style in (pycompat.oscurdir, pycompat.ospardir)
77 or pycompat.ossep in style
78 or pycompat.osaltsep
79 and pycompat.osaltsep in style
80 ):
81 continue
82 locations = [os.path.join(style, b'map'), b'map-' + style]
83 locations.append(b'map')
84
85 for location in locations:
86 mapfile = os.path.join(path, location)
87 if os.path.isfile(mapfile):
88 return style, mapfile
89
90 raise RuntimeError(b"No hgweb templates found in %r" % path)
57
91
58
92
59 def makebreadcrumb(url, prefix=b''):
93 def makebreadcrumb(url, prefix=b''):
@@ -1075,37 +1075,3 b' def templatepath(name):'
1075 if f and os.path.isfile(f):
1075 if f and os.path.isfile(f):
1076 return f
1076 return f
1077 return None
1077 return None
1078
1079
1080 def stylemap(styles, path=None):
1081 """Return path to mapfile for a given style.
1082
1083 Searches mapfile in the following locations:
1084 1. templatepath/style/map
1085 2. templatepath/map-style
1086 3. templatepath/map
1087 """
1088
1089 if path is None:
1090 path = templatedir()
1091
1092 if path is not None:
1093 for style in styles:
1094 # only plain name is allowed to honor template paths
1095 if (
1096 not style
1097 or style in (pycompat.oscurdir, pycompat.ospardir)
1098 or pycompat.ossep in style
1099 or pycompat.osaltsep
1100 and pycompat.osaltsep in style
1101 ):
1102 continue
1103 locations = [os.path.join(style, b'map'), b'map-' + style]
1104 locations.append(b'map')
1105
1106 for location in locations:
1107 mapfile = os.path.join(path, location)
1108 if os.path.isfile(mapfile):
1109 return style, mapfile
1110
1111 raise RuntimeError(b"No hgweb templates found in %r" % path)
General Comments 0
You need to be logged in to leave comments. Login now