google_maps_by_pete 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: 494e0d522b467a5257086be196c726a5832de561c4d9c5b43f6c20fcb51f0135
4
- data.tar.gz: 94a108f0fa5893f4c2c9b22287023f9f82017be0778cad6c49eb950e957258f5
3
+ metadata.gz: 419a07f23a0dadcf6aa04dbfb048c18b8ed441ccb63fb45be5c966784c58fdfc
4
+ data.tar.gz: 7502eff88f07582cdffa5b13232ff5c5f74a64c4e088a53e723a17b7a19c7170
5
5
  SHA512:
6
- metadata.gz: ca9238b3c0bd0b8fc99ef3ab697471f7a2d98cca8de199e411fed20373b3ef5380fb6479afbbb6c6c6bb950382203703058e39ee55db89b5d8e4c4b34c94bb2b
7
- data.tar.gz: bf05a8f6f2739802b749e27dd803d3303a4fc626fafaf86d02312d196122af340bf3d60a11a7bb74d7d0cedfb6e73ce791c5b6ef03b15249ac691f32127aa3e1
6
+ metadata.gz: 4e77e8685eddd34f00a5bc3c78323f5129f69f4e6f2d6e25da68156a366009a5f5be4c1a0848fec9b6d926544f5a444164b3a6f92caaa26b8839860a23e8557b
7
+ data.tar.gz: d37cd4229d7e0163f5ef11ceee20f1ad2caf9cdbe7c1ee9ab16c8ebcc46da6f2a13d4e903e45e22fbd79135d2eacea05ec224d98dcd58a59194ed77b893be2eb
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # Google Maps By Pete
1
+ # Ruby On Rails Google Maps By Pete
2
+
3
+ An agile way to implement Google Maps geolocation in a Ruby On Rails scaffold
4
+ ## Support
5
+
6
+ Ruby On Rails: 5, 6, 7
2
7
 
3
- An agile way to implement Google Maps localization on a scaffold in Ruby On Rails
4
8
  ## Installation
5
9
 
6
10
  Add this line to your application's Gemfile:
@@ -19,28 +23,62 @@ bundle install
19
23
  ## Usage
20
24
  Let's create a example for a Place scaffold:
21
25
 
22
- 1. Go to your application's directory in Terminal and run the command:
26
+ 1. Let's create a new rails app:
27
+
28
+ ```ruby
29
+ rails new myapp --database=postgresql
30
+ ```
31
+
32
+ 2. Create the database:
33
+
34
+ ```ruby
35
+ bundle exec rake db:create
36
+ ```
37
+
38
+ 3. Go to your application's directory in Terminal and run the command:
39
+
40
+ ```ruby
41
+ bundle exec rails g scaffold Place name:string description:text
42
+ ```
43
+
44
+ 4. Add this line to your application's Gemfile:
23
45
 
24
46
  ```ruby
25
- rails g scaffold Place name:string description:text
47
+ gem 'google_maps_by_pete'
26
48
  ```
27
- 2. Go to your application's directory in Terminal and run the command:
49
+
50
+ 5. Go to your application's directory in Terminal and run:
51
+
52
+ ```ruby
53
+ bundle install
54
+ ```
55
+
56
+ 6. Go to your application's directory in Terminal and run the command:
28
57
  ```ruby
29
58
  bundle exec rake 'install_google_maps_by_pete[Place]'
30
59
  ```
31
- 3. Add jQuery to your layout file:
60
+ 7. Add jQuery to your layout file: /app/views/layouts/application.html.erb
32
61
  ```html
33
62
  <script src='/google_maps_by_pete/jquery-3.6.0.min.js'></script>
34
63
  ```
35
- 4. Add maps.css to your layout file:
64
+ 8. Add maps.css to your layout file: /app/views/layouts/application.html.erb
36
65
  ```html
37
66
  <link rel='stylesheet' href='/google_maps_by_pete/maps.css'>
38
67
  ```
39
- 5. Add this to your _form.html.erb file:
68
+ 9. Paste this partial to your _form.html.erb file: /app/views/places/_form.html.erb
69
+
40
70
  ```ruby
41
71
  <%= render 'shared/google_maps_by_pete', api_key: 'your_google_api_key', height: '500px', center_map_on: {lat: 25.761681, lng: -80.191788}, model: place%>
42
72
  ```
43
73
 
74
+ 10. Allow parameters (lat and lng) in your controller: /app/controllers/places_controller.rb
75
+
76
+ ```ruby
77
+ def place_params
78
+ params.require(:place).permit(:name, :description, :lat, :lng)
79
+ end
80
+ ```
81
+
44
82
  ## Video Tutorial
45
83
 
46
84
  Watch this video to see how it works
@@ -51,8 +89,8 @@ Watch this video to see how it works
51
89
 
52
90
  ## Contributing
53
91
 
54
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/google_maps_by_pete. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/google_maps_by_pete/blob/master/CODE_OF_CONDUCT.md).
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/peterconsuegra/google_maps_by_pete. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/peterconsuegra/google_maps_by_pete/blob/master/CODE_OF_CONDUCT.md).
55
93
 
