Support using ivars in stylesheets #38
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Note: this is built on top of #37 and that should be handled first. The diff shown here currently includes those changes).
This allows you to define and use instance variables in both the stylesheet context and also within layers. They operate as if the
glug files were all part of one large ruby class.
This is similar behaviour to "@" variables in LESS, so will feel familiar to anyone coming from a CartoCSS background.
The tests show how it works, but here's a copy of the example stylesheet to give you a good idea:
The main complexity here is that although ruby allows you to get and set instance variables programmatically, there's no hook for intercepting code that's trying to do so with "@foo = bar" statements, like you would find in the stylesheet. Or in other works, there's no equivalent of
method_missingbut for ivars. Instead, we shuffle the ivars back and forward between the LayerDSL and StylesheetDSL, as each layer is evaluated. Slightly clunky but it works.Feedback welcome!