Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-11-28 15:41:06 UTC using RuboCop version 1.81.7.
# on 2025-12-01 11:50:08 UTC using RuboCop version 1.81.7.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -9,34 +9,34 @@
# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 49
Max: 53

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 200
Max: 206

# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 17
Max: 18

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 31
Max: 35

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 19
Max: 21

# Offense count: 1
Naming/AccessorMethodName:
Exclude:
- 'lib/glug/layer.rb'

# Offense count: 1
# Offense count: 5
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 53
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ You create a layer like this:

The layer call begins with the layer id (`:water`) and then any additional layer-wide properties (source, source_layer, metadata, interactive). If no source is specified, the default will be used. If no source_layer is specified, the layer id will be used - so in this case, Glug would assume a source_layer of 'water'.

Zoom levels are always specified as Ruby ranges (`5..13`) rather than separate minzoom/maxzoom properties.
Zoom levels are always specified as Ruby ranges (`5..13`) rather than separate minzoom/maxzoom properties. "Beginless" and "Endless" ranges (e.g. `..5` or `13..`) are supported.

### Style definitions

Expand Down
8 changes: 6 additions & 2 deletions lib/glug/layer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,12 @@ def to_hash

# Convert zoom level
if (v = hash['zoom'])
hash['minzoom'] = v.is_a?(Range) ? v.first : v
hash['maxzoom'] = v.is_a?(Range) ? v.last : v
if v.is_a?(Range)
hash['minzoom'] = v.first unless v.begin.nil?
hash['maxzoom'] = v.last unless v.end.nil?
else
hash['minzoom'] = hash['maxzoom'] = v
end
hash.delete('zoom')
end

Expand Down
28 changes: 28 additions & 0 deletions spec/lib/glug/layer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,33 @@
expect(h['minzoom']).to be(1)
expect(h['maxzoom']).to be(5)
end

context 'with endless ranges' do
it 'does not set a max zoom' do
stylesheet = Glug::Stylesheet.new do
source :osm_data, type: 'vector', url: 'http://example.com/osm.tilejson', default: true
end
l = described_class.new(stylesheet, { zoom: 1.. })
l.line_width 1

h = l.to_hash
expect(h).to have_key('minzoom')
expect(h['minzoom']).to be(1)
expect(h).not_to have_key('maxzoom')
end

it 'does not set a min zoom' do
stylesheet = Glug::Stylesheet.new do
source :osm_data, type: 'vector', url: 'http://example.com/osm.tilejson', default: true
end
l = described_class.new(stylesheet, { zoom: ..5 })
l.line_width 1

h = l.to_hash
expect(h).not_to have_key('minzoom')
expect(h).to have_key('maxzoom')
expect(h['maxzoom']).to be(5)
end
end
end
end