File: article.vala

package info (click to toggle)
template-glib 3.38.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 788 kB
  • sloc: ansic: 6,774; yacc: 288; lex: 237; javascript: 16; makefile: 14; python: 12
file content (42 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
}