File: simple.js

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 (23 lines) | stat: -rw-r--r-- 606 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
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
let expanded = tmpl.expand_string(scope);
log(expanded);