56
94
  ## Code of Conduct
57
95
 
58
- Everyone interacting in the GoogleMapsByPete project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/google_maps_by_pete/blob/master/CODE_OF_CONDUCT.md).
96
+ Everyone interacting in the GoogleMapsByPete project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/peterconsuegra/google_maps_by_pete/blob/master/CODE_OF_CONDUCT.md).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoogleMapsByPete
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -1,16 +1,40 @@
1
1
  require 'colorize'
2
-
2
+ require 'fileutils'
3
+ require "tty-file"
3
4
 
4
5
  module PeterConsuegraRecipes
5
6
 
6
7
  def self.move_templates(src_folder,dest_folder,files)
8
+ FileUtils.mkdir_p dest_folder
7
9
  files.each do |file_name|
8
- #puts "src_folder: #{src_folder} dest_folder: #{dest_folder}".blue
9
10
  FileUtils.cp(src_folder+file_name,dest_folder+file_name)
10
11
  puts "file copied to: #{dest_folder+file_name}".green
11
12
  end
12
13
  end
13
14
 
15
+ def self.move_template(src_folder,dest_folder,file)
16
+ FileUtils.mkdir_p dest_folder
17
+ FileUtils.cp src_folder+file,dest_folder+file
18
+ puts "File copied to: #{dest_folder+file}".green
19
+ end
20
+
21
+ def self.add_route(base_route,action_name,method)
22
+ rails_app_folder = Dir.pwd
23
+ route_file="#{rails_app_folder}/config/routes.rb"
24
+ route_code = "#{method} '/#{base_route}_#{action_name}', to: '#{base_route}##{action_name}'"
25
+ PeterConsuegraRecipes::append_before_last_appearance_of("end",route_code,route_file)
26
+ puts "Adding route: #{route_code}".blue
27
+ end
28
+
29
+ def self.add_concern_to_controller(code,controller_file,controller_class)
30
+ rails_app_folder = Dir.pwd
31
+ file="#{rails_app_folder}/app/controllers/#{controller_file}"
32
+ #puts "class #{controller_class} < ApplicationController"
33
+ #code="include FilesByPete\n"
34
+ TTY::File.inject_into_file file, code, after: "class #{controller_class} < ApplicationController\n"
35
+ puts "Adding concern to controller #{file}: #{code}".blue
36
+ end
37
+
14
38
  def self.append_before_last_appearance_of(string,code,file)
15
39
  File.open(file, 'r+') do |file|
16
40
  lines = file.each_line.to_a
@@ -37,7 +61,7 @@ module PeterConsuegraRecipes
37
61
  hash["controller_file"] = hash["table_name"]+"_controller.rb"
38
62
  hash["controller_class"] = hash["table_name"].titleize.gsub(' ','')+"Controller"
39
63
  hash["base_route"] = hash["table_name"]
40
- puts hash
64
+ #puts hash
41
65
  return hash
42
66
  end
43
67
 
@@ -1,68 +1,44 @@
1
1
  require_relative '../peterconsuegra_recipes'
2
- require 'fileutils'
3
- require "tty-file"
2
+ require 'colorize'
4
3
 
5
- #bundle exec rake 'install_google_maps_by_pete[place]'
4
+ #bundle exec rake 'install_google_maps_by_pete[model]'
6
5
 
7
- desc 'install_google_maps_by_pete required files'
6
+ desc 'install google_maps_by_pete required files'
8
7
  task :install_google_maps_by_pete, [:model] do |t, args|
9
8
 
10
- #require all models
9
+ #Require all models
11
10
  Dir.glob("#{Rails.root}/app/models/*.rb").each { |file| require file }
12
11
 
13
- #route files
12
+ #Folders path
14
13
  rails_app_folder = Dir.pwd
15
14
  gem_folder = File.expand_path('../../../.', __FILE__)
16
-
17
- #Get scaffold vars
18
- hash = PeterConsuegraRecipes::get_scaffold_vars(args[:model])
19
-
20
- #Templates folder
21
15
  src_folder="#{gem_folder}/templates/"
22
16
 
23
- #Adding partials
24
- dest_folder="#{rails_app_folder}/app/views/shared/"
25
- file="_google_maps_by_pete.html.erb"
26
- FileUtils.mkdir_p dest_folder
27
- FileUtils.cp src_folder+file,dest_folder+file
28
- puts "File copied to: #{dest_folder+file}".green
29
-
30
- #Adding concern
31
- dest_folder="#{rails_app_folder}/app/controllers/concerns/"
32
- file="maps_by_pete.rb"
33
- FileUtils.mkdir_p dest_folder
34
- FileUtils.cp src_folder+file,dest_folder+file
35
- puts "File copied to: #{dest_folder+file}".green
17
+ #Get scaffold vars
18
+ hash = PeterConsuegraRecipes::get_scaffold_vars(args[:model])
36
19
 
