jekyll-maps 1.0.1 → 1.0.2

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: 2b00622803d1ea55c166f6dd5a7eb8603092d07f
4
- data.tar.gz: 8faf047b0c0b139ca3141f6e1d8f596b70ce9575
3
+ metadata.gz: 1d991367839c14b8f67ff64821219fc0ebcf9290
4
+ data.tar.gz: ab2ab30d54e9f1ed120f377f0350cc53d5f52d12
5
5
  SHA512:
6
- metadata.gz: f7bd47ce22e43f4a26b5659295164f4900fd2ad7bef769838f231991fdd4fade909531cb8a5d9ce60e31461a8d6afdc5bb03f45b0ddacdda3f23280b62bf0990
7
- data.tar.gz: a5f32d206c1a08008a6145ddfcf35d60a0721c4dd9367a0df68ee70655a5709f85ffa9dc5a11104617a9521b40b963e215023723ada79c2ddfd894460a760529
6
+ metadata.gz: 34ee237acea3325e5c7fa62defb1f41b829586bafa05135c917cd54e8ab085fe98fdf177cd1f1299b8467843777c24662ad841331cabe119e94371310538ec62
7
+ data.tar.gz: e31ce264d925ae834ae80e0ae9fb2e0b8b1cee5ab15cf94bd1a38c0e4d0b074521aa2f3095c1f1cb619304c470d52b206df9317ae8377ad831fa8a5ecf1a4bfb
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  tmp
5
5
  spec/dest
