Skip to content

Commit 022714e

Browse files
committed
Ensure expressions assigned to ivars are stored as conditions
1 parent 3b73697 commit 022714e

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

lib/glug/stylesheet_dsl.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ def respond_to_missing?(*)
2626

2727
# Set a property, e.g. 'bearing 29'
2828
def method_missing(method_sym, *args)
29-
@__impl.add_property(method_sym, *args)
29+
if Layer::EXPRESSIONS.include?(method_sym)
30+
Condition.new.from_list(method_sym, args)
31+
else
32+
@__impl.add_property(method_sym, *args)
33+
end
3034
end
3135
end
3236
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version 8
2+
name 'Expression ivars test'
3+
source :shortbread, type: 'vector', url: 'https://vector.openstreetmap.org/shortbread_v1/tilejson.json'
4+
5+
# Expression assigned to ivar at stylesheet level
6+
@my_halo = rgba(255, 255, 255, 0.8)
7+
@my_color = rgb(100, 200, 50)
8+
9+
layer(:labels, zoom: 5.., source: :shortbread) do
10+
text_halo_color @my_halo
11+
text_color @my_color
12+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"version":8,
3+
"name":"Expression ivars test",
4+
"sources":{
5+
"shortbread":{
6+
"type":"vector",
7+
"url":"https://vector.openstreetmap.org/shortbread_v1/tilejson.json"
8+
}
9+
},
10+
"layers":[
11+
{
12+
"paint":{
13+
"text-halo-color":["rgba",255,255,255,0.8],
14+
"text-color":["rgb",100,200,50]
15+
},
16+
"source":"shortbread",
17+
"id":"labels",
18+
"source-layer":"labels",
19+
"type":"symbol",
20+
"minzoom":5
21+
}
22+
]
23+
}

spec/lib/glug/stylesheet_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,14 @@
104104
output = File.read(File.join(fixture_dir, 'ivars_with_include.json'))
105105
expect(stylesheet.to_json).to eql(output.strip)
106106
end
107+
108+
it 'stores expressions in ivars at stylesheet level' do
109+
glug = File.read(File.join(fixture_dir, 'expression_ivars.glug'))
110+
stylesheet = described_class.new(base_dir: fixture_dir) do
111+
instance_eval(glug)
112+
end
113+
output = File.read(File.join(fixture_dir, 'expression_ivars.json'))
114+
expect(stylesheet.to_json).to eql(output.strip)
115+
end
107116
end
108117
end

0 commit comments

Comments
 (0)