[Commits] r458 - website
commits at geoext.org
commits at geoext.org
Fri Apr 24 02:57:00 CEST 2009
Author: tschaub
Date: 2009-04-24 02:57:00 +0200 (Fri, 24 Apr 2009)
New Revision: 458
Modified:
website/jst.py
Log:
Supporting bracket notation with keys for generating ordered lists in context (will support inheritance eventually).
Modified: website/jst.py
===================================================================
--- website/jst.py 2009-04-24 00:34:18 UTC (rev 457)
+++ website/jst.py 2009-04-24 00:57:00 UTC (rev 458)
@@ -11,8 +11,9 @@
JST_RE = re.compile(r'^\s*/\*\*\s*jst\s*:\s*(.*?)\s*$')
COMMENT_RE = re.compile(r'^\s*\*?')
ENDCOMMENT_RE = re.compile(r'^\s*\*/')
-DEF_RE = re.compile(r"\s*([\w\.]+)\s*=\s*(.*)$")
+DEF_RE = re.compile(r"\s*(\w+)\s*=\s*(.*?)\s*$")
INDENTED_RE = re.compile(r"^\s+\S")
+BRACKET_RE = re.compile(r"(\w+)\[(.*?)\]")
_marker = object()
@@ -58,13 +59,13 @@
if filename.endswith(SUFFIX_JS) and not filename.startswith("."):
filepath = os.path.join(root, filename)[len(sourcedir)+1:]
jsfile = SourceFile(sourcedir, filepath)
- if jsfile.data:
+ if jsfile.context:
template_filename = os.path.join(sourcedir, filepath.split(SUFFIX_JS)[0] + SUFFIX_JST)
if not os.path.exists(template_filename):
# throw something if template not given in config here
template_filename = cfg["template"]
template = Template(open(template_filename, "U").read())
- out = template.render(jsfile.data)
+ out = template.render(jsfile.context)
output_filename = os.path.join(outdir, filepath.split(SUFFIX_JS)[0] + SUFFIX_RST)
f = open(output_filename, "w")
f.write(out)
@@ -79,6 +80,7 @@
self.source = open(os.path.join(sourcedir, filepath), "U").readlines()
self._data = _marker
self._jst_comments = _marker
+ self._context = _marker
@property
def jst_comments(self):
@@ -129,15 +131,20 @@
data[m.group(1)] = m.group(2)
else:
block = "".join(block)
- if label[-2:] == "[]":
- short = label[:-2]
- if data.has_key(short):
- if type(data[short]) is type([]):
- data[short] += [block]
- else:
- data[short] = [data[short], block]
+ m = BRACKET_RE.match(label)
+ if m:
+ name = m.group(1)
+ key = m.group(2)
+ if len(key) > 0:
+ # dictionary
+ if not data.has_key(name):
+ data[name] = {}
+ data[name][key] = block
else:
- data[short] = [block]
+ # list
+ if not data.has_key(name):
+ data[name] = []
+ data[name] += [block]
else:
data[label] = block
if len(self.jst_comments) > 0:
@@ -145,6 +152,24 @@
else:
self._data = None
return self._data
+
+ @property
+ def context(self):
+ if self._context == _marker:
+ data = self.data
+ if data:
+ context = {}
+ for (key, val) in data.items():
+ if type(val) is type({}):
+ # create ordered lists out of dictionaries
+ context[key] = [val[k] for k in sorted(val.keys())]
+ else:
+ context[key] = val
+ self._context = context
+ else:
+ self._context = None
+ return self._context
+
More information about the Commits
mailing list