countries_regions_and_cities_by_peterconsuegra 0.2.0 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +33 -12
- data/lib/countries_regions_and_cities_by_peterconsuegra/version.rb +1 -1
- data/lib/peterconsuegra_recipes.rb +2 -0
- data/lib/tasks/install_countries_regions_and_cities.rake +5 -2
- data/templates/_peterconsuegra_city_select.html.erb +1 -1
- data/templates/_peterconsuegra_country_select.html.erb +9 -10
- data/templates/_peterconsuegra_region_select.html.erb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c98927b759e582fb6de9b590ce6e93628073ca2b76be0b80a0c4a17de60962cf
|
4
|
+
data.tar.gz: 398e821986ac1f8adecbf4c834c3d482a205d54b88d6f2e84a97e71450000a9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c287be78aa49baff9889d848ee1ad5a4eeaa9fa938fa5d28f08a2475e97c9b6ebfe5a8ea8b149694aaddabd052066dcbb75ff54bca74d99c9ed2abe53efa5894
|
7
|
+
data.tar.gz: 07b8184e619580ac06653b40456ca8ba511b53c14f4d5a02a130672e5969c907a02bae1e4368f080a9b41f73690a744e036b943cb0ad6bd2aac8016d5f2101ba
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
countries_regions_and_cities_by_peterconsuegra (0.
|
4
|
+
countries_regions_and_cities_by_peterconsuegra (0.2.5)
|
5
5
|
carmen (~> 1.1.3)
|
6
6
|
city-state (~> 0.1.0)
|
7
|
+
colorize (~> 0.8.0)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
@@ -19,6 +20,7 @@ GEM
|
|
19
20
|
activesupport (>= 3.0.0)
|
20
21
|
city-state (0.1.0)
|
21
22
|
rubyzip (>= 1.1)
|
23
|
+
colorize (0.8.1)
|
22
24
|
concurrent-ruby (1.1.9)
|
23
25
|
i18n (1.8.11)
|
24
26
|
concurrent-ruby (~> 1.0)
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Countries Regions And Cities By Peter Consuegra
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
An agile way to implement Countries, Regions and Cities in your project, without the need to create additional tables
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -16,23 +14,46 @@ And then execute:
|
|
16
14
|
|
17
15
|
$ bundle install
|
18
16
|
|
19
|
-
|
17
|
+
Run the rake command to generate the necessary files:
|
18
|
+
|
19
|
+
$ bundle exec rake 'install_countries_regions_and_cities_to_model[your_model_name]'
|
20
|
+
|
21
|
+
|
22
|
+
Rails
|
23
|
+
===============
|
24
|
+
|
25
|
+
Add this code to the _form.html.erb partial of your_model_name form
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
<div class="field" id="country_field">
|
30
|
+
<%= render partial: 'shared/peterconsuegra_country_select', locals: {model: form.object.class.name.downcase, label: "Country", selected: form.object.country} %>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<div class="field" id="region_field">
|
34
|
+
<%= 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} %>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<div class="field" id="city_field">
|
38
|
+
<%= 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} %>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
|
42
|
+
```
|
20
43
|
|
21
|
-
|
44
|
+
Video Tutorial
|
45
|
+
===============
|
22
46
|
|
23
|
-
|
47
|
+
Watch this video to see how it works
|
24
48
|
|
25
|
-
|
49
|
+
[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](https://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE)
|
26
50
|
|
27
|
-
## Development
|
28
51
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
52
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
53
|
|
33
54
|
## Contributing
|
34
55
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
56
|
+
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).
|
36
57
|
|
37
58
|
## Code of Conduct
|
38
59
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'colorize'
|
2
2
|
|
3
|
+
|
3
4
|
module PeterConsuegraRecipes
|
4
5
|
|
5
6
|
def self.move_templates(src_folder,dest_folder,files)
|
6
7
|
files.each do |file_name|
|
8
|
+
#puts "src_folder: #{src_folder} dest_folder: #{dest_folder}".blue
|
7
9
|
FileUtils.cp(src_folder+file_name,dest_folder+file_name)
|
8
10
|
puts "file copied to: #{dest_folder+file_name}".green
|
9
11
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative '../peterconsuegra_recipes'
|
2
|
-
|
2
|
+
require 'fileutils'
|
3
3
|
#bundle exec rake 'install_countries_regions_and_cities_to_model[place]'
|
4
4
|
|
5
5
|
desc 'install countries_regions_and_cities required files'
|
@@ -8,10 +8,14 @@ task :install_countries_regions_and_cities_to_model, [:model] do |t, args|
|
|
8
8
|
rails_app_folder = Dir.pwd
|
9
9
|
gem_folder = File.expand_path('../../../.', __FILE__)
|
10
10
|
|
11
|
+
puts "rails_app_folder: #{rails_app_folder}"
|
12
|
+
puts "gem_folder: #{gem_folder}"
|
13
|
+
|
11
14
|
#adding partials
|
12
15
|
dest_folder="#{rails_app_folder}/app/views/shared/"
|
13
16
|
src_folder="#{gem_folder}/templates/"
|
14
17
|
files=["_peterconsuegra_city_select.html.erb","_peterconsuegra_country_select.html.erb","_peterconsuegra_region_select.html.erb"]
|
18
|
+
FileUtils.mkdir_p dest_folder
|
15
19
|
PeterConsuegraRecipes::move_templates(src_folder,dest_folder,files)
|
16
20
|
|
17
21
|
#adding controller
|
@@ -25,7 +29,6 @@ task :install_countries_regions_and_cities_to_model, [:model] do |t, args|
|
|
25
29
|
PeterConsuegraRecipes::append_before_last_appearance_of("end",'get "get_cities", to: "peterconsuegra_countries_regions_and_cities#get_cities"',file)
|
26
30
|
|
27
31
|
#adding migration to model
|
28
|
-
puts "table name:"
|
29
32
|
model = args[:model]
|
30
33
|
model = model.capitalize
|
31
34
|
|
@@ -8,6 +8,6 @@
|
|
8
8
|
|
9
9
|
<% if cities %>
|
10
10
|
<label><%=label%></label><br />
|
11
|
-
<%= select_tag "#{model}[city]", options_for_select(cities, selected), include_blank: true %>
|
11
|
+
<%= select_tag "#{model}[city]", options_for_select(cities, selected), include_blank: true, id: "city" %>
|
12
12
|
<% end %>
|
13
13
|
</div>
|
@@ -2,16 +2,15 @@
|
|
2
2
|
|
3
3
|
<div id="country_code_wrapper">
|
4
4
|
<label><%=label%></label><br />
|
5
|
-
<%= select_tag "#{model}[country]", options_for_select(country_options_array.sort_by{|c| c.name}.map{|c| [c.name, c.code]}, selected), include_blank: true %>
|
5
|
+
<%= select_tag "#{model}[country]", options_for_select(country_options_array.sort_by{|c| c.name}.map{|c| [c.name, c.code]}, selected), include_blank: true, id: "country" %>
|
6
6
|
</div>
|
7
7
|
|
8
8
|
<script>
|
9
9
|
|
10
|
-
function
|
10
|
+
function region_select_logic(){
|
11
11
|
|
12
|
-
$('select#
|
13
|
-
|
14
|
-
selected_country = $('select#<%=model%>_country').val();
|
12
|
+
$('select#region').change(function(event) {
|
13
|
+
selected_country = $('select#country').val();
|
15
14
|
selected_region = $(this).val();
|
16
15
|
locale = $('.locale').data('locale')
|
17
16
|
url = "/get_cities?selected_country=" + selected_country + "&selected_region=" + selected_region + "&model=<%=model%>"
|
@@ -22,18 +21,18 @@
|
|
22
21
|
|
23
22
|
$(function() {
|
24
23
|
|
25
|
-
$('select#
|
24
|
+
$('select#country').change(function(event) {
|
26
25
|
|
27
26
|
selected_country = $(this).val();
|
28
|
-
$('select
|
29
|
-
locale = $('.locale').data('locale')
|
27
|
+
$('select#city').val("");
|
28
|
+
//locale = $('.locale').data('locale')
|
30
29
|
url = "/get_regions?selected_country=" + selected_country + "&model=<%=model%>"
|
31
30
|
$('#region_field').load(url, function() {
|
32
|
-
|
31
|
+
region_select_logic();
|
33
32
|
});
|
34
33
|
})
|
35
34
|
|
36
|
-
|
35
|
+
region_select_logic();
|
37
36
|
|
38
37
|
})
|
39
38
|
</script>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<%
|
8
8
|
# byebug
|
9
9
|
%>
|
10
|
-
<%= select_tag "#{model}[region]", options_for_select(regions.sort_by{|c| c.name}.map{|c| [c.name, c.code]}, selected), include_blank: true %>
|
10
|
+
<%= select_tag "#{model}[region]", options_for_select(regions.sort_by{|c| c.name}.map{|c| [c.name, c.code]}, selected), include_blank: true, id: "region" %>
|
11
11
|
<% end %>
|
12
12
|
</div>
|
13
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: countries_regions_and_cities_by_peterconsuegra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
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-
|
11
|
+
date: 2021-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carmen
|