diff --git a/demo/nodejs/index.js b/demo/nodejs/index.js index 88f1c1f6c..8849502bc 100644 --- a/demo/nodejs/index.js +++ b/demo/nodejs/index.js @@ -1,9 +1,14 @@ const { Liquid } = require('liquidjs') const engine = new Liquid({ - root: __dirname, extname: '.liquid', - globals: { title: 'LiquidJS Demo' } + globals: { title: 'LiquidJS Demo' }, + // root files for `.render()` and `.parse()` + root: __dirname, + // layout files for `{% layout %}` + layouts: './layouts', + // partial files for `{% include %}` and `{% render %}` + partials: './partials' }) engine.registerTag('header', { diff --git a/demo/nodejs/html.liquid b/demo/nodejs/layouts/html.liquid similarity index 100% rename from demo/nodejs/html.liquid rename to demo/nodejs/layouts/html.liquid diff --git a/demo/nodejs/package.json b/demo/nodejs/package.json index 68a69386a..e796be483 100644 --- a/demo/nodejs/package.json +++ b/demo/nodejs/package.json @@ -7,6 +7,6 @@ "start": "node index.js" }, "dependencies": { - "liquidjs": "latest" + "liquidjs": "^9.27.0" } } diff --git a/demo/nodejs/footer.liquid b/demo/nodejs/partials/footer.liquid similarity index 100% rename from demo/nodejs/footer.liquid rename to demo/nodejs/partials/footer.liquid diff --git a/demo/nodejs/partials/todo.liquid b/demo/nodejs/partials/todo.liquid new file mode 100644 index 000000000..d81a9f163 --- /dev/null +++ b/demo/nodejs/partials/todo.liquid @@ -0,0 +1 @@ +
  • {{index}} - {{todo}}
  • diff --git a/demo/nodejs/todolist.liquid b/demo/nodejs/todolist.liquid index ff6d19b6b..e3156a889 100644 --- a/demo/nodejs/todolist.liquid +++ b/demo/nodejs/todolist.liquid @@ -2,6 +2,6 @@ {%header content: title | capitalize%} \ No newline at end of file diff --git a/src/fs/loader.ts b/src/fs/loader.ts index 9fc7b0005..41632fd1c 100644 --- a/src/fs/loader.ts +++ b/src/fs/loader.ts @@ -20,16 +20,16 @@ export class Loader { } public * lookup (file: string, type: LookupType, sync?: boolean) { - const { fs, root } = this.options - for (const filepath of this.candidates(file, type)) { + const { fs } = this.options + const dirs = this.options[type] + for (const filepath of this.candidates(file, dirs)) { if (sync ? fs.existsSync(filepath) : yield fs.exists(filepath)) return filepath } - throw this.lookupError(file, root) + throw this.lookupError(file, dirs) } - private * candidates (file: string, type: LookupType) { + private * candidates (file: string, dirs: string[]) { const { fs, extname } = this.options - const dirs = this.options[type] for (const dir of dirs) { yield fs.resolve(dir, file, extname) }