[template-glib] add gjs example



commit 9cf6c92bdc0d18f0e936a2da63bcf97346681dd8
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 11 06:13:55 2016 -0800

    add gjs example

 examples/simple.js |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/examples/simple.js b/examples/simple.js
new file mode 100644
index 0000000..4a37488
--- /dev/null
+++ b/examples/simple.js
@@ -0,0 +1,22 @@
+const Template = imports.gi.Template;
+const Gio = imports.gi.Gio;
+
+// Get our file to process
+let file = Gio.File.new_for_path("simple.tmpl");
+
+// Create a new template and parse our input file
+let tmpl = new Template.Template();
+tmpl.parse_file(file, null);
+
+// Create scope for expansion
+let scope = Template.Scope.new ();
+
+// Create and assign "title" variable in scope
+let title = scope.get("title");
+title.assign_string("Example Title");
+
+// Write to stdout
+let stream = Gio.UnixOutputStream.new (0, false);
+
+// Expand the template into stream
+tmpl.expand(stream, scope, null);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]