mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
fix: respect fs in parser options, for #233
This commit is contained in:
+3
-3
@@ -66,7 +66,7 @@ const browserEsm = {
|
|||||||
external: ['path', 'fs'],
|
external: ['path', 'fs'],
|
||||||
plugins: [
|
plugins: [
|
||||||
replace({
|
replace({
|
||||||
include: './src/liquid.ts',
|
include: './src/liquid-options.ts',
|
||||||
delimiters: ['', ''],
|
delimiters: ['', ''],
|
||||||
'./fs/node': './fs/browser'
|
'./fs/node': './fs/browser'
|
||||||
}),
|
}),
|
||||||
@@ -95,7 +95,7 @@ const browserUmd = {
|
|||||||
}],
|
}],
|
||||||
plugins: [
|
plugins: [
|
||||||
replace({
|
replace({
|
||||||
include: './src/liquid.ts',
|
include: './src/liquid-options.ts',
|
||||||
delimiters: ['', ''],
|
delimiters: ['', ''],
|
||||||
'./fs/node': './fs/browser'
|
'./fs/node': './fs/browser'
|
||||||
}),
|
}),
|
||||||
@@ -123,7 +123,7 @@ const browserMin = {
|
|||||||
}],
|
}],
|
||||||
plugins: [
|
plugins: [
|
||||||
replace({
|
replace({
|
||||||
include: './src/liquid.ts',
|
include: './src/liquid-options.ts',
|
||||||
delimiters: ['', ''],
|
delimiters: ['', ''],
|
||||||
'./fs/node': './fs/browser'
|
'./fs/node': './fs/browser'
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Template } from './template/template'
|
|||||||
import { Cache } from './cache/cache'
|
import { Cache } from './cache/cache'
|
||||||
import { LRU } from './cache/lru'
|
import { LRU } from './cache/lru'
|
||||||
import { FS } from './fs/fs'
|
import { FS } from './fs/fs'
|
||||||
|
import * as fs from './fs/node'
|
||||||
import { defaultOperators, Operators } from './render/operator'
|
import { defaultOperators, Operators } from './render/operator'
|
||||||
import { createTrie, Trie } from './util/operator-trie'
|
import { createTrie, Trie } from './util/operator-trie'
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ export interface NormalizedFullOptions extends NormalizedOptions {
|
|||||||
cache: undefined | Cache<Template[]>;
|
cache: undefined | Cache<Template[]>;
|
||||||
jsTruthy: boolean;
|
jsTruthy: boolean;
|
||||||
dynamicPartials: boolean;
|
dynamicPartials: boolean;
|
||||||
|
fs: FS;
|
||||||
strictFilters: boolean;
|
strictFilters: boolean;
|
||||||
strictVariables: boolean;
|
strictVariables: boolean;
|
||||||
lenientIf: boolean;
|
lenientIf: boolean;
|
||||||
@@ -88,6 +90,7 @@ export const defaultOptions: NormalizedFullOptions = {
|
|||||||
root: ['.'],
|
root: ['.'],
|
||||||
cache: undefined,
|
cache: undefined,
|
||||||
extname: '',
|
extname: '',
|
||||||
|
fs: fs,
|
||||||
dynamicPartials: true,
|
dynamicPartials: true,
|
||||||
jsTruthy: false,
|
jsTruthy: false,
|
||||||
trimTagRight: false,
|
trimTagRight: false,
|
||||||
|
|||||||
+6
-11
@@ -1,5 +1,4 @@
|
|||||||
import { Context } from './context/context'
|
import { Context } from './context/context'
|
||||||
import * as fs from './fs/node'
|
|
||||||
import { forOwn, snakeCase } from './util/underscore'
|
import { forOwn, snakeCase } from './util/underscore'
|
||||||
import { Template } from './template/template'
|
import { Template } from './template/template'
|
||||||
import { Tokenizer } from './parser/tokenizer'
|
import { Tokenizer } from './parser/tokenizer'
|
||||||
@@ -13,7 +12,6 @@ import { TagMap } from './template/tag/tag-map'
|
|||||||
import { FilterMap } from './template/filter/filter-map'
|
import { FilterMap } from './template/filter/filter-map'
|
||||||
import { LiquidOptions, normalizeStringArray, NormalizedFullOptions, applyDefault, normalize } from './liquid-options'
|
import { LiquidOptions, normalizeStringArray, NormalizedFullOptions, applyDefault, normalize } from './liquid-options'
|
||||||
import { FilterImplOptions } from './template/filter/filter-impl-options'
|
import { FilterImplOptions } from './template/filter/filter-impl-options'
|
||||||
import { FS } from './fs/fs'
|
|
||||||
import { toPromise, toValue } from './util/async'
|
import { toPromise, toValue } from './util/async'
|
||||||
import { Emitter } from './render/emitter'
|
import { Emitter } from './render/emitter'
|
||||||
|
|
||||||
@@ -25,13 +23,11 @@ export class Liquid {
|
|||||||
public parser: Parser
|
public parser: Parser
|
||||||
public filters: FilterMap
|
public filters: FilterMap
|
||||||
public tags: TagMap
|
public tags: TagMap
|
||||||
private fs: FS
|
|
||||||
|
|
||||||
public constructor (opts: LiquidOptions = {}) {
|
public constructor (opts: LiquidOptions = {}) {
|
||||||
this.options = applyDefault(normalize(opts))
|
this.options = applyDefault(normalize(opts))
|
||||||
this.parser = new Parser(this)
|
this.parser = new Parser(this)
|
||||||
this.renderer = new Render()
|
this.renderer = new Render()
|
||||||
this.fs = opts.fs || fs
|
|
||||||
this.filters = new FilterMap(this.options.strictFilters, this)
|
this.filters = new FilterMap(this.options.strictFilters, this)
|
||||||
this.tags = new TagMap()
|
this.tags = new TagMap()
|
||||||
|
|
||||||
@@ -70,9 +66,9 @@ export class Liquid {
|
|||||||
|
|
||||||
public * _parseFile (file: string, opts?: LiquidOptions, sync?: boolean) {
|
public * _parseFile (file: string, opts?: LiquidOptions, sync?: boolean) {
|
||||||
const options = { ...this.options, ...normalize(opts) }
|
const options = { ...this.options, ...normalize(opts) }
|
||||||
const paths = options.root.map(root => this.fs.resolve(root, file, options.extname))
|
const paths = options.root.map(root => options.fs.resolve(root, file, options.extname))
|
||||||
if (this.fs.fallback !== undefined) {
|
if (options.fs.fallback !== undefined) {
|
||||||
const filepath = this.fs.fallback(file)
|
const filepath = options.fs.fallback(file)
|
||||||
if (filepath !== undefined) paths.push(filepath)
|
if (filepath !== undefined) paths.push(filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,8 +78,8 @@ export class Liquid {
|
|||||||
const tpls = yield cache.read(filepath)
|
const tpls = yield cache.read(filepath)
|
||||||
if (tpls) return tpls
|
if (tpls) return tpls
|
||||||
}
|
}
|
||||||
if (!(sync ? this.fs.existsSync(filepath) : yield this.fs.exists(filepath))) continue
|
if (!(sync ? options.fs.existsSync(filepath) : yield options.fs.exists(filepath))) continue
|
||||||
const tpl = this.parse(sync ? this.fs.readFileSync(filepath) : yield this.fs.readFile(filepath), filepath)
|
const tpl = this.parse(sync ? options.fs.readFileSync(filepath) : yield options.fs.readFile(filepath), filepath)
|
||||||
if (cache) cache.write(filepath, tpl)
|
if (cache) cache.write(filepath, tpl)
|
||||||
return tpl
|
return tpl
|
||||||
}
|
}
|
||||||
@@ -100,8 +96,7 @@ export class Liquid {
|
|||||||
return this.render(templates, ctx, opts)
|
return this.render(templates, ctx, opts)
|
||||||
}
|
}
|
||||||
public renderFileSync (file: string, ctx?: object, opts?: LiquidOptions) {
|
public renderFileSync (file: string, ctx?: object, opts?: LiquidOptions) {
|
||||||
const options = normalize(opts)
|
const templates = this.parseFileSync(file, opts)
|
||||||
const templates = this.parseFileSync(file, options)
|
|
||||||
return this.renderSync(templates, ctx, opts)
|
return this.renderSync(templates, ctx, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user