china_city 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.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +28 -0
  4. data/app/assets/javascripts/china_city/application.js.coffee +2 -0
  5. data/app/assets/javascripts/china_city/jquery.china_city.js.coffee +17 -0
  6. data/app/assets/stylesheets/china_city/application.css +13 -0
  7. data/app/controllers/china_city/application_controller.rb +4 -0
  8. data/app/controllers/china_city/data_controller.rb +13 -0
  9. data/app/helpers/china_city/application_helper.rb +4 -0
  10. data/app/views/china_city/data/index.html.erb +28 -0
  11. data/app/views/layouts/china_city/application.html.erb +12 -0
  12. data/config/routes.rb +4 -0
  13. data/db/areas.json +6 -0
  14. data/lib/china_city/engine.rb +13 -0
  15. data/lib/china_city/version.rb +3 -0
  16. data/lib/china_city.rb +99 -0
  17. data/lib/tasks/china_city_tasks.rake +4 -0
  18. data/spec/controllers/china_city/data_controller_spec.rb +12 -0
  19. data/spec/dummy/README.rdoc +28 -0
  20. data/spec/dummy/Rakefile +6 -0
  21. data/spec/dummy/app/assets/javascripts/application.js +14 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/spec/dummy/bin/bundle +3 -0
  27. data/spec/dummy/bin/rails +4 -0
  28. data/spec/dummy/bin/rake +4 -0
  29. data/spec/dummy/config/application.rb +28 -0
  30. data/spec/dummy/config/boot.rb +5 -0
  31. data/spec/dummy/config/database.yml +25 -0
  32. data/spec/dummy/config/environment.rb +5 -0
  33. data/spec/dummy/config/environments/development.rb +29 -0
  34. data/spec/dummy/config/environments/production.rb +80 -0
  35. data/spec/dummy/config/environments/test.rb +36 -0
  36. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  37. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  38. data/spec/dummy/config/initializers/inflections.rb +16 -0
  39. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  40. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  41. data/spec/dummy/config/initializers/session_store.rb +3 -0
  42. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  43. data/spec/dummy/config/locales/en.yml +23 -0
  44. data/spec/dummy/config/routes.rb +4 -0
  45. data/spec/dummy/config.ru +4 -0
  46. data/spec/dummy/log/development.log +5921 -0
  47. data/spec/dummy/log/test.log +252 -0
  48. data/spec/dummy/public/404.html +58 -0
  49. data/spec/dummy/public/422.html +58 -0
  50. data/spec/dummy/public/500.html +57 -0
  51. data/spec/dummy/public/favicon.ico +0 -0
  52. data/spec/dummy/tmp/cache/assets/development/sprockets/35f568d6b4c5b9431aeca08ebe1b2dea +0 -0
  53. data/spec/dummy/tmp/cache/assets/development/sprockets/37921dfa12e3d26acd1391b11883b3f6 +0 -0
  54. data/spec/dummy/tmp/cache/assets/development/sprockets/3b490ad633b60008f79d7d5c6bacb53d +0 -0
  55. data/spec/dummy/tmp/cache/assets/development/sprockets/4de331a6a64d5ace50f9234a9a64c617 +0 -0
  56. data/spec/dummy/tmp/cache/assets/development/sprockets/4fc372504d8cd84be102f1e63e2b16f8 +0 -0
  57. data/spec/dummy/tmp/cache/assets/development/sprockets/5ccf082c0c1984395e30b2a6059ee972 +0 -0
  58. data/spec/dummy/tmp/cache/assets/development/sprockets/6b50e161ae0a55621ba1dfc58a60e90c +0 -0
  59. data/spec/dummy/tmp/cache/assets/development/sprockets/78abd667345b2147eba18800e12e6d17 +0 -0
  60. data/spec/dummy/tmp/cache/assets/development/sprockets/887e2ba7efa792fda790a48911a596b2 +0 -0
  61. data/spec/dummy/tmp/cache/assets/development/sprockets/b2f5722a25ec12218a20c130bac9c929 +0 -0
  62. data/spec/dummy/tmp/cache/assets/development/sprockets/ccc63975f47542b9573178e46d3a43a4 +0 -0
  63. data/spec/dummy/tmp/cache/assets/development/sprockets/d7a58a396bcfc9ebb9ea3f8fe69d07a8 +0 -0
  64. data/spec/dummy/tmp/cache/assets/test/sprockets/35f568d6b4c5b9431aeca08ebe1b2dea +0 -0
  65. data/spec/dummy/tmp/cache/assets/test/sprockets/3b490ad633b60008f79d7d5c6bacb53d +0 -0
  66. data/spec/dummy/tmp/cache/assets/test/sprockets/4de331a6a64d5ace50f9234a9a64c617 +0 -0
  67. data/spec/dummy/tmp/cache/assets/test/sprockets/4fc372504d8cd84be102f1e63e2b16f8 +0 -0
  68. data/spec/dummy/tmp/cache/assets/test/sprockets/5ccf082c0c1984395e30b2a6059ee972 +0 -0
  69. data/spec/dummy/tmp/cache/assets/test/sprockets/6b50e161ae0a55621ba1dfc58a60e90c +0 -0
  70. data/spec/dummy/tmp/cache/assets/test/sprockets/78abd667345b2147eba18800e12e6d17 +0 -0
  71. data/spec/dummy/tmp/cache/assets/test/sprockets/887e2ba7efa792fda790a48911a596b2 +0 -0
  72. data/spec/dummy/tmp/cache/assets/test/sprockets/b2f5722a25ec12218a20c130bac9c929 +0 -0
  73. data/spec/dummy/tmp/cache/assets/test/sprockets/d7a58a396bcfc9ebb9ea3f8fe69d07a8 +0 -0
  74. data/spec/dummy/tmp/capybara/capybara-201308122053431011460252.html +1 -0
  75. data/spec/dummy/tmp/capybara/capybara-20130812205400956024760.html +15 -0
  76. data/spec/dummy/tmp/capybara/capybara-201308122055089727609001.html +1 -0
  77. data/spec/dummy/tmp/capybara/capybara-201308122056446100423016.html +15 -0
  78. data/spec/dummy/tmp/capybara/capybara-201308122057069527721661.html +15 -0
  79. data/spec/dummy/tmp/capybara/capybara-201308122102518595840184.html +15 -0
  80. data/spec/dummy/tmp/capybara/capybara-201308122105199923136662.html +2 -0
  81. data/spec/dummy/tmp/capybara/capybara-201308122105296054565456.html +2 -0
  82. data/spec/dummy/tmp/capybara/capybara-201308122109098287796815.html +133 -0
  83. data/spec/dummy/tmp/capybara/capybara-201308122110349829348457.html +133 -0
  84. data/spec/dummy/tmp/capybara/capybara-201308122138487518932375.html +133 -0
  85. data/spec/dummy/tmp/capybara/capybara-201308122236338878485935.html +143 -0
  86. data/spec/dummy/tmp/capybara/capybara-201308122237183217273230.html +143 -0
  87. data/spec/features/china_city_spec.rb +35 -0
  88. data/spec/lib/china_city_spec.rb +33 -0
  89. data/spec/spec_helper.rb +26 -0
  90. metadata +329 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9bf9c1279b6288d335cc2db6b64ecea263530722
