##// END OF EJS Templates
formatter: move most of template option helper to formatter...
Matt Mackall -
r25511:c2a4dfe2 default
parent child Browse files
Show More
@@ -14,6 +14,7 b' import context, repair, graphmod, revset'
14 import changelog
14 import changelog
15 import bookmarks
15 import bookmarks
16 import encoding
16 import encoding
17 import formatter
17 import crecord as crecordmod
18 import crecord as crecordmod
18 import lock as lockmod
19 import lock as lockmod
19
20
@@ -1493,40 +1494,7 b' def gettemplate(ui, tmpl, style):'
1493 if not tmpl:
1494 if not tmpl:
1494 return None, None
1495 return None, None
1495
1496
1496 # looks like a literal template?
1497 return formatter.lookuptemplate(ui, 'changeset', tmpl)
1497 if '{' in tmpl:
1498 return tmpl, None
1499
1500 # perhaps a stock style?
1501 if not os.path.split(tmpl)[0]:
1502 mapname = (templater.templatepath('map-cmdline.' + tmpl)
1503 or templater.templatepath(tmpl))
1504 if mapname and os.path.isfile(mapname):
1505 return None, mapname
1506
1507 # perhaps it's a reference to [templates]
1508 t = ui.config('templates', tmpl)
1509 if t:
1510 try:
1511 tmpl = templater.unquotestring(t)
1512 except SyntaxError:
1513 tmpl = t
1514 return tmpl, None
1515
1516 if tmpl == 'list':
1517 ui.write(_("available styles: %s\n") % templater.stylelist())
1518 raise util.Abort(_("specify a template"))
1519
1520 # perhaps it's a path to a map or a template
1521 if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl):
1522 # is it a mapfile for a style?
1523 if os.path.basename(tmpl).startswith("map-"):
1524 return None, os.path.realpath(tmpl)
1525 tmpl = open(tmpl).read()
1526 return tmpl, None
1527
1528 # constant string?
1529 return tmpl, None
1530
1498
1531 def show_changeset(ui, repo, opts, buffered=False):
1499 def show_changeset(ui, repo, opts, buffered=False):
1532 """show one changeset using template or regular display.
1500 """show one changeset using template or regular display.
@@ -9,6 +9,8 b' import cPickle'
9 from node import hex, short
9 from node import hex, short
10 from i18n import _
10 from i18n import _
11 import encoding, util
11 import encoding, util
12 import templater
13 import os
12
14
13 class baseformatter(object):
15 class baseformatter(object):
14 def __init__(self, ui, topic, opts):
16 def __init__(self, ui, topic, opts):
@@ -133,6 +135,42 b' class jsonformatter(baseformatter):'
133 baseformatter.end(self)
135 baseformatter.end(self)
134 self._ui.write("\n]\n")
136 self._ui.write("\n]\n")
135
137
138 def lookuptemplate(ui, topic, tmpl):
139 # looks like a literal template?
140 if '{' in tmpl:
141 return tmpl, None
142
143 # perhaps a stock style?
144 if not os.path.split(tmpl)[0]:
145 mapname = (templater.templatepath('map-cmdline.' + tmpl)
146 or templater.templatepath(tmpl))
147 if mapname and os.path.isfile(mapname):
148 return None, mapname
149
150 # perhaps it's a reference to [templates]
151 t = ui.config('templates', tmpl)
152 if t:
153 try:
154 tmpl = templater.unquotestring(t)
155 except SyntaxError:
156 tmpl = t
157 return tmpl, None
158
159 if tmpl == 'list':
160 ui.write(_("available styles: %s\n") % templater.stylelist())
161 raise util.Abort(_("specify a template"))
162
163 # perhaps it's a path to a map or a template
164 if ('/' in tmpl or '\\' in tmpl) and os.path.isfile(tmpl):
165 # is it a mapfile for a style?
166 if os.path.basename(tmpl).startswith("map-"):
167 return None, os.path.realpath(tmpl)
168 tmpl = open(tmpl).read()
169 return tmpl, None
170
171 # constant string?
172 return tmpl, None
173
136 def formatter(ui, topic, opts):
174 def formatter(ui, topic, opts):
137 template = opts.get("template", "")
175 template = opts.get("template", "")
138 if template == "json":
176 if template == "json":
General Comments 0
You need to be logged in to leave comments. Login now