china_region_fu 0.0.1
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.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.rdoc +62 -0
- data/Rakefile +1 -0
- data/app/models/city.rb +17 -0
- data/app/models/district.rb +16 -0
- data/app/models/province.rb +8 -0
- data/china_region_fu.gemspec +20 -0
- data/lib/china_region_fu/engine.rb +5 -0
- data/lib/china_region_fu/version.rb +3 -0
- data/lib/china_region_fu.rb +8 -0
- data/lib/generators/china_region_fu/install/USAGE +8 -0
- data/lib/generators/china_region_fu/install/install_generator.rb +30 -0
- data/lib/generators/china_region_fu/install/templates/migration.rb +45 -0
- data/lib/generators/china_region_fu/install/templates/regions.yml +10823 -0
- data/lib/generators/china_region_fu/mvc/USAGE +17 -0
- data/lib/generators/china_region_fu/mvc/mvc_generator.rb +11 -0
- data/lib/tasks/region.rake +34 -0
- metadata +63 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
Description:
|
2
|
+
Copy MVC support files to Rails app folder
|
3
|
+
|
4
|
+
Example:
|
5
|
+
User erb:
|
6
|
+
rails generate china_region_fu:mvc erb
|
7
|
+
|
8
|
+
User haml
|
9
|
+
rails generate china_region_fu:mvc haml
|
10
|
+
|
11
|
+
|
12
|
+
This will create:
|
13
|
+
app/models/province.rb
|
14
|
+
app/models/city.rb
|
15
|
+
app/models/district.rb
|
16
|
+
app/controllers/region_controller.rb
|
17
|
+
app/views/region/index.html.(erb|haml)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ChinaRegionFu
|
2
|
+
class MvcGenerator < Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path('../../../../../app', __FILE__)
|
4
|
+
|
5
|
+
def copy_model_file
|
6
|
+
copy_file "models/province.rb", "app/models/province.rb"
|
7
|
+
copy_file "models/city.rb", "app/models/city.rb"
|
8
|
+
copy_file "models/district.rb", "app/models/district.rb"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
namespace :region do
|
4
|
+
|
5
|
+
desc "Import region data to database from config/regions.yml"
|
6
|
+
task :import => :environment do
|
7
|
+
file_path = File.join(Rails.root, 'config', 'regions.yml')
|
8
|
+
regions = File.open(file_path) { |file| YAML.load(file) }
|
9
|
+
cleanup_regins
|
10
|
+
load_to_db(regions)
|
11
|
+
puts "Regions import done!"
|
12
|
+
end
|
13
|
+
|
14
|
+
def cleanup_regins
|
15
|
+
Province.delete_all
|
16
|
+
City.delete_all
|
17
|
+
District.delete_all
|
18
|
+
end
|
19
|
+
|
20
|
+
def load_to_db(regions)
|
21
|
+
regions.each do |province_name, province_hash|
|
22
|
+
current_province = Province.create(:name => province_name, :pinyin => province_hash['pinyin'], :pinyin_abbr => province_hash['pinyin_abbr'])
|
23
|
+
cities_hash = province_hash['cities']
|
24
|
+
cities_hash.each do |city_name, city_hash|
|
25
|
+
current_city = current_province.cities.create(:name => city_name, :pinyin => city_hash['pinyin'], :pinyin_abbr => city_hash['pinyin_abbr'], :zip_code => city_hash['zip_code'], 'level' => city_hash['level'] || 4)
|
26
|
+
districts_hash = city_hash['districts']
|
27
|
+
districts_hash.each do |district_name, district_hash|
|
28
|
+
current_city.districts.create(:name => district_name, :pinyin => district_hash['pinyin'], :pinyin_abbr => district_hash['pinyin_abbr'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: china_region_fu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- xuhao
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: china region
|
15
|
+
email:
|
16
|
+
- xuhao@rubyfans.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- README.rdoc
|
24
|
+
- Rakefile
|
25
|
+
- app/models/city.rb
|
26
|
+
- app/models/district.rb
|
27
|
+
- app/models/province.rb
|
28
|
+
- china_region_fu.gemspec
|
29
|
+
- lib/china_region_fu.rb
|
30
|
+
- lib/china_region_fu/engine.rb
|
31
|
+
- lib/china_region_fu/version.rb
|
32
|
+
- lib/generators/china_region_fu/install/USAGE
|
33
|
+
- lib/generators/china_region_fu/install/install_generator.rb
|
34
|
+
- lib/generators/china_region_fu/install/templates/migration.rb
|
35
|
+
- lib/generators/china_region_fu/install/templates/regions.yml
|
36
|
+
- lib/generators/china_region_fu/mvc/USAGE
|
37
|
+
- lib/generators/china_region_fu/mvc/mvc_generator.rb
|
38
|
+
- lib/tasks/region.rake
|
39
|
+
homepage: ''
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project: china_region_fu
|
59
|
+
rubygems_version: 1.8.24
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: china region
|
63
|
+
test_files: []
|