4
+ data.tar.gz: 29ca918f6ba4094b0d8d3cf9c2fc7f41169107ef
5
+ SHA512:
6
+ metadata.gz: 16d086d39966a91ac741be04a6478f6056be1fd6cb2721580c4c64222cbe50d6ef602f4570a1e2e56e73048ab8ccf0ee2ee02ddbb417b362cbd72126dc31071d
7
+ data.tar.gz: d0a39e7908305d0c87262358ae7bd6004a755653fd20d0bf4ccf9412a767293fe62a321eab42b6a69b8a0c10200b092404d7e4d1be294183fcb23bcf9a9ddeea
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/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ChinaCity'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rspec/core'
25
+ require 'rspec/core/rake_task'
26
+ desc "Run all specs in spec directory (excluding plugin specs)"
27
+ RSpec::Core::RakeTask.new(:spec)
28
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ #= require 'jquery'
2
+ #= require_tree .
@@ -0,0 +1,17 @@
1
+ (($) ->
2
+ $.fn.china_city = () ->
3
+ @each ->
4
+ selects = $(@).find('.city-select')
5
+ selects.change ->
6
+ next_select = selects.eq(selects.index(@) + 1)
7
+ if !$(@).val() # empty all children city
8
+ $("option:gt(0)", next_select).remove()
9
+ next_select.change()
10
+ else if next_select[0] # init next child
11
+ $.get "/china_city/#{$(@).val()}", (data) ->
12
+ $("option:gt(0)", next_select).remove()
13
+ next_select[0].options.add(new Option(option[0], option[1])) for option in data
14
+
15
+ $ ->
16
+ $('.city-group').china_city()
17
+ )(jQuery)
@@ -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
+ module ChinaCity
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,13 @@
1
+ require_dependency "china_city/application_controller"
2
+
3
+ module ChinaCity
4
+ class DataController < ApplicationController
5
+ def show
6
+ data = ChinaCity.list(params[:id])
7
+ render json: data, layout: nil
8
+ end
9
+
10
+ def index
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module ChinaCity
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ <%-
2
+ province = '440000'
3
+ city = '440300'
4
+ district = '440305'
5
+ provinces = ChinaCity.list
6
+ cities = ChinaCity.list(province)
7
+ districtes = ChinaCity.list(city)
8
+ %>
9
+ <div class='rails-helper city-group'>
10
+ <%= select_tag :province, options_for_select(provinces, province) , prompt: '--省份--', class: ['city-select', 'city-province'] %>
11
+ <%= select_tag :city , options_for_select(cities, city) , prompt: '--城市--', class: ['city-select', 'city-city'] %>
12
+ <%= select_tag :district, options_for_select(districtes, district), prompt: '--地区--', class: ['city-select', 'city-district'] %>
13
+ </div>
14
+
15
+ <div class='html-tag city-group'>
16
+ <select class='city-select city-province'>
17
+ <option>--省份--</option>
18
+ <%= options_for_select(ChinaCity.list, province) %>
19
+ </select>
20
+ <select class='city-select city-city'>
21
+ <option>--城市--</option>
22
+ <%= options_for_select(cities, city) %>
23
+ </select>
24
+ <select class='city-select city-district'>
25
+ <option>--地区--</option>
26
+ <%= options_for_select(districtes, district) %>
27
+ </select>
28
+ </div>
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>ChinaCity</title>
5
+ <%= stylesheet_link_tag "china_city/application", media: "all" %>
6
+ <%= javascript_include_tag "china_city/application" %>
7
+ <%= csrf_meta_tags %>
8
+
9
+ <body>
10
+ <%= yield %>
11
+ </body>
12
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ ChinaCity::Engine.routes.draw do
2
+ root to: 'data#index'
3
+ get ':id', to: 'data#show'
4
+ end