[template-glib] examples: add vala example
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] examples: add vala example
- Date: Sat, 23 Jan 2016 20:15:16 +0000 (UTC)
commit 3f30882e877a867f1324deb1c92accfd65d46d65
Author: Christian Hergert <christian hergert me>
Date: Sat Jan 23 12:14:52 2016 -0800
examples: add vala example
examples/Makefile.am | 12 ++++++++++++
examples/simple-vala.vala | 25 +++++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 81daf0d..fe2e521 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -9,4 +9,16 @@ simple_SOURCES = simple.c
simple_CFLAGS = $(TMPL_CFLAGS) -I$(top_srcdir)/src
simple_LDADD = $(top_builddir)/src/libtemplate-glib-1.0.la
+if ENABLE_VAPIGEN
+noinst_PROGRAMS += simple-vala
+
+simple_vala_SOURCES = simple-vala.vala
+simple_vala_CFLAGS = $(TMPL_CFLAGS) -I$(top_srcdir)/src
+simple_vala_LDADD = $(top_builddir)/src/libtemplate-glib-1.0.la
+simple_vala_VALAFLAGS = \
+ --vapidir $(top_builddir)/src \
+ --pkg template-glib-1.0
+
+endif
+
-include $(top_srcdir)/git.mk
diff --git a/examples/simple-vala.vala b/examples/simple-vala.vala
new file mode 100644
index 0000000..58d11c3
--- /dev/null
+++ b/examples/simple-vala.vala
@@ -0,0 +1,25 @@
+using GLib;
+using Template;
+
+static int main (string[] argv)
+{
+ var file = GLib.File.new_for_path("simple.tmpl");
+ var tmpl = new Template.Template (null);
+
+ try {
+ tmpl.parse_file (file, null);
+
+ var scope = new Template.Scope ();
+
+ var title = scope.get ("title");
+ title.assign_string ("Example Title");
+
+ 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]