-
Notifications
You must be signed in to change notification settings - Fork 6
Description
This might just be a duplicate of #19 , feel free to close it if so.
Currently Glug supports defining constants, e.g.
FOO = 3
layer(:roads, source: :shortbread) do
line_width FOO
endHowever, using either local_variables or @class_variables doesn't work, e.g.
foo = 3
layer(:roads, source: :shortbread) do
line_width foo
end@foo = 3
layer(:roads, source: :shortbread) do
line_width @foo
endIn either case, the variable evaluates to nil, rather than 3.
- "paint":{"line-width":3},
+ "paint":{"line-width":null},The root cause appears to be that the whole stylesheet is evaluated in the context of a Stylesheet instance, but each layer is separately evaluated in its own Layer instance. This means that variables defined at the top level belong to the Stylesheet and aren't available within a layer. Constants have a global scope so are handled differently, and that's why they work.
I've watched the "Ruby ate my DSL" talk again, and I think there's a lot from that talk that's applicable here. It describes many of the issues I'm running into and there are several suggestions in that talk that we might want to try.