mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-14 20:00:39 -07:00
fix: directory info in lookupError message, #395
This commit is contained in:
@@ -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', {
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"liquidjs": "latest"
|
||||
"liquidjs": "^9.27.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<li>{{index}} - {{todo}}</li>
|
||||
@@ -2,6 +2,6 @@
|
||||
{%header content: title | capitalize%}
|
||||
<ul>
|
||||
{% for todo in todos %}
|
||||
<li>{{forloop.index}} - {{todo}}</li>
|
||||
{% render 'todo.liquid' with todo, index: forloop.index%}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
+5
-5
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user