6
+ coverage
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.2
5
+ - 2.1
6
+ - 2.0
7
+ script: script/cibuild
8
+ sudo: false
9
+ cache: bundler
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/History.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 1.0.2 / 2016-07-18
2
+
3
+ * fix script loading
4
+ * look for location coordinates in all collections
5
+
6
+ ## 1.0.1 / 2016-07-17
7
+
8
+ * implement Google Maps tag
data/README.md CHANGED
@@ -1,2 +1,8 @@
1
- # jekyll-maps
1
+ # Jekyll Maps
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jekyll-maps.svg)](https://badge.fury.io/rb/jekyll-maps)
4
+ [![Build Status](https://travis-ci.org/ayastreb/jekyll-maps.svg?branch=master)](https://travis-ci.org/ayastreb/jekyll-maps)
5
+ [![Code Climate](https://codeclimate.com/github/ayastreb/jekyll-maps/badges/gpa.svg)](https://codeclimate.com/github/ayastreb/jekyll-maps)
6
+ [![Test Coverage](https://codeclimate.com/github/ayastreb/jekyll-maps/badges/coverage.svg)](https://codeclimate.com/github/ayastreb/jekyll-maps/coverage)
7
+
2
8
  Google Maps support in Jekyll blog to easily embed maps with posts' locations
data/lib/jekyll-maps.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "jekyll-maps/google_map_tag"
2
+ require "jekyll-maps/location_finder"
3
+ require "jekyll-maps/options_parser"
2
4
  require "jekyll-maps/version"
3
5
 
4
6
  module Jekyll
@@ -27,15 +27,13 @@
27
27
  var position = new google.maps.LatLng(location.latitude, location.longitude);
28
28
  var marker = new google.maps.Marker({
29
29
  position: position,
30
- map: map,
31
- title: location.title,
32
- url: location.url
30
+ title: location.title,
31
+ url: location.url,
32
+ map: map
33
33
  });
34
34
 
35
35
  marker.addListener('click', function () {
36
- if (this.url) {
37
- window.location.href = this.url;
38
- }
36
+ window.location.href = this.url
39
37
  });
40
38
  bounds.extend(position);
41
39
 
@@ -50,9 +48,6 @@
50
48
  },
51
49
  };
52
50
  }());
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
51
  </script>
52
+ <script src='https://googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js'></script>
53
+ <script src='https://maps.googleapis.com/maps/api/js?callback=jekyllMaps.initialize'></script>
@@ -1,50 +1,21 @@
1
1
  module Jekyll
2
2
  module Maps
3
3
  class GoogleMapTag < Liquid::Tag
4
- attr_accessor :context
5
-
6
4
  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
+ options = OptionsParser.parse(args)
6
+ @finder = LocationFinder.new(options)
12
7
  super
13
8
  end
14
9
 
15
10
  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
11
+ template.render!({
12
+ "locations" => @finder.find(context.registers[:site]).to_json
13
+ })
43
14
  end
44
15
 
45
16
  private
46
17
  def template
47
- @template ||= Liquid::Template.parse template_contents
18
+ @template ||= Liquid::Template.parse(template_contents)
48
19
  end
49
20
 
50
21
  private
@@ -57,7 +28,7 @@ module Jekyll
57
28
  private
58
29
  def template_path
59
30
  @template_path ||= begin
60
- File.expand_path "./google_map.html", File.dirname(__FILE__)
31
+ File.expand_path("./google_map.html", File.dirname(__FILE__))
61
32
  end
62
33
  end
63
34
  end
@@ -0,0 +1,43 @@
1
+ module Jekyll
2
+ module Maps
3
+ class LocationFinder
4
+ def initialize(options)
5
+ @options = options
6
+ end
7
+
8
+ def find(site)
9
+ matching_documents(site).map do |document|
10
+ {
11
+ :latitude => document["location"]["latitude"],
12
+ :longitude => document["location"]["longitude"],
13
+ :title => document["title"],
14
+ :url => document.url
15
+ }
16
+ end
17
+ end
18
+
19
+ private
20
+ def matching_documents(site)
21
+ documents = []
22
+ site.collections.each do |_, collection|
23
+ collection.docs.each do |doc|
24
+ documents << doc if location?(doc) && match_filters?(doc)
25
+ end
26
+ end
27
+ documents
28
+ end
29
+
30
+ private
31
+ def location?(doc)
32
+ !doc["location"].nil? && !doc["location"].empty?
33
+ end
34
+
35
+ private
36
+ def match_filters?(doc)
37
+ @options[:filters].each do |key, value|
38
+ return false if doc[key].nil? || doc[key] != value
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,18 @@
1
+ module Jekyll
2
+ module Maps
3
+ class OptionsParser
4
+ class << self
5
+ def parse(raw_options)
6
+ options = { :filters => {} }
7
+ raw_options.strip.split(" ").each do |pair|
8
+ key = pair.split(":").first.strip
9
+ value = pair.split(":").last.strip
10
+ value = value.split(",") if value.include?(",")
11
+ options[:filters][key] = value
12
+ end
13
+ options
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Maps
3
- VERSION = "1.0.1".freeze
3
+ VERSION = "1.0.2".freeze
4
4
  end
5
5
  end
data/script/cibuild ADDED
@@ -0,0 +1,4 @@
1
+ #! /bin/sh
2
+
3
+ bundle exec rspec --color $@
4
+ bundle exec rubocop -S -D
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoliy Yastreb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-17 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -75,7 +75,9 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".rubocop.yml"
78
+ - ".travis.yml"
78
79
  - Gemfile
80
+ - History.md
79
81
  - LICENSE
80
82
  - README.md
81
83
  - Rakefile
@@ -83,8 +85,11 @@ files:
83
85
  - lib/jekyll-maps.rb
84
86
  - lib/jekyll-maps/google_map.html
85
87
  - lib/jekyll-maps/google_map_tag.rb
88
+ - lib/jekyll-maps/location_finder.rb
89
+ - lib/jekyll-maps/options_parser.rb
86
90
  - lib/jekyll-maps/version.rb
87
91
  - script/bootstrap
92
+ - script/cibuild
88
93
  homepage: https://github.com/ayastreb/jekyll-google-maps
89
94
  licenses:
90
95
  - MIT