Skip to content
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

Custom isFalsy definition #255

Closed
amit777 opened this issue Oct 6, 2020 · 4 comments
Closed

Custom isFalsy definition #255

amit777 opened this issue Oct 6, 2020 · 4 comments

Comments

@amit777
Copy link
Contributor

amit777 commented Oct 6, 2020

Hi! I would like isFalsy to match more closely with JavaScript's false definition. Would it be possible to add a feature to override the default isFalsy() definition as an option to the constructor?

@harttle
Copy link
Owner

harttle commented Oct 6, 2020

Not available now. I think an additional JSTrusy option is better cause I can't think of other cases.

@amit777
Copy link
Contributor Author

amit777 commented Oct 6, 2020

We are planning on using a Perl liquid template implementation that shares templates with nodejs. It also has a slightly different truthy implementation which is closer to JS. So I was hoping to normalize them both.

@amit777
Copy link
Contributor Author

amit777 commented Oct 6, 2020

My typescript knowledge is not so good, I was trying to figure out a way to pass the liquid options into boolean.ts isFalsy() function. Would you be able to provide a pointer? I can update docs, tests and code and create pull request after.

@harttle
Copy link
Owner

harttle commented Oct 7, 2020

A simple (direct) approach would be:

  • add an additional ctx: Context argument to src/render/boolean.ts#isTruthy(), and make use of ctx.opts.isTruthy.
  • pass the context to operatorImpls (then passes isTruthy()) to in src/render/expression.ts#evalOperatorToken()
  • similarly, pass contexts in src/builtin/filters/array.ts#where() and src/builtin/tags/if.ts#render()

That would be enough. Let me know if you get stuck.

harttle added a commit that referenced this issue Oct 8, 2020
harttle pushed a commit that referenced this issue Oct 8, 2020
# [9.16.0](v9.15.1...v9.16.0) (2020-10-08)

### Features

* support jsTruthy, [#255](#255) [#257](#257) ([72ee7b4](72ee7b4))
@harttle harttle closed this as completed Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants