cartocss_helper 4.1.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d44210fbbf9317e53a5c01b2b91f9e121523995
4
- data.tar.gz: 5a4e1209c655ad3168da06877fb77a1baf0d6f39
3
+ metadata.gz: abeb68cede68758d9f0c8ef8ef4b85c192190d20
4
+ data.tar.gz: 9c6d087f808d57a21aa8330babedf98cbfce032a
5
5
  SHA512:
6
- metadata.gz: 282ff9198c3c1d46c75d0a2b2bc4afb3426e9e2e5f22c01a9a5d51d5ca261da19c8653979af15ef5b72e5fd09de8a56a3c2347716a6c5e261fea6644df9d5071
7
- data.tar.gz: 8fc86923dff9816152f56e1d4ba667a59e03f6bcdbe398904ae6f04406d3ce699b3a82c792be4698da35899d3203c970c2dd848495a80cea50e482161352ad1d
6
+ metadata.gz: ba4dcae451a8fa7d2ceff112a7c309a1cff302fc31bf38aa3323d79d62e13696d86be19a8f52f24af13ecc312a7fbf9d6bc908bd6af48e43bcb957439ebf5c30
7
+ data.tar.gz: 74a622f7cb5c73a6a95ff89f1c12ec02f86acbb14e83b057217e665cf020768ef4e266d5155a708f7786ba37ab64de228b3ab4f32ae2dfc93996cfb25a7c87a6
@@ -32,6 +32,17 @@ module CartoCSSHelper
32
32
  puts
33
33
  puts e
34
34
  raise OverpassRefusedResponse
35
+ rescue ExceptionWithResponse => e
36
+ if e.http_code == 400
37
+ puts "invalid query"
38
+ puts
39
+ puts query
40
+ puts
41
+ puts url
42
+ puts
43
+ puts e
44
+ end
45
+ raise e
35
46
  end
36
47
 
37
48
  def self.get_allowed_timeout_in_seconds
@@ -99,7 +99,7 @@ module CartoCSSHelper
99
99
  end
100
100
 
101
101
  def self.locate_element_with_given_tags_and_type(tags, type, latitude, longitude, max_range_in_km_for_radius = 1600)
102
- # special support for following tag values: :any_value
102
+ # special support for some tag values - see CartoCSSHelper::OverpassQueryGenerator.turn_list_of_tags_in_overpass_filter for details
103
103
  range = 10 * 1000
104
104
  while range <= max_range_in_km_for_radius * 1000
105
105
  list = OverpassQueryGenerator.get_elements_near_given_location(tags, type, latitude, longitude, range)
@@ -135,7 +135,7 @@ module CartoCSSHelper
135
135
  end
136
136
 
137
137
  def self.get_query_to_get_location_set_format(tags, type, latitude, longitude, range, format)
138
- # special support for following tag values: :any_value
138
+ # special support for some tag values - see CartoCSSHelper::OverpassQueryGenerator.turn_list_of_tags_in_overpass_filter for details
139
139
  locator = "[timeout:#{OverpassDownloader.get_allowed_timeout_in_seconds}]#{format};"
140
140
  locator += "\n"
141
141
  type = 'way' if type == 'closed_way'
@@ -157,20 +157,57 @@ module CartoCSSHelper
157
157
  end
158
158
 
159
159
  def self.turn_list_of_tags_in_overpass_filter(tags)
160
+ # special support for following tag values: :any_value, {operation: :not_equal_to, value: "tag"}
160
161
  element = ''
161
162
  tags.each do |tag|
162
- element += if tag[1] == :any_value
163
- "\t['#{tag[0]}']"
164
- else
165
- "\t['#{tag[0]}'='#{tag[1]}']"
166
- end
163
+ element += turn_tag_into_overpass_filter(tag)
167
164
  element += "\n"
168
165
  end
169
166
  return element
170
167
  end
171
168
 
