china_regions 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -0
- data/LICENSE +19 -2
- data/README.md +31 -28
- data/README.zh.md +117 -0
- data/app/assets/javascripts/region_select.js +2 -1
- data/app/models/city.rb +3 -3
- data/app/models/district.rb +3 -3
- data/app/models/province.rb +1 -1
- data/config/locales/en.yml +1 -1
- data/lib/china_regions/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4de2d9eced27245300d96f23af7e9e5499374f789c975631acbcc286b33c2fb
|
4
|
+
data.tar.gz: eae0d2259e6e32d3557a3f78441ff040c9b271244573f792cfe4f764de55ef72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48da9ff3cb7646afb56e391cde3de6d8f721c324f0a4e508b57c6fdeb64dd44445cc466767c76287fce7a898757b75e8da421f94d2858ae11c302935d8a23d96
|
7
|
+
data.tar.gz: 70ef8dd05114aad397f1612c06f6c7df60ba57caafcf4f7a97e9a6f7d63769fc26f11a93b7aecb87dafc3d84dece439a1679f519c21d7cdc1800667d00784d59
|
data/.travis.yml
ADDED
data/LICENSE
CHANGED
@@ -1,5 +1,22 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2015 Encore Shao
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
5
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# ChinaRegions
|
2
2
|
|
3
|
-
|
3
|
+
Chinese provinces, cities, regions [prefecture-level cities] Ruby on Rails code, Ruby (> 1.9.x) And Rails (> 4.0)
|
4
4
|
|
5
|
-
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/crunchbase-ruby-library.svg)](https://badge.fury.io/rb/crunchbase-ruby-library)
|
6
|
+
[![Build Status](https://travis-ci.org/encoreshao/crunchbase-ruby-library.svg?branch=master)](https://travis-ci.org/encoreshao/crunchbase-ruby-library)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/github/encoreshao/crunchbase-ruby-library/badge.svg)](https://coveralls.io/github/encoreshao/crunchbase-ruby-library)
|
8
|
+
|
9
|
+
### How to update data
|
6
10
|
|
7
11
|
If you are using ChinaRegions version 0.1.x be sure to run:
|
8
12
|
|
@@ -10,55 +14,49 @@ If you are using ChinaRegions version 0.1.x be sure to run:
|
|
10
14
|
|
11
15
|
to have the javascript file copied over into your project.
|
12
16
|
|
13
|
-
|
17
|
+
### Installation
|
14
18
|
|
15
|
-
|
19
|
+
Add it to your Gemfile:
|
16
20
|
|
17
21
|
gem 'china_regions'
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
gem 'china_regions', github: 'encoreshao/china_regions'
|
22
|
-
|
23
|
-
安装:
|
23
|
+
Run the following command to install it:
|
24
24
|
|
25
25
|
>> bundle install
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
复制所需文件到你的项目中:
|
27
|
+
Run the generator:
|
30
28
|
|
31
29
|
>> rails g china_regions:install
|
32
30
|
|
33
|
-
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
31
|
+
Then you can see the changes that happened to the console:
|
32
|
+
* copy `db/migrate/xxxxxxxxxxx_create_china_regions_tables.rb` to your project `db/migrate`
|
33
|
+
* copy datasource cities.yml 到 config 目录. config/cities.yml
|
34
|
+
* copy regions.en.yml 和 regions.zh.yml 文件到 config/locales 目录
|
37
35
|
|
38
|
-
|
36
|
+
Create tables (provinces, cities, districts):
|
39
37
|
|
40
38
|
>> rake db:migrate
|
41
39
|
|
42
|
-
|
40
|
+
Import data:
|
43
41
|
|
44
42
|
>> rake china_regions:import
|
45
43
|
|
46
44
|
|
47
|
-
|
45
|
+
Copy Models [`Province`, `City`, `District`] into your app:
|
48
46
|
|
49
47
|
你可以执行 `rails g` 查看到 generator LIST.
|
50
48
|
|
51
49
|
>> rails g china_regions:regions
|
52
50
|
|
53
|
-
|
51
|
+
Newly added models:
|
54
52
|
|
55
53
|
create app/models/province.rb
|
56
54
|
create app/models/city.rb
|
57
55
|
create app/models/district.rb
|
58
56
|
|
59
|
-
|
57
|
+
### Usage
|
60
58
|
|
61
|
-
|
59
|
+
Example:
|
62
60
|
|
63
61
|
= form_for @article do |f|
|
64
62
|
|
@@ -77,7 +75,7 @@ OR
|
|
77
75
|
|
78
76
|
= f.submit class: 'btn'
|
79
77
|
|
80
|
-
|
78
|
+
Add prefix name:
|
81
79
|
|
82
80
|
= form_for @article do |f|
|
83
81
|
|
@@ -85,7 +83,7 @@ OR
|
|
85
83
|
= f.region_select [:province, :city, :district], :prefix => "work"
|
86
84
|
|
87
85
|
|
88
|
-
|
86
|
+
Pre-selected province:
|
89
87
|
|
90
88
|
= form_for @article do |f|
|
91
89
|
|
@@ -95,20 +93,25 @@ OR
|
|
95
93
|
|
96
94
|
= f.region_select [:province, :city, :district], province: "重庆市"
|
97
95
|
|
98
|
-
|
96
|
+
Prior choice:
|
99
97
|
|
100
98
|
= form_for @article do |f|
|
101
99
|
|
102
100
|
= f.region_select [:province, :city, :district], priority: { province: ["重庆市"], district: %w(巴南区 北碚区 渝北区) }
|
103
101
|
|
104
|
-
|
102
|
+
|
103
|
+
### Other languages
|
104
|
+
|
105
|
+
[Chinese Readme](https://github.com/encoreshao/china_regions/blob/master/README.zh.md)
|
106
|
+
|
107
|
+
### Contributing
|
105
108
|
|
106
109
|
We have a list of valued contributors. Check them all at:
|
107
110
|
|
108
111
|
https://github.com/encoreshao/china_regions/graphs/contributors
|
109
112
|
|
110
113
|
|
111
|
-
|
114
|
+
### License
|
112
115
|
|
113
|
-
|
116
|
+
Copyright © 2018-07 Encore Shao. See LICENSE for details.
|
114
117
|
|
data/README.zh.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# ChinaRegions
|
2
|
+
|
3
|
+
中国省份,城市,地区[地级市]Ruby on Rails 程式代码, Ruby (> 1.9.x) And Rails (> 4.0)
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/china-regions.svg)](https://badge.fury.io/rb/china-regions)
|
6
|
+
[![Build Status](https://travis-ci.org/encoreshao/china-regions.svg?branch=master)](https://travis-ci.org/encoreshao/china-regions)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/github/encoreshao/china-regions/badge.svg)](https://coveralls.io/github/encoreshao/china-regions)
|
8
|
+
|
9
|
+
### 如何更新数据文件
|
10
|
+
|
11
|
+
复制所需文件到你的项目中:
|
12
|
+
|
13
|
+
>> rails g china_regions:regions
|
14
|
+
|
15
|
+
### 如何引入china_regions到你的项目
|
16
|
+
|
17
|
+
添加以下代码到你的 Gemfile:
|
18
|
+
|
19
|
+
gem 'china_regions'
|
20
|
+
|
21
|
+
安装:
|
22
|
+
|
23
|
+
>> bundle install
|
24
|
+
|
25
|
+
#### 开始构建城市数据
|
26
|
+
|
27
|
+
复制所需文件到你的项目中:
|
28
|
+
|
29
|
+
>> rails g china_regions:install
|
30
|
+
|
31
|
+
随后你可以看到控制台发生的变化:
|
32
|
+
* 复制 db/migrate/xxxxxxxxxxx_create_china_regions_tables.rb 文件到db/migrate 目录
|
33
|
+
* 复制 数据源 cities.yml 到 config 目录. config/cities.yml
|
34
|
+
* 复制 regions.en.yml 和 regions.zh.yml 文件到 config/locales 目录
|
35
|
+
|
36
|
+
创建所需的表 (provinces, cities, districts):
|
37
|
+
|
38
|
+
>> rake db:migrate
|
39
|
+
|
40
|
+
导入数据到对应表中:
|
41
|
+
|
42
|
+
>> rake china_regions:import
|
43
|
+
|
44
|
+
|
45
|
+
将所需的模型(Models) [`Province`, `City`, `District`] 到您的应用程式中:
|
46
|
+
|
47
|
+
你可以执行 `rails g` 查看到 generator LIST.
|
48
|
+
|
49
|
+
>> rails g china_regions:regions
|
50
|
+
|
51
|
+
查看 app/models:
|
52
|
+
|
53
|
+
create app/models/province.rb
|
54
|
+
create app/models/city.rb
|
55
|
+
create app/models/district.rb
|
56
|
+
|
57
|
+
### 如何在View中使用
|
58
|
+
|
59
|
+
范例:
|
60
|
+
|
61
|
+
= form_for @article do |f|
|
62
|
+
|
63
|
+
= f.region_select [:province, :city, :district]
|
64
|
+
|
65
|
+
# form_tag
|
66
|
+
= region_select :article, :province_id
|
67
|
+
= region_select :article, :city_id
|
68
|
+
= region_select :article, :district_id
|
69
|
+
|
70
|
+
OR
|
71
|
+
|
72
|
+
= region_select :article, :province
|
73
|
+
= region_select :article, :city
|
74
|
+
= region_select :article, :district
|
75
|
+
|
76
|
+
= f.submit class: 'btn'
|
77
|
+
|
78
|
+
添加前缀名:
|
79
|
+
|
80
|
+
= form_for @article do |f|
|
81
|
+
|
82
|
+
= f.region_select [:province, :city, :district], :prefix => "home"
|
83
|
+
= f.region_select [:province, :city, :district], :prefix => "work"
|
84
|
+
|
85
|
+
|
86
|
+
预选则省份:
|
87
|
+
|
88
|
+
= form_for @article do |f|
|
89
|
+
|
90
|
+
= f.region_select [:province, :city, :district], province: "chongqing"
|
91
|
+
|
92
|
+
OR
|
93
|
+
|
94
|
+
= f.region_select [:province, :city, :district], province: "重庆市"
|
95
|
+
|
96
|
+
优先选择:
|
97
|
+
|
98
|
+
= form_for @article do |f|
|
99
|
+
|
100
|
+
= f.region_select [:province, :city, :district], priority: { province: ["重庆市"], district: %w(巴南区 北碚区 渝北区) }
|
101
|
+
|
102
|
+
|
103
|
+
### 其它语言
|
104
|
+
|
105
|
+
[English Readme](https://github.com/encoreshao/china_regions/blob/master/README.md)
|
106
|
+
|
107
|
+
### 贡献者
|
108
|
+
|
109
|
+
你可以在这里查看到所有的代码贡献者:
|
110
|
+
|
111
|
+
https://github.com/encoreshao/china_regions/graphs/contributors
|
112
|
+
|
113
|
+
|
114
|
+
### 许可
|
115
|
+
|
116
|
+
Copyright © 2018-07 Encore Shao. See LICENSE for details.
|
117
|
+
|
@@ -35,7 +35,8 @@ $(function() {
|
|
35
35
|
$.getJSON('/china_regions/fetch_options', {
|
36
36
|
klass: changed_object.data('region-target-klass'),
|
37
37
|
parent_klass: changed_object.data('region-klass'),
|
38
|
-
parent_id: changed_object.val()
|
38
|
+
parent_id: changed_object.val()
|
39
|
+
}, function(data) {
|
39
40
|
|
40
41
|
$('option[value!=""]', target).remove();
|
41
42
|
$.each(data, function(index, value) {
|
data/app/models/city.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class City <
|
3
|
+
class City < ApplicationRecord
|
4
4
|
belongs_to :province
|
5
5
|
has_many :districts, dependent: :destroy
|
6
6
|
|
7
|
-
scope :
|
7
|
+
scope :for_province, ->(province_id) { where(province_id: province_id) }
|
8
8
|
|
9
9
|
def short_name
|
10
10
|
@short_name ||= name.gsub(/市|自治州|地区|特别行政区/, '')
|
11
11
|
end
|
12
12
|
|
13
13
|
def siblings
|
14
|
-
@siblings ||= where(nil).
|
14
|
+
@siblings ||= where(nil).for_province(province_id)
|
15
15
|
end
|
16
16
|
end
|
data/app/models/district.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class District <
|
3
|
+
class District < ApplicationRecord
|
4
4
|
belongs_to :city
|
5
5
|
|
6
|
-
scope :
|
6
|
+
scope :for_city, ->(city_id) { where(city_id: city_id) }
|
7
7
|
|
8
8
|
def province
|
9
9
|
city.province
|
@@ -14,6 +14,6 @@ class District < ActiveRecord::Base
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def siblings
|
17
|
-
@siblings ||= where(nil).
|
17
|
+
@siblings ||= where(nil).for_city(city_id)
|
18
18
|
end
|
19
19
|
end
|
data/app/models/province.rb
CHANGED
data/config/locales/en.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: china_regions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Encore Shao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jquery-rails
|
@@ -47,9 +47,11 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rubocop.yml"
|
50
|
+
- ".travis.yml"
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE
|
52
53
|
- README.md
|
54
|
+
- README.zh.md
|
53
55
|
- Rakefile
|
54
56
|
- app/assets/javascripts/region_select.js
|
55
57
|
- app/controllers/china_regions/fetch_options_controller.rb
|