]> Devi Nivas Git - chevron.git/commitdiff
Added nicer file targeting
authornoah morrison <noah@morrison.ph>
Fri, 31 Oct 2014 18:35:43 +0000 (14:35 -0400)
committernoah morrison <noah@morrison.ph>
Fri, 31 Oct 2014 18:35:43 +0000 (14:35 -0400)
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
chevron.py
data.json [new file with mode: 0644]

index 8dfb475497cbcc54b68850ca4e9ce7dba68450ee..1cd4fad58e200a4a8a0b17d20df87574ff5b2e8a 100644 (file)
--- 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]
index 35a990150e43a27f78db09f27f53fb371f519308..26973b913b0667d43ee6a5a5d0357867bba6829f 100755 (executable)
@@ -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 (file)
index 0000000..c2a89b0
--- /dev/null
+++ b/data.json
@@ -0,0 +1,7 @@
+{
+  "thing": "world",
+  "html_escaped": "<b>no escape!</b>",
+  "html_escaped2": "<i>ok</i>",
+  "show": true,
+  "delimiter": "custom delimiters work!"
+}