rails-gmaps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5f2462c70a95897998572f51e52a03c183661d1
4
+ data.tar.gz: 337a182994a132e283844df4a777cc5af8e06e85
5
+ SHA512:
6
+ metadata.gz: c96b9197ab2837d9a9fa2c2e2eb2cd165c49bc32daee9741d7d0dce09a1c43e85d8b46c91f6689a4be6076ac34d1e484491febced87d22b1c04e3d0f576c2bad
7
+ data.tar.gz: 135b11f2c429b1a17035977b10292d96b80f9550a07d212716734d459b4fe289090f7227b876ff5722141bb6c63eec65c4a47d9bed114393622daf3f5b5b345d
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gmaps.gemspec
4
+ gemspec
5
+
6
+ gem 'geocoder'
7
+ gem 'rdoc'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Luan D.
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.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # Gmaps
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gmaps`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gmaps'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gmaps
22
+
23
+ ## Usage
24
+
25
+ # GMPOIT
26
+
27
+ This is gem for help to point on google map. You can marker your address and search your location
28
+
29
+ ## Installation
30
+ ### in your Gemfile
31
+ gem 'gmpoint', git: 'git@github.com:dangluan/gmpoint.git'
32
+
33
+ ## Setting Up
34
+
35
+ bundle
36
+ rails g gmpoint:install
37
+ rails g gmpoint MODEL
38
+ rake db:migrate
39
+
40
+ ## Usage
41
+
42
+ ### Registry google map key and add google map key in your head tag in application.html.erb
43
+
44
+ ```ruby
45
+ <%= google_map_api_js("your google api key") %>
46
+ ```
47
+
48
+ ### Require locations.coffee.js into your application.js
49
+
50
+ ```
51
+ .....
52
+ //= require locations
53
+ .....
54
+ ```
55
+
56
+ ### Add code below into any where if you want to display the map :
57
+
58
+ ```
59
+ <%= show_map_helper your_model %>
60
+ ```
61
+
62
+ Example:
63
+
64
+ ```
65
+ <%= show_map_helper user %>
66
+ ```
67
+
68
+ ### You can set options for view
69
+
70
+ #### You can set "width" , "height" for map view
71
+
72
+ ```
73
+ <%= show_map_helper user, {width: 400, height: 200} %>
74
+ ```
75
+
76
+ #### You can set "searchbox_with" for search box
77
+
78
+ ```
79
+ <%= show_map_helper user, {searchbox_width: 300} %>
80
+ ```
81
+
82
+ #### You can show or hide your search box
83
+
84
+ ```
85
+ <%= show_map_helper user, {searchbox: 'show', width: 400, height: 200, searchbox_width: 300} %>
86
+ ```
87
+ and when you want to hide the search box
88
+
89
+ ```
90
+ <%= show_map_helper user, {searchbox: 'none', width: 400, height: 200, searchbox_width: 300} %>
91
+ ```
92
+
93
+ #### You can only set show or point to map using attribute "allow"
94
+
95
+ ```
96
+ <%= show_map_helper user, {allow: 'show', searchbox: 'none', width: 400, height: 200, searchbox_width: 300} %>
97
+ ```
98
+
99
+ and when you want to point
100
+
101
+ ```
102
+ <%= show_map_helper user, {allow: 'point', searchbox: 'none', width: 400, height: 200, searchbox_width: 300} %>
103
+ ```
104
+
105
+ Example:
106
+
107
+ ```
108
+ <%= show_map_helper user, {width: 400, height: 200, searchbox_width: 300} %>
109
+ ```
110
+
111
+ #### You can set latitude and longitude default for your place
112
+
113
+ ```
114
+ <%= show_map_helper user, {latitude: 1.3028, longitude: 103.35, allow: 'show', searchbox: 'none', width: 400, height: 200, searchbox_width: 300} %>
115
+ ```
116
+
117
+ #### You can set zoom for map
118
+
119
+ ```
120
+ <%= show_map_helper user, {zoom: 10, latitude: 1.3028, longitude: 103.35, allow: 'show', searchbox: 'none', width: 400, height: 200, searchbox_width: 300} %>
121
+ ```
122
+
123
+ ## Contributing
124
+
125
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gmaps. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
126
+
127
+
128
+ ## License
129
+
130
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
131
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,55 @@
1
+ window.initJsMap = ->
2
+ window.geopoint_search_map($("#gmaps_location_address"))
3
+ $("#geopoint_search_box_container input").keypress (e) ->
4
+ if e.keyCode == 13 # enter
5
+ window.geopoint_search_map($(@))
6
+
7
+ zoom = $('.data-location').data('zoom')
8
+ if $("#gmaps_location_address").val() == ""
9
+ zoom = 11
10
+ opts =
11
+ center: new google.maps.LatLng($('.data-location').data('latitude'), $('.data-location').data('longitude'))
12
+ zoom: zoom
13
+ mapTypeId: google.maps.MapTypeId.ROADMAP
14
+
15
+
16
+ window.gmaps_map = new google.maps.Map(document.getElementById("map_canvas"), opts)
17
+ window.gmaps_marker = new google.maps.Marker({position: opts.center, draggable: true})
18
+ window.gmaps_info_window = new google.maps.InfoWindow({})
19
+ window.gmaps_map.setCenter(window.gmaps_marker.getPosition(), 16)
20
+ window.gmaps_info_window.close()
21
+ window.gmaps_marker.setMap(window.gmaps_map)
22
+ if $("#gmaps_map_allow").attr('value') == "point"
23
+ google.maps.event.addListener window.gmaps_marker, "click", (event) ->
24
+ latlng = event.latLng
25
+ window.geopoint_handle(latlng)
26
+
27
+ window.mapResize = ->
28
+ google.maps.event.trigger(window.gmaps_map, "resize");
29
+
30
+ window.geopoint_search_map = (dom) ->
31
+ addressField = $(dom)
32
+ geocoder = new google.maps.Geocoder()
33
+ geocoder.geocode {address: addressField.val()}, (results, status) ->
34
+ if status == google.maps.GeocoderStatus.OK
35
+ loc = results[0].geometry.location
36
+ window.gmaps_marker.setPosition(loc)
37
+ window.gmaps_map.setCenter(window.gmaps_marker.getPosition(), 16)
38
+ point = loc
39
+ window.geopoint_handle(point)
40
+
41
+ window.geopoint_handle = (attr)->
42
+ $("#gmaps_location_latitude").val(attr.lat())
43
+ $("#gmaps_location_longitude").val(attr.lng())
44
+ window.gmaps_marker.setPosition(attr)
45
+ geocoder = new google.maps.Geocoder()
46
+ if $("#gmaps_map_allow").attr('value') == "point"
47
+ window.gmaps_info_window.open(window.gmaps_map, window.gmaps_marker)
48
+ else
49
+
50
+ window.gmaps_info_window.setContent("Loading...")
51
+ geocoder.geocode {'latLng': attr}, (results, status) ->
52
+ if status == google.maps.GeocoderStatus.OK
53
+ if results[1]
54
+ window.gmaps_info_window.setContent(results[0].formatted_address)
55
+ $("#gmaps_location_address").val(results[0].formatted_address)
@@ -0,0 +1,10 @@
1
+ #map_canvas {
2
+ width: 1200px;
3
+ height: 500px;
4
+ margin: 0 auto;
5
+ border:1px solid green;
6
+ }
7
+
8
+ #data-location {
9
+ display:none;
10
+ }
@@ -0,0 +1,29 @@
1
+ module Gmaps::GmapsHelper
2
+
3
+ def google_map_api_js(key="AIzaSyA344yCug0-GhjW3XJyZmkLWLN_qtA_ziM")
4
+ javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=#{key}&sensor=false"
5
+ end
6
+
7
+ def show_map_helper(model, opts={})
8
+
9
+ # object = model_name.to_s.singularize.classify.constantize.find(params[:id])
10
+ object = model
11
+ model_name = model.class.to_s.downcase
12
+ @address = object.location_address
13
+ @latitude = object.location_latitude
14
+ @longitude = object.location_longitude
15
+ opts = {allow: 'show', searchbox: 'show', width: '800px', height: '400px', latitude: "#{@latitude}", longitude: "#{@longitude}", address: "#{@address}", zoom: 13, style: "border: 1px solid #green;", searchbox_width: '400px'}.merge(opts)
16
+ [
17
+ content_tag(:div, :id => "geopoint_search_box_container", style: " display: #{opts[:searchbox]}") do
18
+ tag(:input, type: :text, placeholder: 'Search', id: "gmaps_#{model_name}_search_box", style: "width: #{option[:searchbox_width]};")
19
+ end,
20
+ content_tag(:div, '', id: "map_canvas", style: "width: #{opts[:width]}; height: #{opts[:height]}; #{opts[:style]}"),
21
+ content_tag(:div, '', class: "data-location", data: {model: model_name, address:opts[:address], latitude: opts[:latitude] , longitude: opts[:longitude], zoom: opts[:zoom]}),
22
+ tag(:input, type: :hidden, value: "#{opts[:allow]}", name: "allow", id: "gmaps_map_allow"),
23
+ tag(:input, type: :hidden, value: "#{@latitude}", name: "#{model_name}[location_latitude]", id: "gmaps_location_latitude"),
24
+ tag(:input, type: :hidden, value: "#{@longitude}", name: "#{model_name}[location_longitude]", id: "gmaps_location_longitude"),
25
+ tag(:input, type: :hidden, value: "#{@address}", name: "#{model_name}[location_address]", id: "gmaps_location_address"),
26
+ javascript_tag("window.initJsMap();")
27
+ ].join.html_safe
28
+ end
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gmaps"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/gmaps.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gmaps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails-gmaps"
8
+ spec.version = Gmaps::VERSION
9
+ spec.authors = ["Luan D."]
10
+ spec.email = ["luan@lixibox.com"]
11
+
12
+ spec.summary = %q{Google Map for rails applications}
13
+ spec.description = %q{pick lat long, show lat long in map working in rails}
14
+ spec.homepage = "https://github.com/khacluan/gmaps"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActiveRecord
4
+ module Generators
5
+ class GmapsGenerator < ActiveRecord::Generators::Base
6
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ def copy_gmaps_migration
10
+ migration_template "migration.rb", "db/migrate/gmaps_add_columns_to_#{table_name}.rb"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ class GmapsAddColumnsTo<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def change
3
+ add_column :<%= table_name %>, :location_latitude, :float
4
+ add_column :<%= table_name %>, :location_longitude, :float
5
+ add_column :<%= table_name %>, :location_address, :string
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ module Gmaps
2
+ module Generators
3
+ class GmapsGenerator < Rails::Generators::NamedBase
4
+ include Rails::Generators::ResourceHelpers
5
+
6
+ namespace "gmaps"
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ desc "Generates Gmaps attributes for a model given its NAME."
10
+
11
+ hook_for :orm
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require 'securerandom'
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ module Gmaps
6
+ module Generators
7
+ class InstallGenerator < Rails::Generators::Base
8
+ include Rails::Generators::Migration
9
+
10
+ source_root File.expand_path("../../templates", __FILE__)
11
+ desc "Creates a Config file and copy locate files to your application."
12
+ class_option :orm
13
+
14
+ def copy_jsfile
15
+ ["locations.js.coffee"].each do |file|
16
+ copy_file "../../../app/assets/javascripts/#{file}", "app/assets/javascripts/#{file}"
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Gmaps
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gmaps.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "gmaps/version"
2
+
3
+ module Gmaps
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-gmaps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luan D.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-21 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ description: pick lat long, show lat long in map working in rails
42
+ email:
43
+ - luan@lixibox.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - app/assets/javascripts/locations.js.coffee
55
+ - app/assets/stylesheets/locations.scss
56
+ - app/helpers/gmaps/gmaps_helper.rb
57
+ - bin/console
58
+ - bin/setup
59
+ - gmaps.gemspec
60
+ - lib/generators/active_record/gmaps_generator.rb
61
+ - lib/generators/active_record/templates/migration.rb
62
+ - lib/generators/gmaps/gmaps_generator.rb
63
+ - lib/generators/gmaps/install_generator.rb
64
+ - lib/gmaps.rb
65
+ - lib/gmaps/version.rb
66
+ homepage: https://github.com/khacluan/gmaps
67
+ licenses:
68
+ - MIT
69
+ metadata:
70
+ allowed_push_host: https://rubygems.org
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Google Map for rails applications
91
+ test_files: []