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

Function extension documentation errors #538

Open
Bilge opened this issue Aug 29, 2021 · 0 comments
Open

Function extension documentation errors #538

Bilge opened this issue Aug 29, 2021 · 0 comments
Assignees

Comments

@Bilge
Copy link

Bilge commented Aug 29, 2021

There are a lot of errors in the extension documentation, surrounding use of custom functions (TwingFunction). For example:

If you want to access the current context in your filter, set the needs_context option to true. Twing will pass the current context as the first argument to the filter call (or the second one if needs_environment is also set to true):

let filter = new TwingFilter('rot13', function (env, context, string) {
    // ...
}, {needs_context: true, needs_environment: true});

Of course, I am citing the filter documentation even though I am using functions because there are only examples and explanations given for filters and we are lead to believe they both operate alike.

First of all, passing options to the third parameter will do nothing whatsoever because the third parameter is some undocumented feature called acceptedArguments of type TwingCallableArgument[]. Whilst we're on the topic of this weird parameter, it's also a required field, so if you're coding in TypeScript, it's an error not to specify it, even though we can have no idea what it does.

Second, if one wants the environment, one must actually pass needs_template because there is no option called needs_environment.

This is all very misleading and confusing and it's unclear what is a documentation error or what might be an implementation error.

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