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
end
However, 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
end
In 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.
This might just be a duplicate of #19 , feel free to close it if so.
Currently Glug supports defining constants, e.g.
However, using either
local_variablesor@class_variablesdoesn't work, e.g.In either case, the variable evaluates to nil, rather than 3.
The root cause appears to be that the whole stylesheet is evaluated in the context of a
Stylesheetinstance, but each layer is separately evaluated in its ownLayerinstance. 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.