37
- #Copy maps.css file
38
- dest_folder="#{rails_app_folder}/public/google_maps_by_pete/"
39
- file="maps.css"
40
- FileUtils.mkdir_p dest_folder
41
- FileUtils.cp src_folder+file,dest_folder+file
42
- puts "File copied to: #{dest_folder+file}".green
20
+ #Adding partial
21
+ PeterConsuegraRecipes::move_template(src_folder,"#{rails_app_folder}/app/views/shared/","_google_maps_by_pete.html.erb")
22
+
23
+ #Adding concern file
24
+ PeterConsuegraRecipes::move_template(src_folder,"#{rails_app_folder}/app/controllers/concerns/","maps_by_pete.rb")
43
25
 
44
- #Copy jquery-3.6.0.min.js file
45
- dest_folder="#{rails_app_folder}/public/google_maps_by_pete/"
46
- file="jquery-3.6.0.min.js"
47
- FileUtils.mkdir_p dest_folder
48
- FileUtils.cp src_folder+file,dest_folder+file
49
- puts "File copied to: #{dest_folder+file}".green
50
-
51
- #Adding route to routes.rb
52
- file="#{rails_app_folder}/config/routes.rb"
53
- code = "post '/#{hash['base_route']}/set_location', to: '#{hash['base_route']}#set_location'"
54
- PeterConsuegraRecipes::append_before_last_appearance_of("end",code,file)
55
- puts "Adding route: #{code}".blue
26
+ #Adding js and css assets
27
+ PeterConsuegraRecipes::move_templates(src_folder,"#{rails_app_folder}/public/google_maps_by_pete/",["jquery-3.6.0.min.js","maps.css"])
28
+
29
+ #Adding route
30
+ PeterConsuegraRecipes::add_route(hash['base_route'],"set_location","post")
56
31
 
57
- #Adding include GoogleMapsByPete in Controller
58
- file="#{rails_app_folder}/app/controllers/#{hash['controller_file']}"
59
- code="include MapsByPete\n"
60
- TTY::File.inject_into_file file, code, after: "class #{hash['controller_class']} < ApplicationController\n"
61
- puts "Adding concern to controller #{file}: include MapsByPete".blue
32
+ #Adding concern to controller
33
+ PeterConsuegraRecipes::add_concern_to_controller("include MapsByPete\n",hash['controller_file'],hash['controller_class'])
62
34
 
63
- #Add required migration
35
+ #Adding lat and lng fields to model
36
+ puts "Running command:".blue
37
+ puts "rails generate migration AddFieldsTo#{hash['model_class']} lat:decimal{10-6} lng:decimal{10-6}".green
64
38
  `rails generate migration AddFieldsTo#{hash['model_class']} lat:decimal{10-6} lng:decimal{10-6}`
65
39
  sleep 2
40
+ puts "Running command:".blue
41
+ puts "rake db:migrate".green
66
42
  `rake db:migrate`
67
43
 
68
44
  #Print necessary code
@@ -73,10 +49,9 @@ task :install_google_maps_by_pete, [:model] do |t, args|
73
49
  puts "<script src='/google_maps_by_pete/jquery-3.6.0.min.js'></script>".red
74
50
  puts "Add maps.css to your layout file:".red
75
51
  puts "<link rel='stylesheet' href='/google_maps_by_pete/maps.css'>".red
76
- puts "Add this to your _form.html.erb file:".red
52
+ puts "Add this partial to your _form.html.erb file:".red
77
53
  puts "<%= render 'shared/google_maps_by_pete', api_key: 'your_google_api_key', height: '500px', center_map_on: {lat: 25.761681, lng: -80.191788}, model: #{hash['model'].downcase}%>".red
78
- puts "Allow lat and lng params in your controller #{hash['controller_file']}:".red
54
+ puts "Allow :lat and :lng params in your controller #{hash['controller_file']}:".red
79
55
  puts "params.require(:#{hash['model'].downcase}).permit(:lat, :lng)".red
80
-
81
56
 
82
57
  end
@@ -8,7 +8,8 @@
8
8
  <%center_map_on_lng = -80.191788%>
9
9
  <%end%>
10
10
 
11
-
11
+ <%table_name = model.class.table_name%>
12
+ <%set_location_route = "/#{table_name}_set_location"%>
12
13
 
13
14
  <div id="type-selector" class="controls">
14
15
  <input type="radio" name="type" id="changetype-all" checked="checked">
@@ -117,7 +118,7 @@
117
118
 
118
119
  //Save model lat and lng
119
120
  <%if defined? model%>
120
- set_location("/<%=model.class.name.downcase%>s/set_location",marker.position.lat(),marker.position.lng(),"<%=model.class.name%>",<%=model.id%>)
121
+ set_location("<%=set_location_route%>",marker.position.lat(),marker.position.lng(),"<%=model.class.name%>",<%=model.id%>)
121
122
  <%end%>
122
123
 
123
124
  infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_maps_by_pete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Consuegra
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-29 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -55,7 +55,6 @@ files:
55
55
  - Rakefile
56
56
  - bin/console
57
57
  - bin/setup
58
- - google_maps_by_pete-0.1.41.gem
59
58
  - google_maps_by_pete.gemspec
60
59
  - lib/.DS_Store
61
60
  - lib/google_maps_by_pete.rb
Binary file