169
+ def self.translate_tag_object_into_filter_data(tag)
170
+ operator = :equal
171
+ key = tag[0]
172
+ value = :any_value
173
+ if tag[1].class == Hash
174
+ # complex operation
175
+ if tag[1][:operation] == :not_equal_to
176
+ operator = :not_equal
177
+ else
178
+ raise "unexpected operation in #{tag[1]}"
179
+ end
180
+ value = tag[1][:value]
181
+ else
182
+ value = tag[1]
183
+ end
184
+ return {operator: operator, key: key, value: value}
185
+ end
186
+
187
+ def self.overpass_escape(text)
188
+ return text.gsub("\\", "\\\\\\").gsub("'", "\\\\'")
189
+ end
190
+
191
+ def self.turn_tag_into_overpass_filter(tag)
192
+ filter_data = translate_tag_object_into_filter_data(tag)
193
+ value = overpass_escape(filter_data[:value])
194
+ key = overpass_escape(filter_data[:key])
195
+ operator = filter_data[:operator]
196
+ if value == :any_value && operator == :equal
197
+ return "\t['#{key}']"
198
+ elsif value == :any_value && operator == :not_equal
199
+ return "\t['#{key}'!~'.*']"
200
+ elsif value != :any_value && operator == :equal
201
+ return "\t['#{key}'='#{value}']"
202
+ elsif value != :any_value && operator == :not_equal
203
+ return "\t['#{key}'!='#{value}']"
204
+ else
205
+ raise "unexpected situation in <#{tag}>"
206
+ end
207
+ end
208
+
172
209
  def self.get_query_element_to_get_location(tags, latitude, longitude, type, range)
173
- # special support for following tag values: :any_value
210
+ # special support for some tag values - see CartoCSSHelper::OverpassQueryGenerator.turn_list_of_tags_in_overpass_filter for details
174
211
  # TODO - escape value with quotation signs in them
175
212
  element = "(#{type}"
176
213
  element += OverpassQueryGenerator.turn_list_of_tags_in_overpass_filter(tags)
@@ -85,7 +85,9 @@ module CartoCSSHelper
85
85
 
86
86
  execute_rendering_command(command_to_execute, export_location, debug)
87
87
 
88
- puts "generated in #{(Time.now - start).to_i}s (#{Git.get_commit_hash})"
88
+ generation_time = (Time.now - start).to_i
89
+
90
+ puts "generated in #{generation_time}s (#{Git.get_commit_hash})"
89
91
  return export_location
90
92
  end
91
93
 
@@ -57,7 +57,11 @@ class GenericDownloader
57
57
  output_shared_error_part(url, e)
58
58
  Log.warn e.response
59
59
  Log.warn e.http_code
60
- get_specified_resource(url) if retry_allowed(e)
60
+ if retry_allowed(e)
61
+ get_specified_resource(url)
62
+ else
63
+ raise e
64
+ end
61
65
  rescue ExceptionWithoutResponse => e
62
66
  output_shared_error_part(url, e)
63
67
  raise e
@@ -10,12 +10,11 @@ class RestClientWrapper
10
10
  wait if url == @last_url_fetched
11
11
  @last_url_fetched = url
12
12
  return execute_fetch_data_from_url(url, request_timeout)
13
- # http://www.rubydoc.info/gems/rest-client/1.8.0/RestClient/Exception
14
13
  rescue RestClient::RequestTimeout => e
15
14
  raise RequestTimeout, e.to_s
16
15
  rescue RestClient::ExceptionWithResponse => e
17
16
  raise_exception_about_returned_response(e)
18
- rescue RestClient::MaxRedirectsReached, RestClient::SSLCertificateNotVerified, RestClient::ServerBrokeConnection, SocketError, URI::InvalidURIError
17
+ rescue RestClient::SSLCertificateNotVerified, RestClient::ServerBrokeConnection, SocketError, URI::InvalidURIError
19
18
  raise ExceptionWithoutResponse.new(e), e.to_s
20
19
  rescue ArgumentError => e
21
20
  raise_issue_359_exception(e)
@@ -130,7 +130,7 @@ module CartoCSSHelper
130
130
  end
131
131
 
132
132
  def self.visualise_on_overpass_data(tags, type, wanted_latitude, wanted_longitude, zlevels, new_branch, old_branch = 'master')
133
- # special support for following tag values: :any_value
133
+ # special support for some tag values - see CartoCSSHelper::OverpassQueryGenerator.turn_list_of_tags_in_overpass_filter for details
134
134
  header_prefix = "#{VisualDiff.tag_dict_to_string(tags)} #{type} [#{wanted_latitude}, #{wanted_longitude}] -> "
135
135
  target_location = '[?, ?]'
136
136
  header_sufix = " #{old_branch}->#{new_branch} #{zlevels}"
@@ -198,14 +198,7 @@ module CartoCSSHelper
198
198
  end
199
199
 
200
200
  def self.tag_dict_to_string(dict)
201
- result = ''
202
- dict.to_a.each do |tag|
203
- result << '; ' if result != ''
204
- value = "'#{tag[1]}'"
205
- value = '{any value}' if tag[1] == :any_value
206
- result << "#{tag[0]}=#{value}"
207
- end
208
- return result
201
+ return OverpassQueryGenerator.turn_list_of_tags_in_overpass_filter(dict)
209
202
  end
210
203
  end
211
204
  end
