-
Notifications
You must be signed in to change notification settings - Fork 464
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
Pass the compiler to custom functions instead of the options. #1227
Pass the compiler to custom functions instead of the options. #1227
Conversation
Thanks for the suggestion @tristanlins. This probably affects @chriseppstein and @drewwells the most. Would also like your feels here @mgreter. |
While testing this, I find out that this wont work. |
@tristanlins is a dead end then? Should this issue be closed? |
Probably we should identify the state of the executor vs compiler's state. We should be able to provide a stable interface to the custom function implementors (for example, I'd like to have it serializable #1108). Even if some reflective functions should be made available ( e.g. #1065 ) we may need to provide a stable interface there as well. Not only custom functions are affected - probably having the same interface for the built-ins would be beneficial as well. |
Maybe detailing what use cases this solves would help illuminate why this is necessary. I'm a big believer in only exposing the amount of information needed to extensions to keep them sane. For instance, I do not need to keep track of where I am in the import stack and I don't see a reason custom functions would need that information. The best use case for that is throwing coherent errors. If a custom function returns an error |
We need this information because we need to calculate relative paths. Not from the file itself, but from the context the file is defined in. And to know the context, we need to know which file calls the function. |
Perhaps there's an alternative way of doing this. https://github.com/wellington/wellington#functions supports all the compass image operations. Just like Compass, file i/o calls like It's not entirely clear to me if this level of context information is available to custom functions in Ruby Sass http://sass-lang.com/documentation/Sass/Script/Functions/EvaluationContext.html. It looks like you may able to derive the current template from the http://sass-lang.com/documentation/Sass/Engine.html options passed via the Environment to a Ruby Custom Function. However, storing files relative to sass is not something I see often. Web projects, especially as they grow, organize similar resources into distinct directories ie. images/, fonts/, or node_modules/eye-glass-module/. Thoughts? |
Here's a couple of use cases:
|
I see that lots of use cases revolve around mapping "import-identifier" to "actual-imported-resource" So, in general, what is needed is an array of:
or
mappings? Second question: What about introducing a way to specify such mapping upfront to libsass, something like:
This might actually reduce the need for custom importers - as those records could be added dynamically upfront before rendering. |
This PR add specs for sass/libsass#1227
Closing this. We are moving in the direction to have more context information available on the C-API. But we need to take step by step. We already have other open issues regarding similar issues, so this PR serve no real use anymore. Exposing the import context is probably one of the next things to do ... |
For me it makes a lot more sense to pass the compiler to custom functions, so how is it done also in imports.
With the compiler I can not only access the options, I can access the context and the import stack.
Especially the import stack is very interesting, e.g. when you need to generate relative URLs in a custom function.