From 068f30f88ecc986ea4bb6de1e231711d5a1940cf Mon Sep 17 00:00:00 2001 From: noah morrison Date: Fri, 31 Oct 2014 14:35:43 -0400 Subject: [PATCH] Added nicer file targeting You can now specify the data and template files from the command line. Also added a data.json file, even though it is currently unused. --- README.md | 5 ++++- chevron.py | 7 ++++++- data.json | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 data.json diff --git a/README.md b/README.md index 8dfb475..1cd4fad 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ A python3 implementation of the [mustache templating language](http://mustache.github.io). -Currently it only tokenizes the file, and doesn't have any nice way of changing the target file. +Currently it only tokenizes the template file. + +Current usage: + ./chevron.py [data file] [template file] diff --git a/chevron.py b/chevron.py index 35a9901..26973b9 100755 --- a/chevron.py +++ b/chevron.py @@ -1,5 +1,7 @@ #!/usr/bin/python +import sys + def tokenize(template): class EOF(Exception): @@ -70,7 +72,10 @@ def tokenize(template): if __name__ == '__main__': - with open('test.mustache', 'r') as f: + data = sys.argv[1] + template = sys.argv[2] + + with open(template, 'r') as f: template = f.read() tokens = tokenize(template) diff --git a/data.json b/data.json new file mode 100644 index 0000000..c2a89b0 --- /dev/null +++ b/data.json @@ -0,0 +1,7 @@ +{ + "thing": "world", + "html_escaped": "no escape!", + "html_escaped2": "ok", + "show": true, + "delimiter": "custom delimiters work!" +} -- 2.47.3