countries_regions_and_cities_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: 3d6f46cb706a9aef6154eecf7809c20ef0b3829f428979b15aeacd3994023823
4
- data.tar.gz: 3789e83e4c2bfcdc6da49d9d46e00a0bee1b6588bc279da69da5209941bb2d55
3
+ metadata.gz: 57e8bde7c5523da1f52564b022c232b4dc13728f33600e4f6a85ea1885f34b90
4
+ data.tar.gz: 6ba904136481ac3d88b6ecb0174c9df71e11a9672c12a50ccb7c4961a9e58606
5
5
  SHA512:
6
- metadata.gz: 66b5536f6e9b28ba7299c330a9ffeabf8445a795bd4a69c07849e5b0ca2e6b2435f619669d38565079c6bf760b0ca47b55626226bebf11ee9a5f308a221cc130
7
- data.tar.gz: eac164cc1b10bb6fa4c031a760ed25f85b801e34040e5aaf0f3a1e9cd2ef63589e6380708fa17782ff406f2a6f82549be851f90b470212108c4abdcfa98f74b0
6
+ metadata.gz: 62b5e5902d714708e7ab15582993a9b6d59918a2454bdd97dfc77d56ad1cb8bf2da64cc8f200740dbecf300e3d34f632cffbb67b18c40447ce4f44914db5269a
7
+ data.tar.gz: 35f1d34399bf14c6334eb22619324582f87b440b2da385d7f8d47c6a63295f7e4b9b213b7558ad20e343a73065a8ab1351c3de78ddedabce27fc44c223c52ac6
data/README.md CHANGED
@@ -1,55 +1,78 @@
1
- # Countries Regions And Cities By Peter Consuegra
1
+ # Ruby On Rails Countries, Regions and Cities by Pete
2
2
 
3
- An agile way to implement Countries, Regions and Cities in your project, without the need to create additional tables
3
+ An agile way to implement Countries, Regions, and Cities in a Ruby On Rails scaffold without the need to create additional tables
4
+
5
+ ## Support
6
+
7
+ Ruby On Rails: 5, 6, 7
4
8
 
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
8
12
 
9
13
  ```ruby
10
- gem 'countries_regions_and_cities_by_peterconsuegra', '>= 0.2.5'
14
+ gem 'countries_regions_and_cities_by_pete'
11
15
  ```
12
16
 
13
17
  And then execute:
14
18
 
15
19
  $ bundle install
16
20
 
17
- Add the jquery.min.js file to the layout you are using: /app/views/layouts/application.html.erb
18
21
 
19
- ```javascript
20
- <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
22
+ ## Usage
23
+ Let's create a example for a Place scaffold:
24
+
25
+ 1. Let's create a new rails app:
26
+
27
+ ```ruby
28
+ rails new myapp
21
29
  ```
22
30
 
23
- Run the rake command to generate the necessary files:
31
+ 2. Create the database:
24
32
 
25
- $ bundle exec rake 'install_countries_regions_and_cities_to_model[your_model_name]'
33
+ ```ruby
34
+ bundle exec rake db:create
35
+ ```
26
36
 
27
- Allow the following trusted parameters: country, region, city in your model controller. Example:
37
+ 3. Go to the application directory in Terminal and run the following command to create a scaffold for the Place model:
28
38
 
29
39
  ```ruby
30
- # Example: Only allow a list of trusted parameters through.
31
- def hotel_params
32
- params.require(:hotel).permit(:name, :description, :address, :country, :region, :city)
33
- end
40
+ bundle exec rails g scaffold Place name:string description:text
34
41
  ```
35
42
 
36
- Add this code to the _form.html.erb partial of your_model_name form
43
+ 4. Go to the application directory in Terminal and run the following command to install the necessary files from the gem:
44
+
37
45
 
46
+ ```ruby
47
+ bundle exec rake 'install_countries_regions_and_cities_by_pete[Place]'
38
48
  ```
39
49
 
40
- <div class="field" id="country_field">
41
- <%= render partial: 'shared/peterconsuegra_country_select', locals: {model: form.object.class.name.downcase, label: "Country", selected: form.object.country} %>
42
- </div>
50
+ 5. Add jQuery to your layout file: /app/views/layouts/application.html.erb
43
51
 
44
- <div class="field" id="region_field">
45
- <%= render partial: 'shared/peterconsuegra_region_select', locals: {model: form.object.class.name.downcase, label: "Region / State", selected_country: form.object.country, selected: form.object.region} %>
46
- </div>
52
+ ```html
53
+ <script src='/countries_regions_and_cities_by_pete/jquery-3.6.0.min.js'></script>
54
+ ```
55
+
56
+ 6. Paste this code to your _form.html.erb file: /app/views/places/_form.html.erb
57
+ ```ruby
47
58
 
