jekyll-maps 1.0.0 → 1.0.1

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: c572c2073327ace5f9a595bbdf0564385d897c9b
4
- data.tar.gz: beeab2b6dbcb0b717da716202219b93a7df4ccd0
3
+ metadata.gz: 2b00622803d1ea55c166f6dd5a7eb8603092d07f
4
+ data.tar.gz: 8faf047b0c0b139ca3141f6e1d8f596b70ce9575
5
5
  SHA512:
6
- metadata.gz: 139ed76a5fbf7c4a55763044e1af59b7d7ad00acd0ea58366c73a872ab815f84a814f50095d3a7d1eacbfbb19816c35cb928c9fc9c7cdb9aad5eebf3bd8d966a
7
- data.tar.gz: b27288cfa501f18a0a305a343b79dba18c49e9d93b8fd7e3944fcb82aeeed77e4056f92adec7f8c74f2a041101b18aeaaa3592fe54a91c73d343d83d3e330e69
6
+ metadata.gz: f7bd47ce22e43f4a26b5659295164f4900fd2ad7bef769838f231991fdd4fade909531cb8a5d9ce60e31461a8d6afdc5bb03f45b0ddacdda3f23280b62bf0990
7
+ data.tar.gz: a5f32d206c1a08008a6145ddfcf35d60a0721c4dd9367a0df68ee70655a5709f85ffa9dc5a11104617a9521b40b963e215023723ada79c2ddfd894460a760529
data/README.md CHANGED
@@ -1,2 +1,2 @@
1
- # jekyll-google-maps
1
+ # jekyll-maps
2
2
  Google Maps support in Jekyll blog to easily embed maps with posts' locations
@@ -0,0 +1,58 @@
1
+ <div id='google-map'></div>
2
+
3
+ <script type='text/javascript'>
4
+ var jekyllMaps = (function () {
5
+ 'use strict';
6
+
7
+ return {
8
+ loadScript: function (url) {
9
+ var script = document.createElement('script');
10
+ script.type = 'text/javascript';
11
+ script.src = url;
12
+ document.body.appendChild(script);
13
+ },
14
+ initialize: function () {
15
+ this.options = {
16
+ center: new google.maps.LatLng(0, 0),
17
+ mapTypeId: google.maps.MapTypeId.ROADMAP,
18
+ zoom: 3
19
+ }
20
+ this.map = new google.maps.Map(document.getElementById('google-map'), this.options);
21
+ this.showMarkers({{ locations }});
22
+ },
23
+ showMarkers: function (locations) {
24
+ var map = this.map,
25
+ bounds = new google.maps.LatLngBounds(),
26
+ markers = locations.map(function (location) {
27
+ var position = new google.maps.LatLng(location.latitude, location.longitude);
28
+ var marker = new google.maps.Marker({
29
+ position: position,
30
+ map: map,
31
+ title: location.title,
32
+ url: location.url
33
+ });
34
+
35
+ marker.addListener('click', function () {
36
+ if (this.url) {
37
+ window.location.href = this.url;
38
+ }
39
+ });
40
+ bounds.extend(position);
41
+
42
+ return marker;
43
+ });
44
+
45
+ new MarkerClusterer(map, markers, {
46
+ gridSize: 25,
47
+ imagePath: 'https://raw.githubusercontent.com/googlemaps/js-marker-clusterer/gh-pages/images/m'
48
+ });
49
+ map.fitBounds(bounds);
50
+ },
51
+ };
52
+ }());
53
+
54
+ window.onload = function () {
55
+ jekyllMaps.loadScript('https://googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js');
56
+ jekyllMaps.loadScript('http://maps.googleapis.com/maps/api/js?callback=jekyllMaps.initialize');
57
+ };
58
+ </script>
@@ -1,11 +1,64 @@
1
1
  module Jekyll
2
2
  module Maps
3
3
  class GoogleMapTag < Liquid::Tag
4
- def initialize(_tag_name, text, _tokens)
4
+ attr_accessor :context
5
+
6
+ def initialize(_, args, _)
7
+ unless args.empty?
8
+ @filter_key = args.split(":").first.strip
9
+ @filter_value = args.split(":").last.strip
10
+ end
11
+
5
12
  super
6
13
  end
7
14
 
8
- def render(_context)
15
+ def render(context)
16
+ @context = context
17
+ template.render!({ "locations" => locations.to_json })
18
+ end
19
+
20
+ private
21
+ def locations
22
+ filter_posts.map do |post|
23
+ {
24
+ :latitude => post["location"]["latitude"],
25
+ :longitude => post["location"]["longitude"],
26
+ :title => post["title"],
27
+ :url => post.url
28
+ }
29
+ end
30
+ end
31
+
32
+ def filter_posts
33
+ posts = context.registers[:site].posts.docs.reject do |post|
34
+ post["location"].nil? || post["location"].empty?
35
+ end
36
+ if @filter_key
37
+ posts.reject do |post|
38
+ post[@filter_key].nil? || post[@filter_key] != @filter_value
39
+ end
40
+ else
41
+ posts
42
+ end
43
+ end
44
+
45
+ private
46
+ def template
47
+ @template ||= Liquid::Template.parse template_contents
48
+ end
49
+
50
+ private
51
+ def template_contents
52
+ @template_contents ||= begin
53
+ File.read(template_path)
54
+ end
55
+ end
56
+
57
+ private
58
+ def template_path
59
+ @template_path ||= begin
60
+ File.expand_path "./google_map.html", File.dirname(__FILE__)
61
+ end
9
62
  end
10
63
  end
11
64
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Maps
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "1.0.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoliy Yastreb
@@ -81,6 +81,7 @@ files:
81
81
  - Rakefile
82
82
  - jekyll-maps.gemspec
83
83
  - lib/jekyll-maps.rb
84
+ - lib/jekyll-maps/google_map.html
84
85
  - lib/jekyll-maps/google_map_tag.rb
85
86
  - lib/jekyll-maps/version.rb
86
87
  - script/bootstrap