Skip to content

Commit

Permalink
Merge pull request #59 from posthtml/fix-locals-content
Browse files Browse the repository at this point in the history
fix: parse options locals when passed as content
  • Loading branch information
Scrum authored Jan 27, 2021
2 parents 90c6d00 + 5f928c8 commit 2faf42c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function parse(options) {
node.attrs &&
isJSON(node.attrs.locals)
) {
return parseLocals(node.attrs.locals)(node.content);
return parseLocals(node.attrs.locals, options.locals)(node.content);
}

return node.content || '';
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ test('Must parse locals passed to <content>', async t => {
});

test('Must parse locals passed as option', async t => {
const actual = `<module href="./test/locals.option.spec.html" locals='{"inlineFoo": "inlineBar"}'>test</module>`;
const expected = `<div> Locals attribute: inlineBar Locals option: optionBar test</div>`;
const actual = `<module href="./test/locals.option.spec.html" locals='{"inlineFoo": "inlineBar"}'>{{ optionFoo }}</module>`;
const expected = `<div> Locals attribute: inlineBar Locals option: optionBar optionBar</div>`;

const html = await posthtml().use(plugin({locals: {optionFoo: 'optionBar'}})).process(actual).then(result => clean(result.html));

Expand Down

0 comments on commit 2faf42c

Please sign in to comment.