48
- <div class="field" id="city_field">
49
- <%= render partial: 'shared/peterconsuegra_city_select', locals: {model: form.object.class.name.downcase, label: "City", selected_region: form.object.region, selected_country: form.object.country, selected: form.object.city} %>
50
- </div>
59
+ <div class="field" id="country_field">
60
+ <%= render partial: "shared/country_select_by_pete", locals: {model: form.object.class.name, label: "Country", selected: form.object.country} %>
61
+ </div>
62
+ <div class="field" id="region_field">
63
+ <%= render partial: "shared/region_select_by_pete", locals: {model: form.object.class.name, label: "Region / State", selected_country: form.object.country, selected: form.object.region} %>
64
+ </div>
65
+ <div class="field" id="city_field">
66
+ <%= render partial: "shared/city_select_by_pete", locals: {model: form.object.class.name, label: "City", selected_region: form.object.region, selected_country: form.object.country, selected: form.object.city} %>
67
+ </div>
51
68
 
69
+ ```
70
+ 7. Allow parameters (country,region and city) in your controller: /app/controllers/places_controller.rb
52
71
 
72
+ ```ruby
73
+ def place_params
74
+ params.require(:place).permit(:name, :description, :address, :country, :region, :city)
75
+ end
53
76
  ```
54
77
 
55
78
  Video Tutorial
@@ -57,15 +80,12 @@ Video Tutorial
57
80
 
58
81
  Watch this video to see how it works
59
82
 
60
- [![IMAGE ALT TEXT HERE](https://ozonegroup.co/countries_regions_and_cities.png)](https://www.youtube.com/watch?v=VrIVdsOnJsY)
61
-
62
-
63
-
83
+ [![IMAGE ALT TEXT HERE](https://ozonegroup.co/countries_regions_and_cities.png)](https://www.youtube.com/watch?v=mSwfFtYE8HE)
64
84
 
65
85
  ## Contributing
66
86
 
67
- Bug reports and pull requests are welcome on GitHub at https://github.com/peterconsuegra/countries_regions_and_cities. 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]/countries_regions_and_cities_by_peterconsuegra/blob/master/CODE_OF_CONDUCT.md).
87
+ Bug reports and pull requests are welcome on GitHub at https://github.com/peterconsuegra/countries_regions_and_cities. 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/countries_regions_and_cities_by_peterconsuegra/blob/master/CODE_OF_CONDUCT.md).
68
88
 
69
89
  ## Code of Conduct
70
90
 
71
- Everyone interacting in the CountriesRegionsAndCitiesByPeterconsuegra project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/countries_regions_and_cities_by_peterconsuegra/blob/master/CODE_OF_CONDUCT.md).
91
+ Everyone interacting in the CountriesRegionsAndCitiesByPeterconsuegra project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/peterconsuegra/countries_regions_and_cities_by_peterconsuegra/blob/master/CODE_OF_CONDUCT.md).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CountriesRegionsAndCitiesByPete
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
 
@@ -12,47 +12,28 @@ task :install_countries_regions_and_cities_by_pete, [:model] do |t, args|
12
12
  #Base routes
13
13
  rails_app_folder = Dir.pwd
14
14
  gem_folder = File.expand_path('../../../.', __FILE__)
15
+ src_folder="#{gem_folder}/templates/"
15
16
 
16
17
  #Get scaffold vars
17
18
  hash = PeterConsuegraRecipes::get_scaffold_vars(args[:model])
18
19
 
19
- #Adding partials
20
- dest_folder="#{rails_app_folder}/app/views/shared/"
21
- src_folder="#{gem_folder}/templates/"
22
- files=["_city_select_by_pete.html.erb","_country_select_by_pete.html.erb","_region_select_by_pete.html.erb"]
23
- FileUtils.mkdir_p dest_folder
24
- PeterConsuegraRecipes::move_templates(src_folder,dest_folder,files)
20
+ #Adding partials
21
+ PeterConsuegraRecipes::move_templates(src_folder,"#{rails_app_folder}/app/views/shared/",["_city_select_by_pete.html.erb","_country_select_by_pete.html.erb","_region_select_by_pete.html.erb"])
25
22
 
26
23
  #Adding concern
27
- dest_folder="#{rails_app_folder}/app/controllers/concerns/"
28
- file="globalization_by_pete.rb"
29
- FileUtils.mkdir_p dest_folder
30
- FileUtils.cp src_folder+file,dest_folder+file
31
- puts "File copied to: #{dest_folder+file}".green
32
-
33
- #Copy jquery-3.6.0.min.js file
34
- dest_folder="#{rails_app_folder}/public/countries_regions_and_cities_by_pete/"
35
- file="jquery-3.6.0.min.js"
36
- FileUtils.mkdir_p dest_folder
37
- FileUtils.cp src_folder+file,dest_folder+file
38
- puts "File copied to: #{dest_folder+file}".green
39
-
40
- #Adding route to routes.rb
41
- file="#{rails_app_folder}/config/routes.rb"
42
- route1 = "get '/#{hash['base_route']}_get_regions', to: '#{hash['base_route']}#get_regions'"
43
- route2 = "get '/#{hash['base_route']}_get_cities', to: '#{hash['base_route']}#get_cities'"
44
- PeterConsuegraRecipes::append_before_last_appearance_of("end",route1,file)
45
- PeterConsuegraRecipes::append_before_last_appearance_of("end",route2,file)
46
- puts "Adding route: #{route1}".blue
47
- puts "Adding route: #{route2}".blue
48
-
49
- #Adding include GlobalizationByPete in Controller
50
- file="#{rails_app_folder}/app/controllers/#{hash['controller_file']}"
51
- puts "class #{hash['controller_class']} < ApplicationController"
52
- code="include GlobalizationByPete\n"
53
- TTY::File.inject_into_file file, code, after: "class #{hash['controller_class']} < ApplicationController\n"
54
- puts "Adding concern to controller #{file}: include GlobalizationByPete".blue
55
-
24
+ PeterConsuegraRecipes::move_template(src_folder,"#{rails_app_folder}/app/controllers/concerns/","globalization_by_pete.rb")
25
+
26
+ #Adding jQuery
27
+ PeterConsuegraRecipes::move_template(src_folder,"#{rails_app_folder}/public/countries_regions_and_cities_by_pete/","jquery-3.6.0.min.js")
28
+
29
+ #Adding route to routes.rb
30
+ PeterConsuegraRecipes::add_route(hash['base_route'],"get_regions","get")
31
+ PeterConsuegraRecipes::add_route(hash['base_route'],"get_cities","get")
32
+
33
+ #Adding concern to controller
34
+ PeterConsuegraRecipes::add_concern_to_controller("include GlobalizationByPete\n",hash['controller_file'],hash['controller_class'])
35
+
36
+ #Adding migration
56
37
  `rails generate migration AddFieldsTo#{hash['model_class']} country:string region:string city:string`
