aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Rataj <lidel@lidel.org>2014-11-13 00:08:07 +0100
committerMarcin Rataj <lidel@lidel.org>2014-11-13 00:08:07 +0100
commite7f0b30651f64343f9d358a1916f57e5a52d7ba8 (patch)
tree8feec7ef9bf39ceeab456f675525f01d301db318
parent4be377701b5ac2a10a273f3d5eb7a4f41b7de9ec (diff)
downloaddiscourse-umap-e7f0b30651f64343f9d358a1916f57e5a52d7ba8.tar.gz
Code cleanup
-rw-r--r--plugin.rb33
1 files changed, 14 insertions, 19 deletions
diff --git a/plugin.rb b/plugin.rb
index 2185a0b..57d3374 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -12,30 +12,25 @@ class Onebox::Engine::OpenStreetMapOnebox
@@width = 425
@@height = 350
@@tile_size = 256
-
+ @@REGEX = /^https?:\/\/(?:www\.)openstreetmap\.org\/.*#map=([\d\.]+)\/([-\d\.]+)\/([-\d\.]+)/
# enable oneboxing permalinks (http://wiki.openstreetmap.org/wiki/Permalink) into iframes
- matches_regexp(/^https?:\/\/(?:www\.)openstreetmap\.org/)
+ matches_regexp(@@REGEX)
def to_html
- if match = @url.match(/#map=([\d\.]+)\/([-\d\.]+)\/([-\d\.]+)/)
- zoom, lat, lon = match.captures
- iframe_url = "//www.openstreetmap.org/export/embed.html?bbox=#{get_bbox(lat.to_f, lon.to_f, zoom.to_i)}"
-
- if marker = @url.match(/mlat=([-\d\.]+).+mlon=([-\d\.]+)/)
- mlat, mlon = marker.captures
- iframe_url = "#{iframe_url}&amp;marker=#{mlat}%2C#{mlon}"
- end
-
- if layers = @url.match(/layers=(\w+)/)
- iframe_url = "#{iframe_url}&amp;layers=#{layers.captures[0]}"
- end
-
- "<iframe src='#{iframe_url}' style='border: 0' width='#{@@width}' height='#{@@height}' frameborder='0' scrolling='no'></iframe>"
- else
- #"NOPE" #@url
- @url
+ zoom, lat, lon = @url.match(@@REGEX).captures
+ iframe_url = "//www.openstreetmap.org/export/embed.html?bbox=#{get_bbox(lat.to_f, lon.to_f, zoom.to_i)}"
+
+ if marker = @url.match(/mlat=([-\d\.]+).+mlon=([-\d\.]+)/)
+ mlat, mlon = marker.captures
+ iframe_url = "#{iframe_url}&amp;marker=#{mlat}%2C#{mlon}"
end
+
+ if layers = @url.match(/layers=(\w+)/)
+ iframe_url = "#{iframe_url}&amp;layers=#{layers.captures[0]}"
+ end
+
+ "<iframe src='#{iframe_url}' style='border: 0' width='#{@@width}' height='#{@@height}' frameborder='0' scrolling='no'></iframe>"
end
private