mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 05:50:43 -07:00
feat: support custom key-value separator, #752
This commit is contained in:
@@ -39,4 +39,8 @@ describe('Hash', function () {
|
||||
num3: 4
|
||||
})
|
||||
})
|
||||
it('should support custom separator', async function () {
|
||||
const hash = await toPromise(new Hash('num=2.3', '=').render(new Context()))
|
||||
expect(hash.num).toBe(2.3)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -15,7 +15,7 @@ type HashValueTokens = Record<string, Token | undefined>
|
||||
*/
|
||||
export class Hash {
|
||||
hash: HashValueTokens = {}
|
||||
constructor (markup: string, jekyllStyle?: boolean) {
|
||||
constructor (markup: string, jekyllStyle?: boolean | string) {
|
||||
const tokenizer = new Tokenizer(markup, {})
|
||||
for (const hash of tokenizer.readHashes(jekyllStyle)) {
|
||||
this.hash[hash.name.content] = hash.value
|
||||
|
||||
@@ -21,7 +21,7 @@ export function createTagClass (options: TagImplOptions): TagClass {
|
||||
}
|
||||
}
|
||||
* render (ctx: Context, emitter: Emitter): TagRenderReturn {
|
||||
const hash = (yield new Hash(this.token.args).render(ctx)) as Record<string, any>
|
||||
const hash = (yield new Hash(this.token.args, ctx.opts.keyValueSeparator).render(ctx)) as Record<string, any>
|
||||
return yield options.render.call(this, ctx, emitter, hash)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user