china_citys 0.0.4

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 (54) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +29 -0
  4. data/app/assets/javascripts/china_citys/application.js.coffee +3 -0
  5. data/app/assets/javascripts/china_citys/jquery.china_citys.js.coffee +17 -0
  6. data/app/assets/stylesheets/china_citys/application.css +13 -0
  7. data/app/controllers/china_citys/application_controller.rb +4 -0
  8. data/app/controllers/china_citys/data_controller.rb +13 -0
  9. data/app/helpers/china_citys/application_helper.rb +4 -0
  10. data/app/views/china_citys/data/index.html.erb +28 -0
  11. data/app/views/layouts/china_citys/application.html.erb +12 -0
  12. data/config/routes.rb +4 -0
  13. data/db/areas.json +6 -0
  14. data/lib/china_citys/engine.rb +13 -0
  15. data/lib/china_citys/version.rb +3 -0
  16. data/lib/china_citys.rb +99 -0
  17. data/lib/tasks/china_citys_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 +35 -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 +13 -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/public/404.html +58 -0
  47. data/spec/dummy/public/422.html +58 -0
  48. data/spec/dummy/public/500.html +57 -0
  49. data/spec/dummy/public/favicon.ico +0 -0
  50. data/spec/dummy/script/rails +6 -0
  51. data/spec/features/china_city_spec.rb +69 -0
  52. data/spec/lib/china_city_spec.rb +33 -0
  53. data/spec/spec_helper.rb +29 -0
  54. metadata +245 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b3e94da4f9bd933b37607b4b70c971616ba34580
4
+ data.tar.gz: 00cc7958e7f425b781a6ca159c61237e3df54899
5
+ SHA512:
6
+ metadata.gz: d336e7ce9ae69b5dcdc488ddf5f8d6f14db44dad3267556c2adc22c9e7f2fd692342c584a5ba1f15b043fcf1f463829451de5ade1cea9462072888eef17b50a5
7
+ data.tar.gz: 30d08866ee198f96f40ac39d3d431bb95e63696e44257fa3b32b3967c44eea27412da4d48e055110a92056c68f3831ec12c90557a1decf22b9e1f9f43e776263
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 saberma
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,29 @@
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
+ require 'appraisal'
9
+
10
+ RDoc::Task.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'ChinaCitys'
13
+ rdoc.options << '--line-numbers'
14
+ rdoc.rdoc_files.include('README.rdoc')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
19
+ load 'rails/tasks/engine.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rspec/core'
26
+ require 'rspec/core/rake_task'
27
+ desc "Run all specs in spec directory (excluding plugin specs)"
28
+ RSpec::Core::RakeTask.new(:spec)
29
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ #= require jquery
2
+ #= require china_citys/jquery.china_citys
3
+ #= require_tree .
@@ -0,0 +1,17 @@
1
+ (($) ->
2
+ $.fn.china_citys = () ->
3
+ @each ->
4
+ selects = $(@).find('.city-select')
5
+ selects.change ->
6
+ $this = $(@)
7
+ next_selects = selects.slice(selects.index(@) + 1) # empty all children city
8
+ $("option:gt(0)", next_selects).remove()
9
+ if next_selects.first()[0] and $this.val() # init next child
10
+ $.get "/china_citys/#{$(@).val()}", (data) ->
11
+ next_selects.first()[0].options.add(new Option(option[0], option[1])) for option in data
12
+ # init value after data completed.
13
+ next_selects.trigger('china_citys:load_data_completed');
14
+
15
+ $(document).on 'ready page:load', ->
16
+ $('.city-group').china_citys()
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 ChinaCitys
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,13 @@
1
+ require_dependency "china_citys/application_controller"
2
+
3
+ module ChinaCitys
4
+ class DataController < ApplicationController
5
+ def show
6
+ data = ChinaCitys.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 ChinaCitys
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,28 @@
1
+ <%-
2
+ province = '440000'
3
+ city = '440300'
4
+ district = '440305'
5
+ provinces = ChinaCitys.list
6
+ cities = ChinaCitys.list(province)
7
+ districtes = ChinaCitys.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(ChinaCitys.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>ChinaCitys</title>
5
+ <%= stylesheet_link_tag "china_citys/application", media: "all" %>
6
+ <%= javascript_include_tag "china_citys/application" %>
7
+ <%= csrf_meta_tags %>
8
+
9
+ <body>
10
+ <%= yield %>
11
+ </body>
12
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ ChinaCitys::Engine.routes.draw do
2
+ root to: 'data#index'
3
+ get ':id', to: 'data#show'
4
+ end