jekyll-maps-debugging 2.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c55dbd0cceed5e8a5cdc93272042d22283b19cc
4
+ data.tar.gz: 158f0d192e8aebe8576ec66eab27c7f48b2495a2
5
+ SHA512:
6
+ metadata.gz: 5fa91b504b6b32daf85911c8c7e392b60c0164e25b476405dd9ba22f5421697689c4effeceb897fafa0d3efe7eb08a81304a0b881234da6f62a2a0c255bf76e6
7
+ data.tar.gz: be2b0eefa3081dc2cfa347eb9694ad4357fb00b447b71f1a6b7f0302e059c72677fa1af32bfe32cc3e000aa821dd8055c517c9b85ffd7599ab376cb316a2df1f
data/.codeclimate.yml ADDED
@@ -0,0 +1,26 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ - javascript
9
+ fixme:
10
+ enabled: true
11
+ rubocop:
12
+ enabled: true
13
+ eslint:
14
+ enabled: true
15
+ ratings:
16
+ paths:
17
+ - "**.inc"
18
+ - "**.js"
19
+ - "**.jsx"
20
+ - "**.module"
21
+ - "**.php"
22
+ - "**.py"
23
+ - "**.rb"
24
+ exclude_paths:
25
+ - script/
26
+ - spec/
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .idea
2
+ *.gem
3
+ Gemfile.lock
4
+ tmp
5
+ spec/dest
6
+ coverage
7
+ _site
8
+ node_modules
9
+ .DS_store
data/.rubocop.yml ADDED
@@ -0,0 +1,127 @@
1
+ ---
2
+ AllCops:
3
+ TargetRubyVersion: 2.0
4
+ Include:
5
+ - lib/**/*.rb
6
+ - spec/**/*.rb
7
+ Lint/EndAlignment:
8
+ Severity: error
9
+ Lint/UnreachableCode:
10
+ Severity: error
11
+ Lint/UselessAccessModifier:
12
+ Enabled: false
13
+ Metrics/AbcSize:
14
+ Max: 20
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - spec/**/*.rb
18
+ Metrics/ClassLength:
19
+ Max: 300
20
+ Exclude:
21
+ - !ruby/regexp /spec\/.*.rb$/
22
+ Metrics/CyclomaticComplexity:
23
+ Max: 8
24
+ Metrics/LineLength:
25
+ Exclude:
26
+ - Rakefile
27
+ - Gemfile
28
+ - jekyll-maps.gemspec
29
+ Max: 90
30
+ Severity: warning
31
+ Metrics/MethodLength:
32
+ Max: 20
33
+ CountComments: false
34
+ Severity: error
35
+ Metrics/ModuleLength:
36
+ Max: 240
37
+ Metrics/ParameterLists:
38
+ Max: 4
39
+ Metrics/PerceivedComplexity:
40
+ Max: 8
41
+ Style/Alias:
42
+ Enabled: false
43
+ Style/AlignArray:
44
+ Enabled: false
45
+ Style/AlignHash:
46
+ EnforcedHashRocketStyle: table
47
+ Style/AlignParameters:
48
+ EnforcedStyle: with_fixed_indentation
49
+ Enabled: false
50
+ Style/AndOr:
51
+ Severity: error
52
+ Style/Attr:
53
+ Enabled: false
54
+ Style/BracesAroundHashParameters:
55
+ Enabled: false
56
+ Style/ClassAndModuleChildren:
57
+ Enabled: false
58
+ Style/Documentation:
59
+ Enabled: false
60
+ Style/DoubleNegation:
61
+ Enabled: false
62
+ Style/EmptyLinesAroundAccessModifier:
63
+ Enabled: false
64
+ Style/EmptyLinesAroundModuleBody:
65
+ Enabled: false
66
+ Style/ExtraSpacing:
67
+ AllowForAlignment: true
68
+ Style/FileName:
69
+ Enabled: false
70
+ Style/FirstParameterIndentation:
71
+ EnforcedStyle: consistent
72
+ Style/GuardClause:
73
+ Enabled: false
74
+ Style/HashSyntax:
75
+ EnforcedStyle: hash_rockets
76
+ Severity: error
77
+ Style/IfUnlessModifier:
78
+ Enabled: false
79
+ Style/IndentArray:
80
+ EnforcedStyle: consistent
81
+ Style/IndentHash:
82
+ EnforcedStyle: consistent
83
+ Style/IndentationWidth:
84
+ Severity: error
85
+ Style/ModuleFunction:
86
+ Enabled: false
87
+ Style/MultilineMethodCallIndentation:
88
+ EnforcedStyle: indented
89
+ Style/MultilineOperationIndentation:
90
+ EnforcedStyle: indented
91
+ Style/MultilineTernaryOperator:
92
+ Severity: error
93
+ Style/PercentLiteralDelimiters:
94
+ PreferredDelimiters:
95
+ "%q": "{}"
96
+ "%Q": "{}"
97
+ "%r": "!!"
98
+ "%s": "()"
99
+ "%w": "()"
100
+ "%W": "()"
101
+ "%x": "()"
102
+ Style/RedundantReturn:
103
+ Enabled: false
104
+ Style/RedundantSelf:
105
+ Enabled: false
106
+ Style/RegexpLiteral:
107
+ EnforcedStyle: percent_r
108
+ Style/RescueModifier:
109
+ Enabled: false
110
+ Style/SignalException:
111
+ EnforcedStyle: only_raise
112
+ Style/SingleLineMethods:
113
+ Enabled: false
114
+ Style/SpaceAroundOperators:
115
+ Enabled: false
116
+ Style/SpaceInsideBrackets:
117
+ Enabled: false
118
+ Style/StringLiterals:
119
+ EnforcedStyle: double_quotes
120
+ Style/StringLiteralsInInterpolation:
121
+ EnforcedStyle: double_quotes
122
+ Style/UnneededCapitalW:
123
+ Enabled: false
124
+ Style/IndentHeredoc:
125
+ Enabled: false
126
+ Style/SymbolArray:
127
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.1
4
+ - 2.3.0
5
+ - 2.2
6
+ - 2.1
7
+ script: script/cibuild
8
+ after_success:
9
+ - bundle exec codeclimate-test-reporter
10
+ sudo: false
11
+ cache: bundler
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "codeclimate-test-reporter", :group => :test, :require => nil
data/History.md ADDED
@@ -0,0 +1,71 @@
1
+ ## 2.1.1 / 2018-01-25
2
+
3
+ * fixed JS lib injection in header (fix #31)
4
+
5
+ ## 2.1.0 / 2018-01-10
6
+
7
+ * fixed base_url in marker url (fix #28)
8
+
9
+ ## 2.0.4 / 2017-07-19
10
+
11
+ * allow multiple locations per document (fix #6)
12
+ * allow inline locations with map attributes, e.g. `{% google_map laititude='42.23323' longitude='3.213232' %}` (fix #23)
13
+
14
+ ## 2.0.3 / 2017-05-17
15
+
16
+ * load locations from specific data file (fix #26)
17
+
18
+ ## 2.0.2 / 2017-04-24
19
+
20
+ * allow multi-word filters (fix #25)
21
+
22
+ ## 2.0.1 / 2017-04-11
23
+
24
+ * add option to hide markers (show_marker="false")
25
+ * do not show link in marker popup when no URL is set
26
+
27
+ ## 2.0.0 / 2016-11-06
28
+
29
+ * change default behaviour to load location from current page
30
+ * removed on-page flag
31
+ * change attributes syntax to HTML-style
32
+
33
+ ## 1.1.6 / 2016-09-07
34
+
35
+ * fix #15 - broken page if there is <header> tag used
36
+ * allow setting custom zoom level with `zoom:10` attribute
37
+
38
+ ## 1.1.5 / 2016-09-03
39
+
40
+ * allow to disable marker popup on the map
41
+
42
+ ## 1.1.4 / 2016-07-31
43
+
44
+ * open info window when marker is clicked
45
+
46
+ ## 1.1.3 / 2016-07-28
47
+
48
+ * on-page map flag
49
+
50
+ ## 1.1.2 / 2016-07-22
51
+
52
+ * configurable marker cluster
53
+
54
+ ## 1.1.1 / 2016-07-20
55
+
56
+ * configure GoogleMaps API key from \_config.yml
57
+
58
+ ## 1.1.0 / 2016-07-19
59
+
60
+ * add multiple maps to single page
61
+ * load external JavaScript asynchronously
62
+ * configure map element's id, CSS class and dimensions
63
+
64
+ ## 1.0.2 / 2016-07-18
65
+
66
+ * fix script loading
67
+ * look for location coordinates in all collections
68
+
69
+ ## 1.0.1 / 2016-07-17
70
+
71
+ * implement Google Maps tag
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Anatoliy Yastreb
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,179 @@
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
+ [![Dependency Status](https://gemnasium.com/badges/github.com/ayastreb/jekyll-maps.svg)](https://gemnasium.com/github.com/ayastreb/jekyll-maps)
8
+
9
+ Jekyll Maps is a plugin that allows you to easily create different maps on your Jekyll site pages.
10
+ It allows you to select which points to display on the map with different filters.
11
+
12
+ GoogleMaps Marker Clusterer can be used if you have many points within close proximity.
13
+
14
+ ## Installation
15
+
16
+ 1. Add the following to your site's `Gemfile`:
17
+
18
+
19
+ ```ruby
20
+ gem 'jekyll-maps'
21
+ ```
22
+
23
+ 2. Add the following to your site's `_config.yml`:
24
+
25
+
26
+ ```yml
27
+ plugins:
28
+ - jekyll-maps
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Configure Google API Key
34
+
35
+ To be able to use Google Maps you need to obtain
36
+ [API Key](https://developers.google.com/maps/documentation/javascript/get-api-key).
37
+
38
+ Once you have your API Key you need to add it to Jekyll's `_config.yml`:
39
+
40
+ ```yml
41
+ maps:
42
+ google:
43
+ api_key: <YOUR_KEY>
44
+ ```
45
+
46
+ ### Data Source
47
+
48
+ First, add location information to your posts YAML front-matter:
49
+
50
+ ```yml
51
+ location:
52
+ latitude: 51.5285582
53
+ longitude: -0.2416807
54
+ ```
55
+
56
+ You can specify multiple locations per post:
57
+
58
+ ```yml
59
+ location:
60
+ - latitude: 51.5285582
61
+ longitude: -0.2416807
62
+ - latitude: 52.5285582
63
+ longitude: -2.2416807
64
+ - title: custom marker title
65
+ image: custom marker image
66
+ url: custom marker url
67
+ latitude: 51.5285582
68
+ longitude: -0.2416807
69
+ ```
70
+
71
+ Alternatively, you can add location info to your custom collection's documents or even in data
72
+ files:
73
+
74
+ ```yml
75
+ - title: Paris
76
+ url: http://google.fr
77
+ location:
78
+ latitude: 48.8587741
79
+ longitude: 2.2074741
80
+
81
+ - title: Madrid
82
+ url: http://google.es
83
+ location:
84
+ latitude: 40.4378698
85
+ longitude: -3.8196204
86
+ ```
87
+
88
+ By default this plugin will display location from the page it's placed on:
89
+
90
+ ```
91
+ {% google_map %}
92
+ ```
93
+
94
+ But you can use src attribute to load locations from other places, like posts, collections or data
95
+ files!
96
+
97
+ For example, this map will show locations from all posts from 2016:
98
+
99
+ ```
100
+ {% google_map src="_posts/2016" %}
101
+ ```
102
+
103
+ This map will show locations from a collection called 'my_collection':
104
+
105
+ ```
106
+ {% google_map src="_collections/my_collection" %}
107
+ ```
108
+
109
+ This map will show locations from all data files located in 'my_points' sub-folder:
110
+
111
+ ```
112
+ {% google_map src="_data/my_points" %}
113
+ ```
114
+
115
+ You can configure map's dimensions and assign custom CSS class to the element:
116
+
117
+ ```
118
+ {% google_map width="100%" height="400" class="my-map" %}
119
+ ```
120
+
121
+ You can also just set marker coordinates directly in tag attributes:
122
+
123
+ ```
124
+ {% google_map latitude="48.8587741" longitude="2.2074741" marker_title="My Location" marker_img="/img.jpg" marker_url="/my-location.html" %}
125
+ ```
126
+
127
+ This will create a map with single marker in given location. `marker_title`, `marker_img` and
128
+ `marker_url` attributes are optional and current page's data will be used by default.
129
+
130
+ ### Filters
131
+
132
+ You can also filter which locations to display on the map!<br/> For instance, following tag will
133
+ only display locations from documents which have `lang: en` in their front-matter data.
134
+
135
+ ```
136
+ {% google_map src="_posts" lang="en" %}
137
+ ```
138
+
139
+ ### Marker Cluster
140
+
141
+ By default [Marker Clusterer](https://github.com/googlemaps/js-marker-clusterer) is enabled. If you
142
+ have many markers on the map, it will group them and show icon with the count of markers in each
143
+ cluster -
144
+ [see example](https://googlemaps.github.io/js-marker-clusterer/examples/advanced_example.html).
145
+
146
+ If you don't want to use marker cluster, you can disable it globally in `_config.yml`:
147
+
148
+ ```yml
149
+ maps:
150
+ google:
151
+ marker_cluster:
152
+ enabled: false
153
+ ```
154
+
155
+ Or you can disable it per single map tag:
156
+
157
+ ```
158
+ {% google_map no_cluster %}
159
+ ```
160
+
161
+ If you have any questions or proposals - open up an
162
+ [issue](https://github.com/ayastreb/jekyll-maps/issues/new)!
163
+
164
+ ## Examples
165
+
166
+ Want to see it in action? Check out [Demo Page](https://ayastreb.me/jekyll-maps/#examples)!
167
+
168
+ ## Contributing
169
+
170
+ 1. Fork it (https://github.com/ayastreb/jekyll-maps/fork)
171
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
172
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
173
+ 4. Push to the branch (`git push origin my-new-feature`)
174
+ 5. Create a new Pull Request
175
+
176
+ ## License
177
+
178
+ [MIT](https://github.com/ayastreb/jekyll-maps/blob/master/LICENSE). Feel free to use, copy or
179
+ distribute it.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "jekyll-maps/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "jekyll-maps-debugging"
7
+ spec.summary = "Jekyll Google Maps integration"
8
+ spec.description = "Google Maps support in Jekyll blog to easily embed maps with posts' locations"
9
+ spec.version = Jekyll::Maps::VERSION
10
+ spec.authors = ["Chris Lyman, c/o Anatoliy Yastreb"]
11
+ spec.email = ["chris.a.lyman@gmail.com"]
12
+
13
+ spec.homepage = "https://ayastreb.me/jekyll-maps/"
14
+ spec.licenses = ["MIT"]
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "jekyll", "~> 3.0"
19
+
20
+ spec.add_development_dependency "rake", "~> 11.0"
21
+ spec.add_development_dependency "rspec", "~> 3.5"
22
+ spec.add_development_dependency "rubocop", "0.49.1"
23
+ end
@@ -0,0 +1,12 @@
1
+ require "securerandom"
2
+ require "ostruct"
3
+ require "jekyll-maps/google_map_api"
4
+ require "jekyll-maps/google_map_tag"
5
+ require "jekyll-maps/location_finder"
6
+ require "jekyll-maps/options_parser"
7
+ require "jekyll-maps/version"
8
+
9
+ module Jekyll
10
+ module Maps
11
+ end
12
+ end
@@ -0,0 +1,146 @@
1
+ /* global google */
2
+ /* global MarkerClusterer */
3
+ // eslint-disable-next-line no-unused-vars
4
+ var jekyllMaps = (function() {
5
+ 'use strict'
6
+ var clusterSettings = {}
7
+ var clusterReady = false
8
+ var mapReady = false
9
+ var options = {}
10
+ var data = []
11
+ var maps = []
12
+
13
+ return {
14
+ initializeMap: initializeMap,
15
+ initializeCluster: initializeCluster,
16
+ register: register
17
+ }
18
+
19
+ /**
20
+ * Setup Google Maps options and call renderer.
21
+ */
22
+ function initializeMap() {
23
+ options = {
24
+ mapTypeId: google.maps.MapTypeId.ROADMAP,
25
+ center: new google.maps.LatLng(0, 0)
26
+ }
27
+ mapReady = true
28
+ render()
29
+ }
30
+
31
+ /**
32
+ * Register map data to be rendered once Google Maps API is loaded.
33
+ *
34
+ * @param string id
35
+ * @param Array locations
36
+ * @param Object settings
37
+ */
38
+ function register(id, locations, options) {
39
+ data.push({ id: id, locations: locations, options: options })
40
+ render()
41
+ }
42
+
43
+ /**
44
+ * Render maps data if Google Maps API is loaded.
45
+ */
46
+ function render() {
47
+ if (!mapReady) return
48
+
49
+ while (data.length > 0) {
50
+ var item = data.pop()
51
+ var bounds = new google.maps.LatLngBounds()
52
+ var mapOptions = Object.assign({}, options, item.options)
53
+ var map = new google.maps.Map(
54
+ document.getElementById(item.id),
55
+ mapOptions
56
+ )
57
+ var infoWindow = new google.maps.InfoWindow()
58
+ var markers = item.locations.map(createMarker)
59
+
60
+ map.fitBounds(bounds)
61
+ google.maps.event.addListenerOnce(map, 'bounds_changed', function() {
62
+ if (this.customZoom) this.setZoom(this.customZoom)
63
+ })
64
+ if (mapOptions.useCluster) {
65
+ maps.push({ map: map, markers: markers })
66
+ processCluster()
67
+ }
68
+ }
69
+
70
+ function createMarker(location) {
71
+ var position = new google.maps.LatLng(
72
+ location.latitude,
73
+ location.longitude
74
+ )
75
+ bounds.extend(position)
76
+ if (!mapOptions.showMarker) return false
77
+
78
+ var marker = new google.maps.Marker({
79
+ position: position,
80
+ title: location.title,
81
+ image: location.image,
82
+ url: location.url.length > 0 ? mapOptions.baseUrl + location.url : '',
83
+ map: map
84
+ })
85
+ if (mapOptions.showMarkerPopup) marker.addListener('click', markerPopup)
86
+
87
+ return marker
88
+ }
89
+
90
+ function markerPopup() {
91
+ var contentHtml =
92
+ '<div class="map-info-window"><h5>' + this.title + '</h5>'
93
+ var imageHtml = '<img src="' + this.image + '" alt="' + this.title + '"/>'
94
+ if (this.url.length > 0) {
95
+ var linkText = this.image.length > 0 ? imageHtml : 'View'
96
+ contentHtml += '<a href="' + this.url + '">' + linkText + '</a></div>'
97
+ } else if (this.image.length > 0) {
98
+ contentHtml += imageHtml
99
+ }
100
+ infoWindow.setContent(contentHtml)
101
+ infoWindow.open(map, this)
102
+ }
103
+ }
104
+
105
+ function initializeCluster(settings) {
106
+ clusterReady = true
107
+ clusterSettings = settings || {}
108
+ processCluster()
109
+ }
110
+
111
+ function processCluster() {
112
+ if (!clusterReady) return
113
+
114
+ while (maps.length > 0) {
115
+ var obj = maps.pop()
116
+ // eslint-disable-next-line no-new
117
+ new MarkerClusterer(obj.map, obj.markers, {
118
+ gridSize: clusterSettings.grid_size || 25,
119
+ imagePath:
120
+ 'https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/images/m'
121
+ })
122
+ }
123
+ }
124
+ })()
125
+ /* Object.assign polyfill */
126
+ if (typeof Object.assign !== 'function') {
127
+ Object.assign = function(target) {
128
+ 'use strict'
129
+ if (target == null) {
130
+ throw new TypeError('Cannot convert undefined or null to object')
131
+ }
132
+
133
+ target = Object(target)
134
+ for (var index = 1; index < arguments.length; index++) {
135
+ var source = arguments[index]
136
+ if (source != null) {
137
+ for (var key in source) {
138
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
139
+ target[key] = source[key]
140
+ }
141
+ }
142
+ }
143
+ }
144
+ return target
145
+ }
146
+ }
@@ -0,0 +1,72 @@
1
+ module Jekyll
2
+ module Maps
3
+ class GoogleMapApi
4
+ HEAD_END_TAG = %r!</[\s\t]*head>!
5
+
6
+ class << self
7
+ def prepend_api_code(doc)
8
+ @config = doc.site.config
9
+ if doc.output =~ HEAD_END_TAG
10
+ # Insert API code before header's end if this document has one.
11
+ doc.output.gsub!(HEAD_END_TAG, %(#{api_code}#{Regexp.last_match}))
12
+ else
13
+ doc.output.prepend(api_code)
14
+ end
15
+ end
16
+
17
+ private
18
+ def api_code
19
+ <<HTML
20
+ <script type='text/javascript'>
21
+ #{js_lib_contents}
22
+ </script>
23
+ #{load_google_maps_api}
24
+ #{load_marker_cluster}
25
+ HTML
26
+ end
27
+
28
+ private
29
+ def load_google_maps_api
30
+ api_key = @config.fetch("maps", {})
31
+ .fetch("google", {})
32
+ .fetch("api_key", "")
33
+ <<HTML
34
+ <script async defer src='https://maps.googleapis.com/maps/api/js?key=#{api_key}&callback=#{Jekyll::Maps::GoogleMapTag::JS_LIB_NAME}.initializeMap'></script>
35
+ HTML
36
+ end
37
+
38
+ private
39
+ def load_marker_cluster
40
+ settings = @config.fetch("maps", {})
41
+ .fetch("google", {})
42
+ .fetch("marker_cluster", {})
43
+ return unless settings.fetch("enabled", true)
44
+ <<HTML
45
+ <script async defer src='https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/src/markerclusterer.js'
46
+ onload='#{Jekyll::Maps::GoogleMapTag::JS_LIB_NAME}.initializeCluster(#{settings.to_json})'></script>
47
+ HTML
48
+ end
49
+
50
+ private
51
+ def js_lib_contents
52
+ @js_lib_contents ||= begin
53
+ File.read(js_lib_path)
54
+ end
55
+ end
56
+
57
+ private
58
+ def js_lib_path
59
+ @js_lib_path ||= begin
60
+ File.expand_path("./google_map_api.js", File.dirname(__FILE__))
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
69
+ if doc.output =~ %r!#{Jekyll::Maps::GoogleMapTag::JS_LIB_NAME}!
70
+ Jekyll::Maps::GoogleMapApi.prepend_api_code(doc)
71
+ end
72
+ end
@@ -0,0 +1,75 @@
1
+ module Jekyll
2
+ module Maps
3
+ class GoogleMapTag < Liquid::Tag
4
+ JS_LIB_NAME = "jekyllMaps".freeze
5
+ DEFAULT_MAP_WIDTH = 600
6
+ DEFAULT_MAP_HEIGHT = 400
7
+
8
+ def initialize(_, args, _)
9
+ @args = OptionsParser.parse(args)
10
+ @finder = LocationFinder.new(@args)
11
+ super
12
+ end
13
+
14
+ def render(context)
15
+ locations = @finder.find(context.registers[:site], context.registers[:page])
16
+ @args[:attributes][:id] ||= SecureRandom.uuid
17
+
18
+ <<HTML
19
+ <div #{render_attributes}></div>
20
+ <script type='text/javascript'>
21
+ #{JS_LIB_NAME}.register(
22
+ '#{@args[:attributes][:id]}',
23
+ #{locations.to_json},
24
+ #{map_options(context.registers[:site]).to_json}
25
+ );
26
+ </script>
27
+ HTML
28
+ end
29
+
30
+ private
31
+ def render_attributes
32
+ attributes = []
33
+ attributes << "id='#{@args[:attributes][:id]}'"
34
+ attributes << render_dimensions
35
+ attributes << render_class if @args[:attributes][:class]
36
+ attributes.join(" ")
37
+ end
38
+
39
+ private
40
+ def render_dimensions
41
+ width = @args[:attributes][:width] || DEFAULT_MAP_WIDTH
42
+ height = @args[:attributes][:height] || DEFAULT_MAP_HEIGHT
43
+ width_unit = width.to_s.include?("%") ? "" : "px"
44
+ height_unit = height.to_s.include?("%") ? "" : "px"
45
+ %(style='width:#{width}#{width_unit};height:#{height}#{height_unit};')
46
+ end
47
+
48
+ private
49
+ def render_class
50
+ css = @args[:attributes][:class]
51
+ css = css.join(" ") if css.is_a?(Array)
52
+ %(class='#{css}')
53
+ end
54
+
55
+ private
56
+ def map_options(site)
57
+ opts = {
58
+ :baseUrl => site.baseurl || "/",
59
+ :useCluster => !@args[:flags][:no_cluster],
60
+ :showMarker => @args[:attributes][:show_marker] != "false",
61
+ :showMarkerPopup => @args[:attributes][:show_popup] != "false"
62
+ }
63
+ print @args
64
+ if @args[:attributes][:zoom]
65
+ opts[:customZoom] = @args[:attributes][:zoom].to_i
66
+ print "zoom!"
67
+ print opts[:customZoom]
68
+ end
69
+ opts
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ Liquid::Template.register_tag("google_map", Jekyll::Maps::GoogleMapTag)
@@ -0,0 +1,119 @@
1
+ module Jekyll
2
+ module Maps
3
+ class LocationFinder
4
+ def initialize(options)
5
+ @documents = []
6
+ @options = options
7
+ end
8
+
9
+ def find(site, page)
10
+ if @options[:attributes][:latitude] && @options[:attributes][:longitude]
11
+ return [location_from_options(page)]
12
+ elsif @options[:filters].empty?
13
+ @documents << page if with_location?(page)
14
+ else
15
+ site.collections.each_value { |collection| filter(collection.docs) }
16
+ site_data(site).each_value { |items| traverse(items) }
17
+ end
18
+
19
+ documents_to_locations
20
+ end
21
+
22
+ private
23
+ def location_from_options(page)
24
+ {
25
+ :latitude => @options[:attributes][:latitude],
26
+ :longitude => @options[:attributes][:longitude],
27
+ :title => @options[:attributes][:marker_title] || page["title"],
28
+ :url => @options[:attributes][:marker_url] || fetch_url(page),
29
+ :image => @options[:attributes][:marker_img] || page["image"] || ""
30
+ }
31
+ end
32
+
33
+ private
34
+ def site_data(site)
35
+ return {} unless data_source?
36
+
37
+ path = @options[:filters]["src"].scan(%r!_data\/([^\/]+)!).join(".")
38
+ return site.data if path.empty?
39
+
40
+ data = OpenStruct.new(site.data)
41
+ if @options[:filters]["src"] =~ %r!\.ya?ml!
42
+ { :path => data[path.gsub(%r!\.ya?ml!, "")] }
43
+ else
44
+ data[path]
45
+ end
46
+ end
47
+
48
+ private
49
+ def data_source?
50
+ filters = @options[:filters]
51
+ filters.key?("src") && filters["src"].start_with?("_data")
52
+ end
53
+
54
+ private
55
+ def traverse(items)
56
+ return filter(items) if items.is_a?(Array)
57
+
58
+ items.each_value { |children| traverse(children) } if items.is_a?(Hash)
59
+ end
60
+
61
+ private
62
+ def filter(docs)
63
+ docs.each do |doc|
64
+ @documents << doc if with_location?(doc) && match_filters?(doc)
65
+ end
66
+ end
67
+
68
+ private
69
+ def with_location?(doc)
70
+ !doc["location"].nil? && !doc["location"].empty?
71
+ end
72
+
73
+ private
74
+ def match_filters?(doc)
75
+ @options[:filters].each do |filter, value|
76
+ if filter == "src"
77
+ return true unless doc.respond_to?(:relative_path)
78
+ return false unless doc.relative_path.start_with?(value)
79
+ elsif doc[filter].nil? || doc[filter] != value
80
+ return false
81
+ end
82
+ end
83
+ end
84
+
85
+ private
86
+ def documents_to_locations
87
+ locations = []
88
+ @documents.each do |document|
89
+ if document["location"].is_a?(Array)
90
+ document["location"].each do |location|
91
+ locations.push(convert(document, location))
92
+ end
93
+ else
94
+ locations.push(convert(document, document["location"]))
95
+ end
96
+ end
97
+ locations
98
+ end
99
+
100
+ private
101
+ def convert(document, location)
102
+ {
103
+ :latitude => location["latitude"],
104
+ :longitude => location["longitude"],
105
+ :title => location["title"] || document["title"],
106
+ :url => location["url"] || fetch_url(document),
107
+ :image => location["image"] || document["image"] || ""
108
+ }
109
+ end
110
+
111
+ private
112
+ def fetch_url(document)
113
+ return document["url"] if document.is_a?(Hash) && document.key?("url")
114
+ return document.url if document.respond_to? :url
115
+ ""
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,46 @@
1
+ module Jekyll
2
+ module Maps
3
+ class OptionsParser
4
+ OPTIONS_SYNTAX = %r!([^\s]+)\s*=\s*['"]+([^'"]+)['"]+!
5
+ ALLOWED_FLAGS = %w(
6
+ no_cluster
7
+ ).freeze
8
+ ALLOWED_ATTRIBUTES = %w(
9
+ id
10
+ width
11
+ height
12
+ class
13
+ show_marker
14
+ show_popup
15
+ zoom
16
+ latitude
17
+ longitude
18
+ marker_title
19
+ marker_img
20
+ marker_url
21
+ ).freeze
22
+
23
+ class << self
24
+ def parse(raw_options)
25
+ options = {
26
+ :attributes => {},
27
+ :filters => {},
28
+ :flags => {}
29
+ }
30
+ raw_options.scan(OPTIONS_SYNTAX).each do |key, value|
31
+ value = value.split(",") if value.include?(",")
32
+ if ALLOWED_ATTRIBUTES.include?(key)
33
+ options[:attributes][key.to_sym] = value
34
+ else
35
+ options[:filters][key] = value
36
+ end
37
+ end
38
+ ALLOWED_FLAGS.each do |key|
39
+ options[:flags][key.to_sym] = true if raw_options.include?(key)
40
+ end
41
+ options
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module Maps
3
+ VERSION = "2.1.1".freeze
4
+ end
5
+ end
data/script/bootstrap ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ bundle install
data/script/cibuild ADDED
@@ -0,0 +1,4 @@
1
+ #! /bin/sh
2
+
3
+ bundle exec rspec --color $@
4
+ bundle exec rubocop -S -D
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-maps-debugging
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Lyman, c/o Anatoliy Yastreb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.49.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.49.1
69
+ description: Google Maps support in Jekyll blog to easily embed maps with posts' locations
70
+ email:
71
+ - chris.a.lyman@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".codeclimate.yml"
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - History.md
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - jekyll-maps.gemspec
86
+ - lib/jekyll-maps.rb
87
+ - lib/jekyll-maps/google_map_api.js
88
+ - lib/jekyll-maps/google_map_api.rb
89
+ - lib/jekyll-maps/google_map_tag.rb
90
+ - lib/jekyll-maps/location_finder.rb
91
+ - lib/jekyll-maps/options_parser.rb
92
+ - lib/jekyll-maps/version.rb
93
+ - script/bootstrap
94
+ - script/cibuild
95
+ homepage: https://ayastreb.me/jekyll-maps/
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.5.1
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Jekyll Google Maps integration
119
+ test_files: []