aboutsummaryrefslogtreecommitdiff
path: root/test.js
diff options
context:
space:
mode:
authorpabs@pablotron.org <pabs@pablotron.org>2014-08-24 01:15:02 -0400
committerpabs@pablotron.org <pabs@pablotron.org>2014-08-24 01:15:02 -0400
commitdd9d9521f810a038a68134756647c10d05815a26 (patch)
tree531b2a41f522a23f3bc3f5f716a0027a54d91818 /test.js
downloadluigi-template-dd9d9521f810a038a68134756647c10d05815a26.tar.bz2
luigi-template-dd9d9521f810a038a68134756647c10d05815a26.zip
initial commit (moved from different repo)
Diffstat (limited to 'test.js')
-rw-r--r--test.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..afbad18
--- /dev/null
+++ b/test.js
@@ -0,0 +1,58 @@
+
+load('luigi-template.js');
+
+// define custom template filter
+function custom_filter(v) {
+ return "foo" + v + "bar";
+}
+
+function custom_filter_with_args(v, args) {
+ var i, l, r = [v];
+
+ for (i = 0, l = args.length; i < l; i++)
+ r.push(args[i]);
+
+ return r.join(' and ');
+}
+
+// add custom template filters
+LuigiTemplate.FILTERS.custom = custom_filter;
+LuigiTemplate.FILTERS.custom_args = custom_filter_with_args;
+
+// build template string
+var template_str = [
+ // test basic templates
+ "%{greet}, %{name}!",
+
+ // test filters and filters with parameters
+ "Your name hashes to: %{name|hash(sha1)|uc}",
+
+ // test custom filter
+ "Your custom filtered name is: %{name|custom}",
+
+ // test custom filter with arguments
+ "Your custom_args name is: %{name|custom_args(foo,bar,baz)}",
+
+ // test whitespace in filters
+ "random test: %{name | hash( sha512 ) | uc }",
+
+ // test pluralize filter
+ 'pluralize test (0): %{count_0} %{count_0 | pluralize(item)}',
+ 'pluralize test (1): %{count_1} %{count_1 | pluralize(item)}',
+ 'pluralize test (10): %{count_10} %{count_10 | pluralize(item)}',
+
+ // terminating newline
+ ''
+].join("\n");
+
+// build template
+var t = new LuigiTemplate(template_str);
+
+// print results
+print(t.run({
+ greet: 'hello',
+ name: 'paul',
+ count_0: 0,
+ count_1: 1,
+ count_10: 10
+}));