china 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +30 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/sharp_zones/application.js +15 -0
  6. data/app/assets/javascripts/sharp_zones/sharp_cities.js +2 -0
  7. data/app/assets/javascripts/sharp_zones/sharp_zones.js +2 -0
  8. data/app/assets/stylesheets/sharp_zones/application.css +13 -0
  9. data/app/assets/stylesheets/sharp_zones/sharp_cities.css +4 -0
  10. data/app/assets/stylesheets/sharp_zones/sharp_zones.css +4 -0
  11. data/app/controllers/china/application_controller.rb +4 -0
  12. data/app/controllers/china/sharp_cities_controller.rb +14 -0
  13. data/app/helpers/sharp_zones/application_helper.rb +5 -0
  14. data/app/helpers/sharp_zones/sharp_cities_helper.rb +4 -0
  15. data/app/helpers/sharp_zones/sharp_zones_helper.rb +4 -0
  16. data/app/inputs/simple_form.rb +20 -0
  17. data/app/views/layouts/sharp_zones/application.html.erb +14 -0
  18. data/app/views/sharp_cities/_select.html.erb +16 -0
  19. data/app/views/sharp_cities/_simple_form_select.html.erb +16 -0
  20. data/app/views/sharp_cities/index.js.erb +1 -0
  21. data/config/routes.rb +3 -0
  22. data/db/cities.json +1 -0
  23. data/db/city_code.rb +27104 -0
  24. data/db/zones.db +0 -0
  25. data/lib/china/engine.rb +6 -0
  26. data/lib/china/version.rb +3 -0
  27. data/lib/china/view_helpers.rb +12 -0
  28. data/lib/china.rb +5 -0
  29. data/lib/generators/china/USAGE +8 -0
  30. data/lib/generators/china/china_generator.rb +26 -0
  31. data/lib/generators/china/templates/china_city.rb +9 -0
  32. data/lib/generators/china/templates/create_china_cities.rb +18 -0
  33. data/lib/generators/china/templates/import_china_cities.rb +34 -0
  34. data/test/dummy/README.rdoc +261 -0
  35. data/test/dummy/Rakefile +7 -0
  36. data/test/dummy/app/assets/javascripts/application.js +15 -0
  37. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  38. data/test/dummy/app/controllers/application_controller.rb +3 -0
  39. data/test/dummy/app/helpers/application_helper.rb +2 -0
  40. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/test/dummy/config/application.rb +59 -0
  42. data/test/dummy/config/boot.rb +10 -0
  43. data/test/dummy/config/database.yml +25 -0
  44. data/test/dummy/config/environment.rb +5 -0
  45. data/test/dummy/config/environments/development.rb +37 -0
  46. data/test/dummy/config/environments/production.rb +67 -0
  47. data/test/dummy/config/environments/test.rb +37 -0
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/test/dummy/config/initializers/inflections.rb +15 -0
  50. data/test/dummy/config/initializers/mime_types.rb +5 -0
  51. data/test/dummy/config/initializers/secret_token.rb +7 -0
  52. data/test/dummy/config/initializers/session_store.rb +8 -0
  53. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/test/dummy/config/locales/en.yml +5 -0
  55. data/test/dummy/config/routes.rb +4 -0
  56. data/test/dummy/config.ru +4 -0
  57. data/test/dummy/public/404.html +26 -0
  58. data/test/dummy/public/422.html +26 -0
  59. data/test/dummy/public/500.html +25 -0
  60. data/test/dummy/public/favicon.ico +0 -0
  61. data/test/dummy/script/rails +6 -0
  62. data/test/fixtures/sharp_zones/cities.yml +11 -0
  63. data/test/fixtures/sharp_zones/provinces.yml +11 -0
  64. data/test/fixtures/sharp_zones/zones.yml +11 -0
  65. data/test/functional/sharp_zones/sharp_cities_controller_test.rb +9 -0
  66. data/test/functional/sharp_zones/sharp_zones_controller_test.rb +9 -0
  67. data/test/integration/navigation_test.rb +10 -0
  68. data/test/sharp_zones_test.rb +7 -0
  69. data/test/test_helper.rb +15 -0
  70. data/test/unit/helpers/sharp_zones/sharp_cities_helper_test.rb +6 -0
  71. data/test/unit/helpers/sharp_zones/sharp_zones_helper_test.rb +6 -0
  72. data/test/unit/sharp_zones/city_test.rb +9 -0
  73. data/test/unit/sharp_zones/province_test.rb +9 -0
  74. data/test/unit/sharp_zones/zone_test.rb +9 -0
  75. metadata +186 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c64e06bf1ac24480584ed1c30a7ef72e1c910501
4
+ data.tar.gz: 8a74a9f71c5f9bd407deedf5fe4c8735cbcd4a04
5
+ SHA512:
6
+ metadata.gz: 787aebae1505922ba11625c5067d1f13e3047f112e26e32706a9c966d2ffd351e0ee77d61c61e36b5f39b7169270bdeb714a6c448109745b923bdec0376fa088
7
+ data.tar.gz: f9e58d2402013211d9a3e215d048ea41f62fc3e928b0afc9ce7b7dc702613f6aebe783cff4f7ff712315258b8fee120f6cb7c0fbb1fe338d5f17514122139be2
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,30 @@
1
+ ## Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ gem 'china'
6
+
7
+
8
+ And then execute:
9
+
10
+ bundle
11
+
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ rails g china install
17
+
18
+ rake db:migrate
19
+
20
+ ```
21
+
22
+ ### sql Table Struct
23
+
24
+
25
+
26
+
27
+ LICENSE.
28
+ -------------------------
29
+
30
+ 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,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -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,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ module China
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ require_dependency "china/application_controller"
2
+
3
+ module China
4
+ class SharpCitiesController < ApplicationController
5
+ respond_to :html, :json
6
+
7
+ def ajax
8
+ @cities = ChinaCity.where(parent_id: params[:id])
9
+ respond_to do |format|
10
+ format.js { render 'sharp_cities/ajax' }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module SharpZones
2
+ module ApplicationHelper
3
+
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module SharpZones
2
+ module SharpCitiesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module SharpZones
2
+ module SharpZonesHelper
3
+ end
4
+ 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(ChinaCity.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
+ %>
@@ -0,0 +1 @@
1
+ $("#city_code").empty().append("<%= escape_javascript(options_for_select(@cities.map{|i|[i.name, i.code]})) %>");
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ China::Engine.routes.draw do
2
+ get "cities/:id/ajax" => "sharp_cities#ajax"
3
+ end