summaryrefslogtreecommitdiffstats
path: root/src/web/template.vala
diff options
context:
space:
mode:
authorHolger Cremer <HolgerCremer@gmail.com>2018-08-27 19:38:11 +0200
committerHolger Cremer <HolgerCremer@gmail.com>2018-08-27 19:38:11 +0200
commit8f2ba2050ee78d0e4a47f1277c6bc4422d06170c (patch)
treec008d2878905e03df7a8bf8bd3330762cc2d8f43 /src/web/template.vala
parentbb55e121576a5b5d225bfc68c5062f386cc32db9 (diff)
parent3fc3ea6c6df237dbdf48d14703118b747bf5d647 (diff)
downloadserial-barcode-scanner-8f2ba2050ee78d0e4a47f1277c6bc4422d06170c.tar.bz2
Merge branch 'master' into better_inventory
Conflicts: README data/templates/products/entry.html docker/Dockerfile docker/init.sh src/database/database.vala src/database/db-interface.vala src/pdf-stock/Makefile src/pdf-stock/pdf-stock-interface.vala src/pdf-stock/pdf-stock.vala src/web/Makefile src/web/main.vala templates/menu.html templates/products/index.html
Diffstat (limited to 'src/web/template.vala')
-rw-r--r--src/web/template.vala41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/web/template.vala b/src/web/template.vala
index b5265d8..009ebcf 100644
--- a/src/web/template.vala
+++ b/src/web/template.vala
@@ -24,44 +24,48 @@ public class WebTemplate {
public uint8[] data { get { return template.data; } }
public WebTemplate(string file, WebSession login) throws TemplateError {
- var b = File.new_for_path(templatedir+"base.html");
- var m = File.new_for_path(templatedir+"menu.html");
- var f = File.new_for_path(templatedir+file);
+ var bf = Path.build_filename(templatedir, "base.html");
+ var b = File.new_for_path(bf);
+ var mf = Path.build_filename(templatedir, "menu.html");
+ var m = File.new_for_path(mf);
+ var ff = Path.build_filename(templatedir, file);
+ var f = File.new_for_path(ff);
File fauth;
if(login.logged_in)
- fauth = File.new_for_path(templatedir+"menu_logout.html");
+ fauth = File.new_for_path(Path.build_filename(templatedir, "menu_logout.html"));
else
- fauth = File.new_for_path(templatedir+"menu_login.html");
+ fauth = File.new_for_path(Path.build_filename(templatedir, "menu_login.html"));
uint8[] basis, menu, template, auth;
if(!b.query_exists())
- throw new TemplateError.NOT_FOUND(templatedir+"base.html not found!");
+ throw new TemplateError.NOT_FOUND(_("%s not found!").printf(bf));
if(!m.query_exists())
- throw new TemplateError.NOT_FOUND(templatedir+"menu.html not found!");
+ throw new TemplateError.NOT_FOUND(_("%s not found!").printf(mf));
if(!fauth.query_exists())
- throw new TemplateError.NOT_FOUND(fauth.get_path()+" not found!");
+ throw new TemplateError.NOT_FOUND(_("%s not found!").printf(fauth.get_path()));
if(!f.query_exists())
- throw new TemplateError.NOT_FOUND(templatedir+file+" not found!");
+ throw new TemplateError.NOT_FOUND(_("%s not found!").printf(ff));
try {
if(!b.load_contents(null, out basis, null))
- throw new TemplateError.NOT_LOADABLE(templatedir+"base.html could not be loaded!");
+ throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(bf));
if(!m.load_contents(null, out menu, null))
- throw new TemplateError.NOT_LOADABLE(templatedir+"menu.html could not be loaded!");
+ throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(mf));
if(!fauth.load_contents(null, out auth, null))
- throw new TemplateError.NOT_LOADABLE(fauth.get_path()+" could not be loaded!");
+ throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(fauth.get_path()));
if(!f.load_contents(null, out template, null))
- throw new TemplateError.NOT_LOADABLE(templatedir+file+" could not be loaded!");
+ throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(ff));
} catch(Error e) {
- throw new TemplateError.NOT_LOADABLE("could not load templates!");
+ throw new TemplateError.NOT_LOADABLE(_("could not load templates!"));
}
this.template = ((string) basis).replace("{{{NAVBAR}}}", ((string) menu));
+ this.template = this.template.replace("{{{SHORTNAME}}}", shortname);
this.template = this.template.replace("{{{AUTH}}}", ((string) auth));
this.template = this.template.replace("{{{CONTENT}}}", ((string) template));
this.template = this.template.replace("{{{USERNAME}}}", login.name);
@@ -71,17 +75,18 @@ public class WebTemplate {
}
public WebTemplate.DATA(string file) throws TemplateError {
- var f = File.new_for_path(templatedir+file);
+ var ff = Path.build_filename(templatedir, file);
+ var f = File.new_for_path(ff);
uint8[] template;
if(!f.query_exists())
- throw new TemplateError.NOT_FOUND(templatedir+file+" not found!");
+ throw new TemplateError.NOT_FOUND(_("%s not found!").printf(ff));
try {
if(!f.load_contents(null, out template, null))
- throw new TemplateError.NOT_LOADABLE(templatedir+file+" could not be loaded!");
+ throw new TemplateError.NOT_LOADABLE(_("%s could not be loaded!").printf(ff));
} catch(Error e) {
- throw new TemplateError.NOT_LOADABLE("could not load templates!");
+ throw new TemplateError.NOT_LOADABLE(_("could not load templates!"));
}
this.template = (string) template;