57
38
  sleep 2
58
39
  `rake db:migrate`
@@ -76,7 +57,7 @@ task :install_countries_regions_and_cities_by_pete, [:model] do |t, args|
76
57
  puts ' <div class="field" id="city_field">
77
58
  <%= render partial: "shared/city_select_by_pete", locals: {model: form.object.class.name, label: "City", selected_region: form.object.region, selected_country: form.object.country, selected: form.object.city} %>
78
59
  </div>'.red
79
- puts "Allow globalization params in your controller #{hash['controller_file']}:".red
60
+ puts "Allow countries_regions_and_cities_by_pete globalization params in your controller #{hash['controller_file']}:".red
80
61
  puts "params.require(:#{hash['model']}).permit(:city, :region, :country)".red
81
62
 
82
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: countries_regions_and_cities_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-27 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: carmen
@@ -84,8 +84,6 @@ files:
84
84
  - Rakefile
85
85
  - bin/console
86
86
  - bin/setup
87
- - countries_regions_and_cities_by_pete-0.1.26.gem
88
- - countries_regions_and_cities_by_pete-0.1.7.gem
89
87
  - countries_regions_and_cities_by_pete.gemspec
90
88
  - countries_regions_and_cities_by_peterconsuegra-0.2.5.gem
91
89
  - lib/countries_regions_and_cities_by_pete.rb