Skip to content

allow delimeter specification #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2020

Conversation

deiay
Copy link
Contributor

@deiay deiay commented Oct 17, 2020

Posthtml-include uses posthtml-expressions to detect local variables passed into include blocks. The default variable syntax for posthtml-expressions is {{ my_variable }}. However, many JavaScript frameworks use {{ and }} as expression delimiters for their own uses which would clash with posthtml-expression's variable injection. posthtml-expressions allows for the configuartion of variable delimiters to solve this.

This change allows for the passing in of a delimiter option that will get passed to posthtml-expressions. This lets us change the delimter that's used for variables in out includes.

@deiay deiay marked this pull request as ready for review October 17, 2020 20:59
Copy link
Member

@Scrum Scrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi great suggestion, could you please make a few changes

lib/index.js Outdated
@@ -21,6 +21,7 @@ module.exports = (options = {}) => {
let subtree;
let source;
let locals = false;
const delimiters = options.delimiters || ['{{', '}}'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth creating a separate settings object for posthtml-expressions

const posthtmlExpressionsOptions = {
  locals: false
}

Pay attention to the locale, it will be necessary to override the used local variable locals to the link to the options object posthtmlExpressionsOptions.locals

if (options.delimiters) {
  posthtmlExpressionsOptions.delimiters = options.delimiters
}

so we will be sure that nothing will break if u posthtml-expressions the default value will change delimiters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Scrum updated. How does this look now?

@deiay deiay force-pushed the allow-delimiter-specification branch from 753454e to 4bcb79b Compare November 3, 2020 17:30
@Scrum Scrum merged commit 3ca8ec4 into posthtml:master Nov 5, 2020
@Scrum
Copy link
Member

Scrum commented Nov 5, 2020

@deiay publish v1.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants