summaryrefslogtreecommitdiff
path: root/mako/template.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-04-14 11:21:10 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-04-14 11:21:10 -0400
commit6d96ef8c2d454622070d2d63ed0a2a911cde3834 (patch)
tree0e8d97d4df6a43e573d2d9c01d751117a45fe518 /mako/template.py
parent10c0aae0e06832d7a1684063246568dc93217b7a (diff)
downloadmako-6d96ef8c2d454622070d2d63ed0a2a911cde3834.tar.gz
- add module source thing as ModuleInfo.get_module_source_metadata
Diffstat (limited to 'mako/template.py')
-rw-r--r--mako/template.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/mako/template.py b/mako/template.py
index 00783b7..c19a66a 100644
--- a/mako/template.py
+++ b/mako/template.py
@@ -596,6 +596,26 @@ class ModuleInfo(object):
if module_filename:
self._modules[module_filename] = self
+ @classmethod
+ def get_module_source_metadata(cls, module_source, full_line_map=False):
+ source_map = re.search(
+ r"__M_BEGIN_METADATA(.+?)__M_END_METADATA",
+ module_source, re.S).group(1)
+ source_map = compat.json.loads(source_map)
+ if full_line_map:
+ line_map = source_map['full_line_map'] = dict(
+ (int(k), v) for k, v in source_map['line_map'].items()
+ )
+
+ for mod_line in reversed(sorted(line_map)):
+ tmpl_line = line_map[mod_line]
+ while mod_line > 0:
+ mod_line -= 1
+ if mod_line in line_map:
+ break
+ line_map[mod_line] = tmpl_line
+ return source_map
+
@property
def code(self):
if self.module_source is not None: