china_region_fu 0.0.6 → 0.1.0

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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -5
  3. data/.rspec +2 -1
  4. data/.rubocop.yml +101 -0
  5. data/.travis.yml +4 -2
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +10 -4
  8. data/LICENSE.txt +21 -0
  9. data/README.en.md +212 -0
  10. data/README.md +103 -68
  11. data/Rakefile +1 -1
  12. data/app/controllers/china_region_fu/fetch_options_controller.rb +64 -28
  13. data/app/models/city.rb +1 -11
  14. data/app/models/district.rb +1 -11
  15. data/app/models/province.rb +4 -4
  16. data/bin/console +14 -0
  17. data/bin/rspec +17 -0
  18. data/bin/setup +8 -0
  19. data/china_region_fu.gemspec +20 -19
  20. data/db/migrate/20111111111111_create_china_region_tables.rb +19 -17
  21. data/lib/china_region_fu.rb +4 -3
  22. data/lib/china_region_fu/engine.rb +11 -9
  23. data/lib/china_region_fu/errors.rb +5 -0
  24. data/lib/china_region_fu/helpers/formtastic.rb +4 -6
  25. data/lib/china_region_fu/helpers/helpers.rb +44 -53
  26. data/lib/china_region_fu/helpers/simple_form.rb +15 -14
  27. data/lib/china_region_fu/helpers/utils.rb +82 -0
  28. data/lib/china_region_fu/version.rb +1 -1
  29. data/lib/generators/china_region_fu/models/USAGE +1 -1
  30. data/lib/generators/china_region_fu/models/models_generator.rb +3 -3
  31. data/lib/tasks/{region.rake → china_region_fu_tasks.rake} +8 -14
  32. data/spec/china_region_fu_spec.rb +3 -7
  33. data/spec/helpers/helpers_spec.rb +113 -0
  34. data/spec/helpers/utils_spec.rb +87 -0
  35. data/spec/spec_helper.rb +6 -1
  36. data/spec/support/models.rb +39 -0
  37. metadata +50 -61
  38. data/LICENSE +0 -22
  39. data/lib/china_region_fu/exceptions.rb +0 -7
  40. data/lib/china_region_fu/helpers/utilities.rb +0 -54
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2012 Xuhao
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,7 +0,0 @@
1
- module ChinaRegionFu
2
- class InvalidAttributeError < StandardError
3
- def initialize
4
- super 'Region attribute is not valid.'
5
- end
6
- end
7
- end
@@ -1,54 +0,0 @@
1
- module ChinaRegionFu
2
- module Utilities
3
- def js_for_region_ajax
4
- js = <<-JAVASCRIPT
5
- <script type="text/javascript">
6
- //<![CDATA[
7
- $(function(){
8
- $('body').on('change', '.region_select', function(event) {
9
- var self, $targetDom;
10
- self = $(event.currentTarget);
11
- $targetDom = $('#' + self.data('region-target'));
12
- if ($targetDom.size() > 0) {
13
- $.getJSON('/china_region_fu/fetch_options', {klass: self.data('region-target-kalss'), parent_klass: self.data('region-klass'), parent_id: self.val()}, function(data) {
14
- var options = [];
15
- $('option[value!=""]', $targetDom).remove();
16
- $.each(data, function(index, value) {
17
- options.push("<option value='" + value.id + "'>" + value.name + "</option>");
18
- });
19
- $targetDom.append(options.join(''));
20
- });
21
- }
22
- });
23
- });
24
- //]]>
25
- </script>
26
- JAVASCRIPT
27
- js.html_safe
28
- end
29
-
30
- def set_html_options(object, method, html_options, next_region)
31
- region_klass_name = method.to_s#.sub(/_id\Z/, '')
32
- next_region_klass_name = next_region.to_s#.sub(/_id\Z/, '')
33
- html_options[:data] ? (html_options[:data][:region_klass] = region_klass_name) : (html_options[:data] = { region_klass: region_klass_name })
34
- if next_region
35
- region_target = object ? "#{object}_#{next_region.to_s}" : next_region.to_s
36
- html_options[:data].merge!(region_target: region_target, region_target_kalss: next_region_klass_name)
37
- else
38
- html_options[:data].delete(:region_target)
39
- html_options[:data].delete(:region_target_kalss)
40
- end
41
- html_options
42
- end
43
-
44
- def to_class(str_name)
45
- return nil if str_name.blank?
46
- str_name.to_s.sub(/_id\Z/, '').classify.safe_constantize
47
- end
48
-
49
- def append_region_class(options)
50
- options[:class] ? (options[:class].prepend('region_select ')) : (options[:class] = 'region_select')
51
- options
52
- end
53
- end
54
- end