opal-google_maps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5360d29c0f5cabf4c11ca826a0d3e0e2d9a5fc50
4
+ data.tar.gz: ec3414274194e249480133e3c319017237959623
5
+ SHA512:
6
+ metadata.gz: 9b8d0daaba7de60e5eddf530592461912361ef1ee0efd727d803fcef1a2246a58112d812388e5c4acc88eafb30e00981651eea37895fe06e2c611c6d8b6eb18c
7
+ data.tar.gz: 882c2d21b688265290bf92e2ab59d74adee8b0a56afe0ea2572a33a99f2932d02cca8673eea6651f93fc4240ed23605b825ff5765ff78563e3ef9fe059d670ac
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jgaskins@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in opal-google_maps.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jamie Gaskins
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # Opal::GoogleMaps
2
+
3
+ Ruby bindings for client-side Google Maps integration via Opal and helpers for server-side loading.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'opal-google_maps'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Since this gem is a Ruby interface for Google Maps, it requires that the Google Maps JS library be loaded (from Google) first. This is as simple as putting the following line in your server-side application's view template:
20
+
21
+ ```erb
22
+ <%= Opal::GoogleMaps.google_maps(YOUR_API_KEY) %>
23
+ ```
24
+
25
+ This will add a `<script>` tag to the rendered HTML with your API key.
26
+
27
+ ### Client-side
28
+
29
+ If you're using this gem with Clearwater, you'll want to render it into a `Clearwater::BlackBoxNode` rather than a simple `Clearwater::Component`. The `BlackBoxNode` gives you callbacks for `mount`, `update`, and `unmount`, but the simpler components do not. For example:
30
+
31
+ ```ruby
32
+ require 'clearwater/black_box_node' # It is not loaded with Clearwater by default
33
+ require 'google/maps' # No need for the `opal` namespace
34
+
35
+ class MyMap
36
+ include Clearwater::BlackBoxNode
37
+ include Google::Maps # So we don't have to namespace every constant
38
+
39
+ attr_reader :map
40
+
41
+ def node
42
+ # Important to set the dimensions of the map container
43
+ Clearwater::Component.div(style: { width: '600px', height: '600px' })
44
+ end
45
+
46
+ def mount(element)
47
+ # Need to delay this one animation frame so the div we specified above is
48
+ # actually in the rendered DOM. Google Maps needs to get the dimensions of
49
+ # the map from a fully rendered DOM node.
50
+ Bowser.window.animation_frame do
51
+ # Similar to the `google.maps.Map` namespace
52
+ @map = Map.new(
53
+ element, # passed into this method
54
+ center: LatLng.new(-34.397, 150.644), # Sydney, NSW, Australia
55
+ zoom: 8,
56
+ )
57
+ end
58
+ end
59
+
60
+ # Each time you render a BlackBoxNode, you get a new instance, so you need
61
+ # to copy it across instances if you want to operate on it across renders.
62
+ # If you're only rendering it and never doing anything with it, you can omit
63
+ # this method entirely.
64
+ def update(previous, element)
65
+ @map = previous.map
66
+ end
67
+ end
68
+ ```
69
+
70
+ ### Loading other Google Maps JS libraries
71
+
72
+ Google Maps has several additional libraries to choose from. To load them, add the `libraries` key to your server-side rendering call:
73
+
74
+ ```erb
75
+ <%= Opal::GoogleMaps.google_maps(YOUR_API_KEY, libraries: %w[drawing geometry places visualization]) %>
76
+ ```
77
+
78
+ ### Loading Google Maps asynchronously
79
+
80
+ You can use the `async` keyword argument to load the Google Maps libraries in a way that will not block rendering.
81
+
82
+ ```erb
83
+ <%= Opal::GoogleMaps.google_maps(YOUR_API_KEY, async: true) %>
84
+ ```
85
+
86
+ Keep in mind that this can cause problems if your app renders a map immediately on load. If you load Google Maps asynchronously, it isn't guaranteed to be loaded before your app. In such a case, you may get an error saying something to the effect of `google is not an object`.
87
+
88
+ ## Contributing
89
+
90
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jgaskins/opal-google_maps. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
95
+
96
+ ## Code of Conduct
97
+
98
+ Everyone interacting in the Opal::GoogleMaps project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jgaskins/opal-google_maps/blob/master/CODE_OF_CONDUCT.md).
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "opal/google_maps"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require 'opal'
2
+ require "opal/google_maps/version"
3
+
4
+ module Opal
5
+ module GoogleMaps
6
+ def google_maps key, libraries: [], async: false
7
+ %{<script src="https://maps.googleapis.com/maps/api/js?key=#{key}&libraries=#{libraries.join(',')}"#{' async defer' if async}></script>}
8
+ end
9
+ end
10
+ end
11
+
12
+ Opal.append_path File.expand_path('../../../opal', __FILE__)
@@ -0,0 +1,5 @@
1
+ module Opal
2
+ module GoogleMaps
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "opal/google_maps/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "opal-google_maps"
8
+ spec.version = Opal::GoogleMaps::VERSION
9
+ spec.authors = ["Jamie Gaskins"]
10
+ spec.email = ["jgaskins@gmail.com"]
11
+
12
+ spec.summary = %q{Opal bindings for Google Maps}
13
+ spec.homepage = "https://github.com/jgaskins/opal-google_maps"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_dependency "opal", "~> 0.10.0"
27
+ spec.add_dependency "bowser" # Uses Bowser::EventTarget
28
+ end
@@ -0,0 +1,39 @@
1
+ require 'bowser/event_target'
2
+ require 'google/maps/map'
3
+ require 'google/maps/delegate_native'
4
+
5
+ module Google
6
+ module Maps
7
+ class LatLng
8
+ attr_reader :lat, :lng
9
+
10
+ def self.from_native native
11
+ new(`#{native}.lat()`, `#{native}.lng()`)
12
+ end
13
+
14
+ def initialize lat, lng
15
+ @lat = lat
16
+ @lng = lng
17
+ end
18
+
19
+ # An instance of this class can stand in for a google.maps.LatLng instance
20
+ def to_n
21
+ self
22
+ end
23
+
24
+ alias latitude lat
25
+ alias longitude lng
26
+ end
27
+
28
+ class Marker
29
+ include DelegateNative
30
+ include Bowser::EventTarget
31
+
32
+ def initialize options={}
33
+ @native = `new maps.Marker(#{options.to_n})`
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ require 'google/maps/map'
@@ -0,0 +1,35 @@
1
+ module Google
2
+ module Maps
3
+ module DelegateNative
4
+ %x{
5
+ var upper = function(char) { return char[char.length - 1].toUpperCase() };
6
+ var titleCase = function(string) {
7
+ return string.replace(/^\w|_\w/, upper)
8
+ };
9
+ var maps = google.maps;
10
+ }
11
+
12
+ def method_missing message, *args, &block
13
+ property = `titleCase(#{message})`
14
+
15
+ result = if `#@native['get' + #{property}]`
16
+ puts "#{self.class}#get#{property}(#{args})"
17
+ `#@native['get' + #{property}].apply(#@native, #{args})`
18
+ elsif property.end_with?('=') && `#@native['set' + #{property.chop}]`
19
+ puts "#{self.class}#set#{property.chop}(#{args})"
20
+ `#@native['set' + #{property.chop}].apply(#@native, #{args})`
21
+ else
22
+ super
23
+ end
24
+
25
+ if `#{result} instanceof maps.LatLng`
26
+ LatLng.from_native(result)
27
+ end
28
+ end
29
+
30
+ def to_n
31
+ @native
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ require 'bowser/event_target'
2
+ require 'google/maps/delegate_native'
3
+
4
+ module Google
5
+ module Maps
6
+ class Map
7
+ include Bowser::EventTarget
8
+ include DelegateNative
9
+
10
+ def initialize element, options={}
11
+ @element = element
12
+ @options = options
13
+ @native = `new google.maps.Map(#{element.to_n}, #{options.to_n})`
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opal-google_maps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Gaskins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: opal
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bowser
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - jgaskins@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/opal/google_maps.rb
101
+ - lib/opal/google_maps/version.rb
102
+ - opal-google_maps.gemspec
103
+ - opal/google/maps.rb
104
+ - opal/google/maps/delegate_native.rb
105
+ - opal/google/maps/map.rb
106
+ homepage: https://github.com/jgaskins/opal-google_maps
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.12
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Opal bindings for Google Maps
130
+ test_files: []