full_country_select 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +53 -0
- data/Rakefile +26 -0
- data/app/assets/config/full_country_select_manifest.js +1 -0
- data/app/assets/javascripts/full_country_select/api.coffee +26 -0
- data/app/assets/javascripts/full_country_select/application.js +13 -0
- data/app/controllers/full_country_select/api_controller.rb +13 -0
- data/app/controllers/full_country_select/application_controller.rb +5 -0
- data/app/helpers/full_country_select/api_helper.rb +17 -0
- data/app/helpers/full_country_select/application_helper.rb +4 -0
- data/config/routes.rb +4 -0
- data/lib/full_country_select.rb +5 -0
- data/lib/full_country_select/engine.rb +9 -0
- data/lib/full_country_select/version.rb +3 -0
- data/lib/generators/full_country_select/install_generator.rb +26 -0
- data/lib/tasks/full_country_select_tasks.rake +4 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 10eaa4bff03b1965a5faaab53237e2d3cb0cc334
|
4
|
+
data.tar.gz: fa0e97c019124e7d50e5e60a3b2fd5d47674255a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 07ec953d5052e539807b295a345fa90f99bcdab65af07594fb93a62e48634fc0540c9b4ddfa085e11312a64dd96c7d9017f3376edec1efb4b466d375a554ea2a
|
7
|
+
data.tar.gz: 2be43b75fbab2b05f05832514b76687c37c4cbd1723fc53b24bf2e84a14abaf9101b3a2cb184092c950b08c99224888d6e0a807dcb5c4cf9eeb73dcedd9e6bfb
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Igor
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# FullCountrySelect
|
2
|
+
Gems adds dynamic functionality for 'city-state' gem. For example, you choose
|
3
|
+
some country and automatically you receive all states for that country, then
|
4
|
+
you choose state and receive all cities for that state using ajax.
|
5
|
+
All databases are taken from MaxMind.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your Rails application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'full_country_select'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
Then you should run generator **rails g full_country_select:install** which will add
|
19
|
+
routes, helpers and assets to your app.
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
```bash
|
23
|
+
$ gem install full_country_select
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
Your form should include the following params and ids: :country, :state, :city.
|
28
|
+
For example(search form):
|
29
|
+
|
30
|
+
= form_tag(some_path) do
|
31
|
+
|
32
|
+
= select_tag(:country, options_for_select(get_countries),{class: 'form-control', include_blank: true})
|
33
|
+
|
34
|
+
= select_tag(:state, {}, {class: 'form-control'})
|
35
|
+
|
36
|
+
= select_tag(:city, {}, {class: 'form-control'})
|
37
|
+
|
38
|
+
If you want to use country select for objects and to get selected one from db, you should do like that:
|
39
|
+
|
40
|
+
= form_for @object do |f|
|
41
|
+
|
42
|
+
= f.select :country, get_countries, {}, id: 'country'
|
43
|
+
|
44
|
+
= f.select :state, selected_state(@object), {}, id: 'state'
|
45
|
+
|
46
|
+
= f.select :city, selected_city(@object), {}, id: 'city'
|
47
|
+
|
48
|
+
You have the following helpers: get_countries - returns countries list, selected_state and
|
49
|
+
selected_city - helpers that require your object and return selected value. Of course, your object
|
50
|
+
should include fields: country(string), state(string), city(integer).
|
51
|
+
|
52
|
+
## Example
|
53
|
+
[link to Example!] (https://jobbber.herokuapp.com/jobs)
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'FullCountrySelect'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link_directory ../javascripts/full_country_select .js
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$(document).on 'turbolinks:load ready', ->
|
2
|
+
|
3
|
+
build_select = (resource, data) ->
|
4
|
+
resource.empty()
|
5
|
+
resource.append('<option></option')
|
6
|
+
$.each data, (i, item) ->
|
7
|
+
resource.append $('<option>',
|
8
|
+
value: i
|
9
|
+
text: item)
|
10
|
+
return
|
11
|
+
|
12
|
+
get_states = (state, obj) ->
|
13
|
+
$.post '/full_country_select/get_states/' + obj.val(), (data) ->
|
14
|
+
build_select(state, data)
|
15
|
+
|
16
|
+
get_cities = (country, city, obj) ->
|
17
|
+
$.post '/full_country_select/get_cities/' + country + '/' + obj.val(), (data) ->
|
18
|
+
build_select(city, data)
|
19
|
+
|
20
|
+
$('#country').on "change", ->
|
21
|
+
$('#city').empty()
|
22
|
+
get_states($('#state'), $(this))
|
23
|
+
|
24
|
+
$('#state').on 'change', ->
|
25
|
+
country = $('#country').val()
|
26
|
+
get_cities(country, $('#city'), $(this))
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_dependency "full_country_select/application_controller"
|
2
|
+
|
3
|
+
module FullCountrySelect
|
4
|
+
class ApiController < ApplicationController
|
5
|
+
def get_states
|
6
|
+
render json: CS.get(params[:country])
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_cities
|
10
|
+
render json: CS.get(params[:country], params[:state])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module FullCountrySelect
|
2
|
+
module ApiHelper
|
3
|
+
def get_countries
|
4
|
+
CS.get.invert
|
5
|
+
end
|
6
|
+
|
7
|
+
def selected_state(obj)
|
8
|
+
return {} unless obj.country
|
9
|
+
CS.get(obj.country).invert
|
10
|
+
end
|
11
|
+
|
12
|
+
def selected_city(obj)
|
13
|
+
return {} unless obj.country
|
14
|
+
CS.get(obj.country, obj.state).map.with_index{|v, k| [v, k]}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module FullCountrySelect
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
desc 'Mount routes.'
|
4
|
+
def mount_routes
|
5
|
+
inject_into_file 'config/routes.rb', before: "root" do
|
6
|
+
"mount FullCountrySelect::Engine => '/full_country_select'\n"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Adds helper to app controller.'
|
11
|
+
|
12
|
+
def add_helper
|
13
|
+
inject_into_file 'app/controllers/application_controller.rb', after: "exception" do
|
14
|
+
"\nhelper FullCountrySelect::ApiHelper"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Adds assets.'
|
19
|
+
|
20
|
+
def add_assets
|
21
|
+
inject_into_file 'app/assets/javascripts/application.js', after: "jquery_ujs" do
|
22
|
+
"\n//= require full_country_select/api"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: full_country_select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: city-state
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Adds dynamic search for countries, states and cities.
|
42
|
+
email:
|
43
|
+
- igor12306@mail.ru
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/assets/config/full_country_select_manifest.js
|
52
|
+
- app/assets/javascripts/full_country_select/api.coffee
|
53
|
+
- app/assets/javascripts/full_country_select/application.js
|
54
|
+
- app/controllers/full_country_select/api_controller.rb
|
55
|
+
- app/controllers/full_country_select/application_controller.rb
|
56
|
+
- app/helpers/full_country_select/api_helper.rb
|
57
|
+
- app/helpers/full_country_select/application_helper.rb
|
58
|
+
- config/routes.rb
|
59
|
+
- lib/full_country_select.rb
|
60
|
+
- lib/full_country_select/engine.rb
|
61
|
+
- lib/full_country_select/version.rb
|
62
|
+
- lib/generators/full_country_select/install_generator.rb
|
63
|
+
- lib/tasks/full_country_select_tasks.rake
|
64
|
+
homepage: https://github.com/rockandruby/full_country_select
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.5.1
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Country/State/City select list.
|
88
|
+
test_files: []
|