mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
fix: directory info in lookupError message, #395
This commit is contained in:
@@ -1,9 +1,14 @@
|
|||||||
const { Liquid } = require('liquidjs')
|
const { Liquid } = require('liquidjs')
|
||||||
|
|
||||||
const engine = new Liquid({
|
const engine = new Liquid({
|
||||||
root: __dirname,
|
|
||||||
extname: '.liquid',
|
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', {
|
engine.registerTag('header', {
|
||||||
|
|||||||
@@ -7,6 +7,6 @@
|
|||||||
"start": "node index.js"
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"liquidjs": "latest"
|
"liquidjs": "^9.27.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<li>{{index}} - {{todo}}</li>
|
||||||
@@ -2,6 +2,6 @@
|
|||||||
{%header content: title | capitalize%}
|
{%header content: title | capitalize%}
|
||||||
<ul>
|
<ul>
|
||||||
{% for todo in todos %}
|
{% for todo in todos %}
|
||||||
<li>{{forloop.index}} - {{todo}}</li>
|
{% render 'todo.liquid' with todo, index: forloop.index%}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
+5
-5
@@ -20,16 +20,16 @@ export class Loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public * lookup (file: string, type: LookupType, sync?: boolean) {
|
public * lookup (file: string, type: LookupType, sync?: boolean) {
|
||||||
const { fs, root } = this.options
|
const { fs } = this.options
|
||||||
for (const filepath of this.candidates(file, type)) {
|
const dirs = this.options[type]
|
||||||
|
for (const filepath of this.candidates(file, dirs)) {
|
||||||
if (sync ? fs.existsSync(filepath) : yield fs.exists(filepath)) return filepath
|
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 { fs, extname } = this.options
|
||||||
const dirs = this.options[type]
|
|
||||||
for (const dir of dirs) {
|
for (const dir of dirs) {
|
||||||
yield fs.resolve(dir, file, extname)
|
yield fs.resolve(dir, file, extname)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user