Skip to content

Commit

Permalink
Fix template issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledyba committed Jul 23, 2021
1 parent a0f6cc9 commit b77026e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ server/node_modules
server/dist
var
dev-var
_shelf
backup-*
16 changes: 10 additions & 6 deletions server/src/controller/ura/lib/UraTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Asset from 'lib/asset';
import Config from '../../../Config';
import dayjs from "dayjs";

const kCompileOption: CompileOptions = {
preventIndent: true,
};

export default class UraTemplate<T = any> {
private readonly hbs: typeof Handlebars;
private readonly template: Handlebars.TemplateDelegate<T>;
Expand All @@ -12,23 +16,23 @@ export default class UraTemplate<T = any> {
}
static async create<T>(asset: Asset, contentFilepath: string): Promise<UraTemplate<T>> {
const hbs = Handlebars.create();
hbs.registerPartial('omote-url', hbs.compile(`//${Config.OmoteHost}/`));
hbs.registerPartial('ura-url', hbs.compile(`//${Config.UraHost}/`));
hbs.registerPartial('content', hbs.compile(await asset.loadString(`templates/ura/${contentFilepath}`)));
hbs.registerPartial('currentYear', hbs.compile(`${dayjs().year()}`));
hbs.registerPartial('omote-url', hbs.compile(`//${Config.OmoteHost}/`, kCompileOption));
hbs.registerPartial('ura-url', hbs.compile(`//${Config.UraHost}/`, kCompileOption));
hbs.registerPartial('content', hbs.compile(await asset.loadString(`templates/ura/${contentFilepath}`), kCompileOption));
hbs.registerPartial('currentYear', hbs.compile(`${dayjs().year()}`, kCompileOption));
hbs.registerHelper('eq', function (arg1: any, arg2: any):boolean {
return arg1 === arg2;
})
const src = await asset.loadString('templates/ura/_main.hbs');
const template = hbs.compile<T>(src);
const template = hbs.compile<T>(src, kCompileOption);
return new UraTemplate<T>(hbs, template);
}
registerPartial(name: string, fn: Template): UraTemplate<T> {
this.hbs.registerPartial(name, fn);
return this;
}
registerString(name: string, content: string): UraTemplate<T> {
this.hbs.registerPartial(name, this.hbs.compile(content));
this.hbs.registerPartial(name, this.hbs.compile(content, kCompileOption));
return this;
}
registerHelper(name: string, fn: Handlebars.HelperDelegate): UraTemplate<T> {
Expand Down
65 changes: 0 additions & 65 deletions server/src/importer.ts

This file was deleted.

0 comments on commit b77026e

Please sign in to comment.