data/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- ##CartoCSS Helper
1
+ ## CartoCSS Helper
2
2
 
3
3
  It is a tool making development of CartoCSS styles more efficient. Allows to write simple Ruby scripts that generate comparison images of how rendering changed between two versions of map style. It is also possible to generate validation reports detecting for example too low values of text-dy. Loading data using osm2pgsql, rendering with TileMill, obtaining test data from overpass turbo.
4
4
 
@@ -12,7 +12,7 @@ It is work in progress, major problems that should be solved include:
12
12
  * Executing git checkout commands on map style git repository during normal script operation (https://github.com/matkoniecz/CartoCSSHelper/issues/9)
13
13
  * Current rendering method is obnoxiously slow. (https://github.com/matkoniecz/CartoCSSHelper/issues/1)
14
14
 
15
- ###Installation
15
+ ### Installation
16
16
 
17
17
  Assumes that osm2pgsql and TileMill are installed.
18
18
 
@@ -26,7 +26,7 @@ Unfortunately, standard `gem install cartocss_helper` may not be enough as Carto
26
26
  2. `gem install --user-install rmagick`
27
27
  3. `gem install --user-install cartocss_helper`.
28
28
 
29
- ###Examples
29
+ ### Examples
30
30
 
31
31
  It is assumed that CartoCSS project with Default OSM Style (https://github.com/gravitystorm/openstreetmap-carto/) is located at `~/Documents/MapBox/project/osm-carto`.
32
32
 
@@ -74,8 +74,15 @@ It is also possible to look for certain keys, with any value:
74
74
  tags = {'landuse' => 'village_green', 'tourism' => 'attraction', 'name' => :any_value}
75
75
  CartoCSSHelper.test tags, 'master', 'v2.28.1'
76
76
 
77
+ ### Tests
77
78
 
78
- ###Automated stuff
79
+ Tests are written using rspec. Use `rspec` command to run them.
80
+
81
+ ### Automated stuff
79
82
 
80
83
  [![Code Climate](https://codeclimate.com/github/matkoniecz/CartoCSSHelper/badges/gpa.svg)](https://codeclimate.com/github/matkoniecz/CartoCSSHelper)
81
- [![Build Status](https://travis-ci.org/matkoniecz/CartoCSSHelper.svg?branch=master)](https://travis-ci.org/matkoniecz/CartoCSSHelper)
84
+ [![Build Status](https://travis-ci.org/matkoniecz/CartoCSSHelper.svg?branch=master)](https://travis-ci.org/matkoniecz/CartoCSSHelper)
85
+
86
+ ### RubyGems link
87
+
88
+ [https://rubygems.org/gems/cartocss_helper](https://rubygems.org/gems/cartocss_helper)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cartocss_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Konieczny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-24 00:00:00.000000000 Z
11
+ date: 2018-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: '2.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
- version: '1.8'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sys-filesystem
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -73,73 +73,73 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '1.8'
75
75
  - !ruby/object:Gem::Dependency
76
- name: rubocop
76
+ name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '0.41'
82
- - - ">"
81
+ version: '3.4'
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: '0.41'
84
+ version: 3.4.0
85
85
  type: :development
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
- version: '0.41'
92
- - - ">"
91
+ version: '3.4'
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: '0.41'
94
+ version: 3.4.0
95
95
  - !ruby/object:Gem::Dependency
96
- name: rspec
96
+ name: rubocop
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: '3.4'
102
- - - ">="
101
+ version: '0.52'
102
+ - - ">"
103
103
  - !ruby/object:Gem::Version
104
- version: 3.4.0
104
+ version: 0.48.1
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '3.4'
112
- - - ">="
111
+ version: '0.52'
112
+ - - ">"
113
113
  - !ruby/object:Gem::Version
114
- version: 3.4.0
114
+ version: 0.48.1
115
115
  - !ruby/object:Gem::Dependency
116
- name: travis
116
+ name: simplecov
117
117
  requirement: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - "~>"
120
120
  - !ruby/object:Gem::Version
121
- version: '1.8'
121
+ version: '0.11'
122
122
  type: :development
123
123
  prerelease: false
124
124
  version_requirements: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - "~>"
127
127
  - !ruby/object:Gem::Version
128
- version: '1.8'
128
+ version: '0.11'
129
129
  - !ruby/object:Gem::Dependency
130
- name: simplecov
130
+ name: travis
131
131
  requirement: !ruby/object:Gem::Requirement
132
132
  requirements:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
- version: '0.11'
135
+ version: '1.8'
136
136
  type: :development
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
- version: '0.11'
142
+ version: '1.8'
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: codeclimate-test-reporter
145
145
  requirement: !ruby/object:Gem::Requirement