[template-glib: 2/4] A simple vala application that satisfies article.tmpl



commit 295ac5f632ea35e568386299939a976434dcf8cd
Author: Zander Brown <ajhb2001 outlook com>
Date:   Sat Feb 3 22:58:24 2018 +0000

    A simple vala application that satisfies article.tmpl

 examples/article.vala | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
---
diff --git a/examples/article.vala b/examples/article.vala
new file mode 100644
index 0000000..d490d23
--- /dev/null
+++ b/examples/article.vala
@@ -0,0 +1,42 @@
+using GLib;
+using Template;
+
+class Article : Object {
+       public string title {
+               get { return "Sample Article"; }
+       }
+
+       public string author {
+               get { return Environment.get_user_name(); }
+       }
+
+       private string _date = (new DateTime.now_local()).to_string();
+       public string date {
+               get { return  _date; }
+       }
+
+       private string[] _sections = {"Iterate", "over", "strv"};
+       public string[] sections {
+               get { return _sections; }
+       }
+}
+
+static int main (string[] args) {
+       var file = GLib.File.new_for_path("article.tmpl");
+       var tmpl = new Template.Template (null);
+
+       try {
+               tmpl.parse_file (file, null);
+
+               var scope = new Template.Scope ();
+
+               scope["article"].assign_object(new Article());
+
+               var expanded = tmpl.expand_string (scope);
+               stdout.printf ("%s\n", expanded);
+       } catch (GLib.Error ex) {
+               stderr.printf ("%s\n", ex.message);
+               return 1;
+       }
+       return 0;
+}


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