From 85d68990750019480d2877af93b2c06dfc19c970 Mon Sep 17 00:00:00 2001 From: Tobias Langer Date: Fri, 7 Oct 2016 12:49:26 +0200 Subject: [PATCH] Added utility functions to fiddle around with text in mustache file. --- generate.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/generate.py b/generate.py index 660289d..75621e9 100755 --- a/generate.py +++ b/generate.py @@ -20,6 +20,29 @@ import shutil import json import pystache +class UtilityFunctions(pystache.TemplateSpec): + def Upper(self, text=None): + """ + Capitalize a given token + """ + return lambda txt: txt.upper() + + def Lower(self, text=None): + """ + Return the given text in lowercase. + """ + return lambda txt: txt.lower() + + def CamelCase(self, text=None): + """ + Capitalize the first letter of the given text. + """ + def _camel(text): + text[0].upper() + return text + return _camel + + def query_yes_no(question, default=None): """ Queries the user for a decision. @@ -62,7 +85,7 @@ def create_header(headerfile, experiment, destination): """ with open(headerfile, 'r') as header_template: template = header_template.read() - header_txt = pystache.render(template, experiment) + header_txt = pystache.render(template, experiment, UtilityFunctions()) with open(destination, 'w') as header: print(header_txt, file=header) -- libgit2 0.26.0