glug 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/glug.rb +19 -8
  3. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58209224a893c7908aec8ff0b9f9c85211353842
4
- data.tar.gz: 5b75fb0f41c1276914b0bddd27569be07c352002
3
+ metadata.gz: 021d7f8ef27d817a09761e33a6768f58f8d94848
4
+ data.tar.gz: ae6f46a63cc86c955683f64f44118e50efc28845
5
5
  SHA512:
6
- metadata.gz: f3368acdea157ec8e53f69f9361d185d44dc35f97f3bf8ecd1e0edad04ddf16fb491429341cb4045beaaaacfa3a2547334a04704a6c0729608fd2c2746d13a7b
7
- data.tar.gz: 1fbf8f7471e5a029400b8bc0239ccec3d2599867f8844203ea0d85b502299a929dc97ed8758e3e4382c96d9ca066b483f8bf230528837bc6bbae3911ff8d7db9
6
+ metadata.gz: '039967c1194fabd0c105c3f4eb2e328ffb4589d7fda079037d109338aac9b09ebee55db91ba9b4a5421f45aab7aaa20aa7acc51e4868a79860925be964bb0ce7'
7
+ data.tar.gz: 89e4ec1f4a0dd64cd3186f4e911e24088c9104623df83483b180c7987fe21fe76f7084dfaadf71783bf70a2d2b9c4239976f3e5b69b49d1f2b343081bcc3b48e
@@ -93,7 +93,7 @@ module Glug # :nodoc:
93
93
  def to_hash
94
94
  out = @kv.dup
95
95
  out['sources'] = @sources
96
- out['layers'] = @layers.select { |r| r.write? }.collect { |r| r.to_hash }
96
+ out['layers'] = @layers.select { |r| r.write? }.collect { |r| r.to_hash }.compact
97
97
  out
98
98
  end
99
99
  def to_json(*args); JSON.neat_generate(to_hash) end
@@ -119,7 +119,7 @@ module Glug # :nodoc:
119
119
  def <=(*args); Condition.new.from_key(:<=,@k,args) end
120
120
  def >=(*args); Condition.new.from_key(:>=,@k,args) end
121
121
  def in(*args); Condition.new.from_key(:in,@k,args) end
122
- def not_in(*args); Condition.new.from_key(:not_in,@k,args) end
122
+ def not_in(*args); Condition.new.from_key('!in',@k,args) end
123
123
  end
124
124
 
125
125
  # ----- Layer
@@ -195,9 +195,9 @@ module Glug # :nodoc:
195
195
  sub_cond = @condition # just inherit parent layer's condition
196
196
  else
197
197
  sub_cond = (args.length==1) ? args[0] : Condition.new.from_list(:any,args)
198
- sub_cond = sub_cond & @condition
198
+ sub_cond = nilsafe_merge(sub_cond, @condition)
199
199
  end
200
- r._set_filter(sub_cond & @uncascaded)
200
+ r._set_filter(nilsafe_merge(sub_cond, @uncascaded))
201
201
  r.instance_eval(&block)
202
202
  @stylesheet._add_layer(r)
203
203
 
@@ -206,13 +206,23 @@ module Glug # :nodoc:
206
206
  @cascades.each do |c|
207
207
  c_cond, c_kv = c
208
208
  l = Layer.new(@stylesheet, :id=>"#{r.kv[:id]}__#{child_chr}", :kv=>r.kv.dup)
209
- l._set_filter(sub_cond & c_cond)
209
+ l._set_filter(nilsafe_merge(sub_cond, c_cond))
210
210
  l.kv.merge!(c_kv)
211
211
  @stylesheet._add_layer(l)
212
212
  child_chr.next!
213
213
  end
214
214
  end
215
215
 
216
+ # Short-form key constructor - for reserved words
217
+ def tag(k)
218
+ OSMKey.new(k)
219
+ end
220
+
221
+ # Nil-safe merge
222
+ def nilsafe_merge(a,b)
223
+ a.nil? ? b : (a & b)
224
+ end
225
+
216
226
  # Add a cascading condition
217
227
  def cascade(*args, &block)
218
228
  cond = (args.length==1) ? args[0] : Condition.new.from_list(:any,args)
@@ -241,7 +251,7 @@ module Glug # :nodoc:
241
251
  _set_filter(args.length==1 ? args[0] : Condition.new.from_list(:any,args))
242
252
  end
243
253
  def _set_filter(condition)
244
- @condition = condition.dup
254
+ @condition = condition.nil? ? nil : condition.dup
245
255
  end
246
256
 
247
257
  # Set layer name
@@ -291,7 +301,7 @@ module Glug # :nodoc:
291
301
  hash['type'] = @type
292
302
  if @condition then hash['filter'] = @condition.encode end
293
303
 
294
- # Convert zoom level
304
+ # Convert zoom level
295
305
  if (v=hash['zoom'])
296
306
  hash['minzoom'] = v.is_a?(Range) ? v.first : v
297
307
  hash['maxzoom'] = v.is_a?(Range) ? v.last : v
@@ -306,7 +316,8 @@ module Glug # :nodoc:
306
316
  else
307
317
  stylesheet.refs[mk] = hash['id']
308
318
  end
309
- hash
319
+
320
+ hash[:layout].empty? && hash[:paint].empty? ? nil : hash
310
321
  end
311
322
 
312
323
  # Key to identify matching layer properties (slow but...)
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Fairhurst
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-06 00:00:00.000000000 Z
11
+ date: 2018-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neatjson
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: Text-based markup for Mapbox GL styles
@@ -31,8 +31,8 @@ executables:
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - lib/glug.rb
35
34
  - bin/glug
35
+ - lib/glug.rb
36
36
  homepage: http://github.com/systemed/glug
37
37
  licenses:
38
38
  - FTWPL
@@ -43,17 +43,17 @@ require_paths:
43
43
  - lib
44
44
  required_ruby_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 2.0.14
56
+ rubygems_version: 2.6.13
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: Glug