leaflet_helper 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/leaflet_helper.gemspec +1 -1
- data/lib/leaflet_helper.rb +1 -0
- data/lib/leaflet_helper/manage_markers.rb +51 -3
- data/lib/leaflet_helper/string_template.rb +20 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff792cd61366c579ade93b826b7fc0102747b683
|
4
|
+
data.tar.gz: 5a0752f2db7fb3c7e54185f2c6a260a6ac3b731e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd17fda3735424b865e735903708c2fa5149221927fdc151bce5da526b1e49e5658cda1211f10a0c97811b525f4a83033cde7688c5af87d6930e01fc8f6e8b73
|
7
|
+
data.tar.gz: 84aaec46fac3bf5d900255a9cf887f0e2e943fb14c6130ee70d27fd4bab3a78ed3e63853bd1dd83bd115e42e10562f4a9d2e31ee215a639cbc38d8c0ffacdbdd
|
data/README.md
CHANGED
@@ -9,7 +9,21 @@ do this:
|
|
9
9
|
```
|
10
10
|
|
11
11
|
The `cd` to the root directory of the gem. There you will find a subdirectory named `example` in
|
12
|
-
which there is a simple Sinatra-based web application that
|
12
|
+
which there is a simple Sinatra-based web application that demonstrates how to use this gem.
|
13
|
+
|
14
|
+
## Recent Changes
|
15
|
+
|
16
|
+
### v0.0.7
|
17
|
+
|
18
|
+
* Added StringTemplate class
|
19
|
+
Reused the regex from @redpist easy_template gem
|
20
|
+
|
21
|
+
* Fixed typo in ManageMarkers#remove - fat fingered a p[ when all I wanted was a [
|
22
|
+
|
23
|
+
### v0.0.6 - released
|
24
|
+
|
25
|
+
* Added ManageMarkers class
|
26
|
+
A singleton class that manages an array of hash markers to be applied on top of a map
|
13
27
|
|
14
28
|
## Installation
|
15
29
|
|
data/leaflet_helper.gemspec
CHANGED
data/lib/leaflet_helper.rb
CHANGED
@@ -18,12 +18,12 @@ module LeafletHelper
|
|
18
18
|
# a marker consists of an identification (not unique),
|
19
19
|
# a location expressed as decimal latitude longitude and
|
20
20
|
# an html component.
|
21
|
-
def add(id:, lat:, lon:, html: '
|
21
|
+
def add(id:, lat:, lon:, html: '<p>Anything with {variable} markers to be replaced by data contents.</p>', data:{})
|
22
22
|
@markers << {
|
23
23
|
id: id,
|
24
24
|
lat: lat,
|
25
25
|
lon: lon,
|
26
|
-
html: html
|
26
|
+
html: data.empty? ? html : StringTemplate.new(html).use(data)
|
27
27
|
}
|
28
28
|
end
|
29
29
|
alias :insert :add
|
@@ -35,7 +35,7 @@ module LeafletHelper
|
|
35
35
|
def remove(id)
|
36
36
|
return() if @markers.empty?
|
37
37
|
@markers.each_index do |x|
|
38
|
-
@
|
38
|
+
@markers[x] = nil if id == @markers[x][:id]
|
39
39
|
end
|
40
40
|
@markers.compact!
|
41
41
|
end
|
@@ -44,6 +44,21 @@ module LeafletHelper
|
|
44
44
|
alias :pull :remove
|
45
45
|
|
46
46
|
|
47
|
+
# Replace the html string's variables with values from a hash
|
48
|
+
def replace_with(id, a_hash)
|
49
|
+
return() if @markers.empty?
|
50
|
+
@markers.each_index do |x|
|
51
|
+
if :all == id || id == @markers[x][:id]
|
52
|
+
@markers[x][:html] = StringTemplate.new(@markers[x][:html]).use(a_hash)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def replace_all_with(a_hash)
|
58
|
+
replace_with(:all, a_hash)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
47
62
|
# Clear out the array so we can start over
|
48
63
|
def clear
|
49
64
|
@markers = Array.new
|
@@ -63,6 +78,8 @@ end # module LeafletHelper
|
|
63
78
|
|
64
79
|
__END__
|
65
80
|
|
81
|
+
# TODO: move some of this into the example sinatra app
|
82
|
+
|
66
83
|
Example: One Map
|
67
84
|
|
68
85
|
my_map = LeafletHelper::ManageMarkers.new
|
@@ -100,3 +117,34 @@ markers['map2'].add id: 'Secret Place',
|
|
100
117
|
<img src='ufo.png'>
|
101
118
|
<p>For Sale <em>Low Mileage</em>, owner is modivated. Must see to appriciate! Come by after sunset; beware of guards!</p>
|
102
119
|
EOS
|
120
|
+
|
121
|
+
Example: Using StringTemplate woth one map
|
122
|
+
|
123
|
+
my_map = LeafletHelper::ManageMarkers.new
|
124
|
+
|
125
|
+
# You can setup a complex string template
|
126
|
+
template = <<~EOS
|
127
|
+
<h3>{title}</h3>
|
128
|
+
<em>{classification}<em>
|
129
|
+
<img src="{thumbnail}">
|
130
|
+
<a href="http://{image}"">Show Full Image</a>
|
131
|
+
{comments}
|
132
|
+
EOS
|
133
|
+
|
134
|
+
# Then use a hash to populate the template with data
|
135
|
+
data = {
|
136
|
+
title: 'Actual Flying Saucer Crash Remains',
|
137
|
+
classification: "Above TS; Q; TK; SAP: MJ12; NTK: not you; NOFORN; SCI: Silliness",
|
138
|
+
thumbnail: "images/p123_150x150.png",
|
139
|
+
image: "images/p123.png"
|
140
|
+
}
|
141
|
+
|
142
|
+
my_map.add id: 'Secret Place',
|
143
|
+
lat: AREA51.latitude,
|
144
|
+
lon: AREA51.longitude,
|
145
|
+
html: template,
|
146
|
+
data: data
|
147
|
+
|
148
|
+
my_map.replace_all_with {comments: "<em>You never saw this. I was never here.</em>"}
|
149
|
+
|
150
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# string_template.rb
|
2
|
+
# this class resulted in pull_requests to the easy_template gem
|
3
|
+
# Merci to Jeremy Lecerf @redpist for the regex
|
4
|
+
|
5
|
+
module LeafletHelper
|
6
|
+
class StringTemplate
|
7
|
+
def initialize(a_string)
|
8
|
+
@text = a_string
|
9
|
+
end
|
10
|
+
|
11
|
+
def use(variables)
|
12
|
+
@text.gsub(/(\\\{)|((?<!\\)(?:\\\\)*#{variables.map{|v|"\\{#{Regexp.escape(v[0])}\\}"}.join('|')})/i){|s| s[0] == '\\' ? s[1] : variables.fetch(s[1..-2], ( s[1..-2].respond_to?(:to_sym) ? variables.fetch(s[1..-2].to_sym, nil) : nil))}
|
13
|
+
end
|
14
|
+
alias :<< :use
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
@text
|
18
|
+
end
|
19
|
+
end # class StringTemplate
|
20
|
+
end # LeafletHelper
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leaflet_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dewayne VanHoozer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- leaflet_helper.gemspec
|
79
79
|
- lib/leaflet_helper.rb
|
80
80
|
- lib/leaflet_helper/manage_markers.rb
|
81
|
+
- lib/leaflet_helper/string_template.rb
|
81
82
|
homepage: http://github.com/MadBomber/leaflet_helper
|
82
83
|
licenses:
|
83
84
|
- You want it? Its yours!
|