sharp_zones 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/MIT-LICENSE +20 -0
- data/README.md +51 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/sharp_zones/application.js +15 -0
- data/app/assets/javascripts/sharp_zones/sharp_cities.js +2 -0
- data/app/assets/javascripts/sharp_zones/sharp_zones.js +2 -0
- data/app/assets/stylesheets/sharp_zones/application.css +13 -0
- data/app/assets/stylesheets/sharp_zones/sharp_cities.css +4 -0
- data/app/assets/stylesheets/sharp_zones/sharp_zones.css +4 -0
- data/app/controllers/sharp_zones/application_controller.rb +4 -0
- data/app/controllers/sharp_zones/sharp_cities_controller.rb +14 -0
- data/app/controllers/sharp_zones/sharp_zones_controller.rb +6 -0
- data/app/helpers/sharp_zones/application_helper.rb +5 -0
- data/app/helpers/sharp_zones/sharp_cities_helper.rb +4 -0
- data/app/helpers/sharp_zones/sharp_zones_helper.rb +4 -0
- data/app/inputs/simple_form.rb +20 -0
- data/app/views/layouts/sharp_zones/application.html.erb +14 -0
- data/app/views/sharp_cities/_select.html.erb +16 -0
- data/app/views/sharp_cities/_simple_form_select.html.erb +16 -0
- data/app/views/sharp_cities/index.js.erb +7 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20130418094005_create_sharp_zones.rb +28 -0
- data/db/zones.db +0 -0
- data/lib/generators/sharp_zones/USAGE +8 -0
- data/lib/generators/sharp_zones/sharp_zones_generator.rb +15 -0
- data/lib/generators/sharp_zones/templates/city.rb +2 -0
- data/lib/generators/sharp_zones/templates/migration.rb +28 -0
- data/lib/generators/sharp_zones/templates/province.rb +2 -0
- data/lib/generators/sharp_zones/templates/zone.rb +2 -0
- data/lib/sharp_zones/engine.rb +6 -0
- data/lib/sharp_zones/version.rb +3 -0
- data/lib/sharp_zones/view_helpers.rb +12 -0
- data/lib/sharp_zones.rb +5 -0
- data/lib/tasks/sharp_zones_tasks.rake +32 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/fixtures/sharp_zones/cities.yml +11 -0
- data/test/fixtures/sharp_zones/provinces.yml +11 -0
- data/test/fixtures/sharp_zones/zones.yml +11 -0
- data/test/functional/sharp_zones/sharp_cities_controller_test.rb +9 -0
- data/test/functional/sharp_zones/sharp_zones_controller_test.rb +9 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/sharp_zones_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/helpers/sharp_zones/sharp_cities_helper_test.rb +6 -0
- data/test/unit/helpers/sharp_zones/sharp_zones_helper_test.rb +6 -0
- data/test/unit/sharp_zones/city_test.rb +9 -0
- data/test/unit/sharp_zones/province_test.rb +9 -0
- data/test/unit/sharp_zones/zone_test.rb +9 -0
- metadata +195 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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,51 @@
|
|
1
|
+
## SharpZones
|
2
|
+
|
3
|
+
导入省市区数据库
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sharp_zones'
|
10
|
+
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
bundle
|
15
|
+
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```
|
20
|
+
rails g sharp_zones install
|
21
|
+
|
22
|
+
rake db:migrate
|
23
|
+
|
24
|
+
rake sharp_zones:import
|
25
|
+
```
|
26
|
+
|
27
|
+
### Sqlite Table Struct
|
28
|
+
|
29
|
+
|
30
|
+
```
|
31
|
+
sqlite> PRAGMA table_info(T_Province);
|
32
|
+
0|ProName|varchar(50)|1||1
|
33
|
+
1|ProSort|TEXT|0||0
|
34
|
+
2|ProRemark|varchar(50)|0||0
|
35
|
+
|
36
|
+
sqlite> PRAGMA table_info(T_City);
|
37
|
+
0|CityName|varchar(50)|1||0
|
38
|
+
1|ProID|TEXT|0||0
|
39
|
+
2|CitySort|TEXT|0||1
|
40
|
+
|
41
|
+
sqlite> PRAGMA table_info(T_Zone);
|
42
|
+
0|ZoneID|INTEGER|1||1
|
43
|
+
1|ZoneName|TEXT|0||0
|
44
|
+
2|CityID|TEXT|0||0
|
45
|
+
```
|
46
|
+
|
47
|
+
|
48
|
+
LICENSE.
|
49
|
+
-------------------------
|
50
|
+
|
51
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'SharpZones'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
@@ -0,0 +1,15 @@
|
|
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 vendor/assets/javascripts of plugins, if any, 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
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_dependency "sharp_zones/application_controller"
|
2
|
+
|
3
|
+
module SharpZones
|
4
|
+
class SharpCitiesController < ApplicationController
|
5
|
+
respond_to :html, :json
|
6
|
+
|
7
|
+
def index
|
8
|
+
@cities = City.where(province_code: params[:province_code])
|
9
|
+
respond_to do |format|
|
10
|
+
format.js { render 'sharp_cities/index' }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SharpZones
|
2
|
+
module SimpleForm
|
3
|
+
class CityInput < ::SimpleForm::Inputs::Base
|
4
|
+
def input
|
5
|
+
out = '' # the output string we're going to build
|
6
|
+
# check if there's an uploaded file (eg: edit mode or form not saved)
|
7
|
+
if object.send("#{attribute_name}?")
|
8
|
+
# append preview image to output
|
9
|
+
#select_tag(:city_id, '<option value="1">Lisbon</option>...')
|
10
|
+
out << template.select_tag(object.send(attribute_name), options_for_select(SharpZones::City.all.map { |c| [c.name, c.code] }))
|
11
|
+
end
|
12
|
+
# append file input. it will work accordingly with your simple_form wrappers
|
13
|
+
#(out << @builder.file_field(attribute_name, input_html_options)).html_safe
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
::SimpleForm::FormBuilder.map_type :city_input, :to => RailsKindeditor::SimpleForm::CityInput
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>SharpZones</title>
|
5
|
+
<%= stylesheet_link_tag "sharp_zones/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "sharp_zones/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
<%= select_tag :province_code, options_for_select(SharpZones::Province.all.collect{|i|[i.name, i.code]}), prompt: '请选择省份',
|
3
|
+
data: {
|
4
|
+
remote: true,
|
5
|
+
url: '/sharp_zones/cities',
|
6
|
+
update: "city_code"
|
7
|
+
},
|
8
|
+
style: 'float:left'
|
9
|
+
%>
|
10
|
+
|
11
|
+
<%= select_tag :city_code, options_for_select([]),
|
12
|
+
wrapper_html: { style: 'display: inline; float:left; margin-left:5px;' }, prompt: '请选择城市', label: false, input_html: {
|
13
|
+
id: 'city_code',
|
14
|
+
style: 'display: inline'
|
15
|
+
}
|
16
|
+
%>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
<%= select_tag :province_code, options_for_select(SharpZones::Province.all.collect{|i|[i.name, i.code]}), prompt: '请选择省份',
|
3
|
+
data: {
|
4
|
+
remote: true,
|
5
|
+
url: '/sharp_zones/cities',
|
6
|
+
update: "city_code"
|
7
|
+
},
|
8
|
+
style: 'float:left'
|
9
|
+
%>
|
10
|
+
|
11
|
+
<%= select_tag :city_code, options_for_select([]),
|
12
|
+
wrapper_html: { style: 'display: inline; float:left; margin-left:5px;' }, prompt: '请选择城市', label: false, input_html: {
|
13
|
+
id: 'city_code',
|
14
|
+
style: 'display: inline'
|
15
|
+
}
|
16
|
+
%>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class CreateSharpZones < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table "cities", :force => true do |t|
|
4
|
+
t.integer "province_id", :null => false
|
5
|
+
t.string "name"
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
add_index "cities", "province_id"
|
9
|
+
|
10
|
+
create_table "provinces", :force => true do |t|
|
11
|
+
t.string "name"
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table "zones", :force => true do |t|
|
16
|
+
t.string "name", :null => false
|
17
|
+
t.integer "city_id", :null => false
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
add_index "zones", "city_id"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
drop_table :cities
|
25
|
+
drop_table :provinces
|
26
|
+
drop_table :zones
|
27
|
+
end
|
28
|
+
end
|
data/db/zones.db
ADDED
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
class SharpZonesGenerator < ActiveRecord::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def generate_model
|
7
|
+
copy_file 'city.rb', "app/models/city.rb"
|
8
|
+
copy_file 'zone.rb', "app/models/zone.rb"
|
9
|
+
copy_file 'province.rb', "app/models/province.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_migration
|
13
|
+
migration_template 'migration.rb', "db/migrate/create_sharp_zones"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class CreateSharpZones < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table "cities", :force => true do |t|
|
4
|
+
t.integer "province_id", :null => false
|
5
|
+
t.string "name"
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
add_index "cities", "province_id"
|
9
|
+
|
10
|
+
create_table "provinces", :force => true do |t|
|
11
|
+
t.string "name"
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table "zones", :force => true do |t|
|
16
|
+
t.string "name", :null => false
|
17
|
+
t.integer "city_id", :null => false
|
18
|
+
t.timestamps
|
19
|
+
end
|
20
|
+
add_index "zones", "city_id"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
drop_table :cities
|
25
|
+
drop_table :provinces
|
26
|
+
drop_table :zones
|
27
|
+
end
|
28
|
+
end
|