china_regions 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +9 -4
- data/config/locales/en.yml +26 -0
- data/config/locales/zh.yml +26 -0
- data/lib/china_regions/action_view/extension.rb +2 -0
- data/lib/china_regions/version.rb +1 -1
- data/lib/generators/china_regions/{install/install_generator.rb → install_generator.rb} +13 -3
- data/lib/generators/china_regions/{regions/regions_generator.rb → regions_generator.rb} +2 -2
- data/lib/generators/china_regions/{install/templates → templates}/cities.yml +0 -0
- data/lib/generators/china_regions/{install/templates → templates}/migration.rb +0 -0
- metadata +7 -5
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
# ChinaRegions
|
2
2
|
|
3
|
-
中国省份,城市,地区[地级市]. 紧支持 Ruby on Rails 程序.
|
3
|
+
中国省份,城市,地区[地级市]. 紧支持 Ruby on Rails 程序. Ruby Version ( > 1.9.x ) Rails Version ( > 3.2.x )
|
4
4
|
|
5
5
|
|
6
6
|
## How to use it
|
7
7
|
|
8
8
|
添加一下代码到你的 Gemfile:
|
9
9
|
|
10
|
+
gem 'china_regions'
|
11
|
+
|
12
|
+
or
|
13
|
+
|
10
14
|
gem 'china_regions', :git => 'git://github.com/encoreshao/china_regions.git'
|
11
15
|
|
12
16
|
bundle install
|
@@ -16,13 +20,14 @@ bundle install
|
|
16
20
|
rails g china_regions:install
|
17
21
|
|
18
22
|
随后你可以看到控制台:
|
19
|
-
*
|
20
|
-
* 创建
|
23
|
+
* 创建 migration 文件到db/migrate 目录 db/migrate/xxxxxxxxxxx_create_china_regions_tables.rb
|
24
|
+
* 创建 数据源 cities.yml 到 config 目录. config/cities.yml
|
25
|
+
* 创建 regions.en.yml 和 regions.zh.yml 文件到 config/locales 文件下
|
21
26
|
* 执行 `rake db:migrate` 添加三张表(provinces, cities, districts).
|
22
27
|
* 执行 `rake china_regions:import` 导入数据.
|
23
28
|
|
24
29
|
|
25
|
-
此时 你可能需要添加三个
|
30
|
+
此时 你可能需要添加三个 models[`Province`, `City`, `District`] 到你应用中:
|
26
31
|
|
27
32
|
你可以执行 `rails g` 查看到 generator LIST.
|
28
33
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
en:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
province: Province
|
5
|
+
city: City
|
6
|
+
district: District
|
7
|
+
|
8
|
+
attributes:
|
9
|
+
province:
|
10
|
+
name: Name
|
11
|
+
name_en: English Name
|
12
|
+
name_abbr: Short Name
|
13
|
+
city:
|
14
|
+
name: Name
|
15
|
+
province_id: Province
|
16
|
+
province: Province
|
17
|
+
name_en: English Name
|
18
|
+
name_abbr: Short Name
|
19
|
+
zip_code: Zip
|
20
|
+
level: Level
|
21
|
+
district:
|
22
|
+
name: Name
|
23
|
+
city_id: City
|
24
|
+
city: City
|
25
|
+
name_en: English Name
|
26
|
+
name_abbr: Short Name
|
@@ -0,0 +1,26 @@
|
|
1
|
+
zh:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
province: 省份
|
5
|
+
city: 城市
|
6
|
+
district: 区县
|
7
|
+
|
8
|
+
attributes:
|
9
|
+
province:
|
10
|
+
name: 名称
|
11
|
+
name_en: 拼音
|
12
|
+
name_abbr: 简称
|
13
|
+
city:
|
14
|
+
name: 名称
|
15
|
+
province_id: 省份
|
16
|
+
province: 省份
|
17
|
+
name_en: 拼音
|
18
|
+
name_abbr: 简称
|
19
|
+
zip_code: 邮编
|
20
|
+
level: 等级
|
21
|
+
district:
|
22
|
+
name: 名称
|
23
|
+
city_id: 城市
|
24
|
+
city: 城市
|
25
|
+
name_en: 拼音
|
26
|
+
name_abbr: 简称
|
@@ -5,14 +5,24 @@ module ChinaRegions
|
|
5
5
|
include Rails::Generators::Migration
|
6
6
|
source_root File.expand_path('../templates', __FILE__)
|
7
7
|
|
8
|
-
def
|
8
|
+
def copy_migration
|
9
|
+
system("rm db/migrate/*_china_regions_tables.rb")
|
9
10
|
migration_template "migration.rb", "db/migrate/create_china_regions_tables.rb"
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
-
copy_file
|
13
|
+
def copy_cities
|
14
|
+
copy_file('cities.yml', 'config/cities.yml') unless File::exists?("config/cities.yml")
|
14
15
|
end
|
15
16
|
|
17
|
+
def copy_locales
|
18
|
+
unless File::exists?("config/locales/regions.en.yml")
|
19
|
+
copy_file "../../../../config/locales/en.yml", "config/locales/regions.en.yml"
|
20
|
+
end
|
21
|
+
unless File::exists?("config/locales/regions.zh.yml")
|
22
|
+
copy_file "../../../../config/locales/zh.yml", "config/locales/regions.zh.yml"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
16
26
|
def execute_migrate
|
17
27
|
rake("db:migrate")
|
18
28
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module ChinaRegions
|
4
|
-
class
|
5
|
-
source_root File.expand_path('
|
4
|
+
class RegionsGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path('../../../../app', __FILE__)
|
6
6
|
|
7
7
|
def copy_models_file
|
8
8
|
copy_file "models/province.rb", "app/models/province.rb"
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: china_regions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -44,15 +44,17 @@ files:
|
|
44
44
|
- app/models/district.rb
|
45
45
|
- app/models/province.rb
|
46
46
|
- china_regions.gemspec
|
47
|
+
- config/locales/en.yml
|
48
|
+
- config/locales/zh.yml
|
47
49
|
- config/routes.rb
|
48
50
|
- lib/china_regions.rb
|
49
51
|
- lib/china_regions/action_view/extension.rb
|
50
52
|
- lib/china_regions/engine.rb
|
51
53
|
- lib/china_regions/version.rb
|
52
|
-
- lib/generators/china_regions/
|
53
|
-
- lib/generators/china_regions/
|
54
|
-
- lib/generators/china_regions/
|
55
|
-
- lib/generators/china_regions/
|
54
|
+
- lib/generators/china_regions/install_generator.rb
|
55
|
+
- lib/generators/china_regions/regions_generator.rb
|
56
|
+
- lib/generators/china_regions/templates/cities.yml
|
57
|
+
- lib/generators/china_regions/templates/migration.rb
|
56
58
|
- lib/tasks/china_regions.rake
|
57
59
|
homepage: http://github.com/encoreshao
|
58
60
|
licenses: []
|