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

Use TemplaceContext's MemberRenamer when importing built-in functions #59

Open
Tyrrrz opened this issue Jul 1, 2018 · 1 comment
Open

Comments

@Tyrrrz
Copy link
Contributor

Tyrrrz commented Jul 1, 2018

It would be nice if the default built-in functions would be aware of the TemplateContext.MemberRenamer. This would make it a bit more consistent.

@xoofx
Copy link
Member

xoofx commented Jul 4, 2018

Ideally, it would be nice, but in practice, it is quite cumbersome to do.The TemplateContext.MemberRenamer can be changed at any time, and it would require to check this and rebuild a new set of builtin functions. Also builtin functions are cached (only created once) so that they don't generate a new one everytime with create a new template context.
That being said, It is true that a ScriptObject doesn't take as a parameter a template renamer, so it is making all ScriptObject that are using auto-import of methods not usable with a different renamer (as this is the case for builtin functions)

So at least a first step to improve this situation would be to allow to propagate a MemberRenamer at ScriptObject constructor time, to pass it the the Import call here:

https://github.com/lunet-io/scriban/blob/d00574d4e2858f31cbc3891b394f8c5fb0d00a92/src/Scriban/Runtime/ScriptObject.cs#L49

And then add a new BuiltinFunctions constructor that could take a MemberRenamer and propagate it to the internal constructors (without using the internal DefaultBuiltins cache)

PR welcome (don't have enough spare time to work on this)

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