country_state_select 2.0.0 → 3.0.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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/README.md +126 -8
  4. data/app/controllers/country_state_select/cscs_controller.rb +9 -0
  5. data/config/routes.rb +4 -4
  6. data/country_state_select.gemspec +16 -10
  7. data/lib/country_state_select.rb +33 -22
  8. data/lib/country_state_select/version.rb +1 -1
  9. data/spec/country_state_select_spec.rb +172 -0
  10. data/spec/spec_helper.rb +8 -0
  11. data/test/dummy/Gemfile +40 -43
  12. data/test/dummy/app/assets/javascripts/application.js +4 -3
  13. data/test/dummy/app/assets/javascripts/locations.coffee +2 -0
  14. data/test/dummy/app/assets/stylesheets/application.scss +16 -0
  15. data/test/dummy/app/assets/stylesheets/{users.css.scss → locations.css.scss} +1 -1
  16. data/test/dummy/app/controllers/locations_controller.rb +55 -0
  17. data/test/dummy/app/form/location_form.rb +11 -0
  18. data/test/dummy/app/models/location.rb +2 -0
  19. data/test/dummy/app/views/layouts/application.html.erb +7 -5
  20. data/test/dummy/app/views/locations/_form.html.erb +15 -0
  21. data/test/dummy/app/views/locations/index.html.erb +29 -0
  22. data/test/dummy/app/views/locations/new.html.erb +13 -0
  23. data/test/dummy/app/views/locations/show.html.erb +13 -0
  24. data/test/dummy/bin/bundle +0 -0
  25. data/test/dummy/bin/rails +0 -0
  26. data/test/dummy/bin/rake +0 -0
  27. data/test/dummy/config/environments/production.rb +1 -1
  28. data/test/dummy/config/initializers/simple_form.rb +165 -0
  29. data/test/dummy/config/locales/simple_form.en.yml +31 -0
  30. data/test/dummy/config/routes.rb +2 -56
  31. data/test/dummy/db/migrate/20140724080030_create_locations.rb +10 -0
  32. data/test/dummy/db/migrate/20151024160724_add_test_city_to_locations.rb +5 -0
  33. data/test/dummy/db/schema.rb +5 -8
  34. data/vendor/assets/javascript/country_state_select.js.erb +159 -36
  35. metadata +172 -39
  36. data/lib/country_state_select/cst_data.rb +0 -17
  37. data/test/dummy/app/assets/javascripts/users.js.coffee +0 -9
  38. data/test/dummy/app/assets/stylesheets/application.css +0 -14
  39. data/test/dummy/app/assets/stylesheets/scaffolds.css.scss +0 -69
  40. data/test/dummy/app/controllers/users_controller.rb +0 -74
  41. data/test/dummy/app/helpers/users_helper.rb +0 -2
  42. data/test/dummy/app/models/user.rb +0 -2
  43. data/test/dummy/app/views/users/_form.html.erb +0 -35
  44. data/test/dummy/app/views/users/edit.html.erb +0 -6
  45. data/test/dummy/app/views/users/index.html.erb +0 -35
  46. data/test/dummy/app/views/users/index.json.jbuilder +0 -4
  47. data/test/dummy/app/views/users/new.html.erb +0 -5
  48. data/test/dummy/app/views/users/show.html.erb +0 -27
  49. data/test/dummy/app/views/users/show.json.jbuilder +0 -1
  50. data/test/dummy/db/migrate/20140724080030_create_users.rb +0 -12
  51. data/test/dummy/db/migrate/20140728194622_add_state_name_to_users.rb +0 -5
  52. data/test/dummy/db/migrate/20140728203606_add_country_name_to_user.rb +0 -5
  53. data/test/dummy/test/controllers/users_controller_test.rb +0 -49
  54. data/test/dummy/test/fixtures/users.yml +0 -13
  55. data/test/dummy/test/helpers/users_helper_test.rb +0 -4
  56. data/test/dummy/test/models/user_test.rb +0 -7
@@ -0,0 +1,8 @@
1
+ require 'rails'
2
+ require 'active_record'
3
+ require 'pry'
4
+ require 'country_state_select'
5
+
6
+ RSpec.configure do |config|
7
+ #add configuration here
8
+ end
@@ -1,47 +1,44 @@
1
- source 'https://rubygems.org'
2
-
3
- # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
4
- gem 'rails', '4.0.5'
5
-
6
- # Use sqlite3 as the database for Active Record
7
- gem 'sqlite3'
8
-
9
- # Use SCSS for stylesheets
10
- gem 'sass-rails', '~> 4.0.2'
11
-
12
- # Use Uglifier as compressor for JavaScript assets
13
- gem 'uglifier', '>= 1.3.0'
14
-
15
- gem 'country_state_select', path: '../../'
16
-
17
- # Use CoffeeScript for .js.coffee assets and views
18
- gem 'coffee-rails', '~> 4.0.0'
19
-
20
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
21
- # gem 'therubyracer', platforms: :ruby
22
-
23
- # Use jquery as the JavaScript library
24
- gem 'jquery-rails'
25
-
26
- # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
27
- gem 'turbolinks'
28
-
29
- # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
30
- gem 'jbuilder', '~> 1.2'
31
-
32
- group :doc do
33
- # bundle exec rake doc:rails generates the API under doc/api.
34
- gem 'sdoc', require: false
1
+ source "https://rubygems.org"
2
+
3
+ group :development, :test do
4
+ gem "byebug", "~> 6.0"
5
+ gem "pry-rails", "~> 0.3"
6
+ gem "spring", "~> 1.4"
7
+ gem "web-console", "~> 2.2"
8
+ gem "thin", "~> 1.6"
9
+ gem "faker", "~> 1.5"
35
10
  end
36
11
 
37
- # Use ActiveModel has_secure_password
38
- # gem 'bcrypt', '~> 3.1.7'
39
- gem 'chosen-rails'
40
- # Use unicorn as the app server
41
- # gem 'unicorn'
12
+ group :development do
13
+ gem "bullet", "~> 4.14"
14
+ gem "better_errors", "~> 2.1"
15
+ end
42
16
 
43
- # Use Capistrano for deployment
44
- # gem 'capistrano', group: :development
17
+ group :test do
18
+ gem "cucumber-rails", "~> 1.4", {:require=>false}
19
+ gem "rspec-rails", "~> 3.3"
20
+ gem "factory_girl_rails", "~> 4.5"
21
+ gem "capybara", "~> 2.5"
22
+ gem "database_cleaner", "~> 1.5"
23
+ gem "launchy", "~> 2.4"
24
+ gem "poltergeist", "~> 1.7"
25
+ gem "selenium-webdriver", "~> 2.47"
26
+ gem "capybara-webkit"
27
+ gem "simplecov", "~> 0.10"
28
+ end
45
29
 
46
- # Use debugger
47
- # gem 'debugger', group: [:development, :test]
30
+ gem "rails", "~> 4.2"
31
+ gem "sqlite3"
32
+ gem "sass-rails", "~> 5.0"
33
+ gem "uglifier", "~> 2.7"
34
+ gem "coffee-rails", "~> 4.1"
35
+ gem "jquery-rails", "~> 4.0"
36
+ gem "turbolinks", "~> 2.5"
37
+ gem "jbuilder", "~> 2.3"
38
+ gem "sdoc", "~> 0.4", {:group=>:doc}
39
+ gem "bootstrap-sass", "~> 3.3"
40
+
41
+ gem "simple_form", "~> 3.2"
42
+ gem "reform", "~> 2.0"
43
+
44
+ gem 'country_state_select', path: '../../'
@@ -2,17 +2,18 @@
2
2
  // listed below.
3
3
  //
4
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.
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
6
  //
7
7
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
8
  // compiled file.
9
9
  //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
13
  //= require jquery
14
+ //= require bootstrap-sprockets
14
15
  //= require jquery_ujs
15
16
  //= require turbolinks
16
17
  //= require chosen-jquery
17
18
  //= require country_state_select
18
- //= require_tree .
19
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ $(document).on 'ready page:load', ->
2
+ CountryStateSelect({ chosen_ui: true, country_id: "location_test_country", state_id: "location_test_state", city_id: "location_test_city" })
@@ -0,0 +1,16 @@
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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ */
14
+ @import "bootstrap-sprockets";
15
+ @import "bootstrap";
16
+ @import "chosen";
@@ -1,3 +1,3 @@
1
1
  // Place all the styles related to the Users controller here.
2
- // They will automatically be included in application.css.
2
+ // They will automatically be included in application.scss.
3
3
  // You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,55 @@
1
+ class LocationsController < ApplicationController
2
+
3
+ def index
4
+ @locations = Location.all
5
+ end
6
+
7
+ def new
8
+ build_location_form
9
+ end
10
+
11
+ def create
12
+ build_location_form
13
+ options = { flash: { success: "You've successfully created a location." } }
14
+ save_location_form(options) or render "new"
15
+ end
16
+
17
+ def show
18
+ load_location_form
19
+ end
20
+
21
+ def update
22
+ load_location_form
23
+ build_location_form
24
+ options = { flash: { success: "You've successfully updated location." } }
25
+ save_location_form(options) or render "show"
26
+ end
27
+
28
+ def destroy
29
+ @location ||= Location.find(params[:id])
30
+ @location.destroy
31
+ redirect_to locations_path, flash: { success: "You've successfully deleted this location." }
32
+ end
33
+
34
+ private
35
+ def location_params
36
+ params.require(:location).permit!
37
+ end
38
+
39
+ def build_location_form
40
+ @location ||= LocationForm.new(Location.new)
41
+ end
42
+
43
+ def load_location_form
44
+ @location ||= LocationForm.new(Location.find(params[:id]))
45
+ end
46
+
47
+ def save_location_form(options)
48
+ if @location.validate(params[:location])
49
+ @location.save
50
+ redirect_to locations_path, options
51
+ end
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,11 @@
1
+ require "reform/form/validation/unique_validator.rb"
2
+
3
+ class LocationForm < Reform::Form
4
+
5
+ include ModelReflections
6
+
7
+ property :test_country
8
+ property :test_state
9
+ property :test_city
10
+
11
+ end
@@ -0,0 +1,2 @@
1
+ class Location < ActiveRecord::Base
2
+ end
@@ -1,14 +1,16 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
- <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
4
+ <title>Locations</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => false %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => false %>
7
7
  <%= csrf_meta_tags %>
8
8
  </head>
9
9
  <body>
10
10
 
11
- <%= yield %>
11
+ <div class="container">
12
+ <%= yield %>
13
+ </div>
12
14
 
13
15
  </body>
14
- </html>
16
+ </html>
@@ -0,0 +1,15 @@
1
+ <%= simple_form_for @location do |f| %>
2
+
3
+ <%= f.input :test_country, label: "Country", collection: CountryStateSelect.countries_collection %>
4
+
5
+ <%= f.input :test_state, CountryStateSelect.state_options(label: "State / Province", form: f, field_names: { :country => :test_country, :state => :home_state } ) %>
6
+
7
+ <%= f.input :test_city, label: "State / Province" %>
8
+
9
+ <br /><br />
10
+
11
+ <%= f.button :submit %>
12
+
13
+ <%= link_to "Cancel", locations_path, class: "btn btn-danger" %>
14
+
15
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <h1>Listing Locations</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Country</th>
7
+ <td>&nbsp;</td>
8
+ <th>State</th>
9
+ <td>&nbsp;</td>
10
+ <td>&nbsp;</td>
11
+ </tr>
12
+ </thead>
13
+
14
+ <tbody>
15
+ <% @locations.each do |location| %>
16
+ <tr>
17
+ <td><%= location.test_country %></td>
18
+ <td>&nbsp;</td>
19
+ <td><%= location.test_state %></td>
20
+ <td>&nbsp;</td>
21
+ <td><%= link_to "X", location, :method => :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %></td>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+
27
+ <br>
28
+
29
+ <%= link_to 'New Location', new_location_path, class: "btn btn-success" %>
@@ -0,0 +1,13 @@
1
+ <div class="container">
2
+
3
+ <div class="panel">
4
+ <div class="panel-heading">
5
+ <h1>Add Location</h1>
6
+ </div>
7
+ </div>
8
+
9
+ <div class="panel-body">
10
+ <%= render partial: "form" %>
11
+ </div>
12
+
13
+ </div>
@@ -0,0 +1,13 @@
1
+ <div class="container">
2
+
3
+ <div class="panel">
4
+ <div class="panel-heading">
5
+ <h1>Edit Location</h1>
6
+ </div>
7
+ </div>
8
+
9
+ <div class="panel-body">
10
+ <%= render partial: "form" %>
11
+ </div>
12
+
13
+ </div>
File without changes
File without changes
File without changes
@@ -58,7 +58,7 @@ Dummy::Application.configure do
58
58
  # config.action_controller.asset_host = "http://assets.example.com"
59
59
 
60
60
  # Precompile additional assets.
61
- # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
61
+ # application.js, application.scss, and all non-JS/CSS in app/assets folder are already added.
62
62
  # config.assets.precompile += %w( search.js )
63
63
 
64
64
  # Ignore bad email addresses and do not raise email delivery errors.
@@ -0,0 +1,165 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ # Wrappers are used by the form builder to generate a
4
+ # complete input. You can remove any component from the
5
+ # wrapper, change the order or even add your own to the
6
+ # stack. The options given below are used to wrap the
7
+ # whole input.
8
+ config.wrappers :default, class: :input,
9
+ hint_class: :field_with_hint, error_class: :field_with_errors do |b|
10
+ ## Extensions enabled by default
11
+ # Any of these extensions can be disabled for a
12
+ # given input by passing: `f.input EXTENSION_NAME => false`.
13
+ # You can make any of these extensions optional by
14
+ # renaming `b.use` to `b.optional`.
15
+
16
+ # Determines whether to use HTML5 (:email, :url, ...)
17
+ # and required attributes
18
+ b.use :html5
19
+
20
+ # Calculates placeholders automatically from I18n
21
+ # You can also pass a string as f.input placeholder: "Placeholder"
22
+ b.use :placeholder
23
+
24
+ ## Optional extensions
25
+ # They are disabled unless you pass `f.input EXTENSION_NAME => true`
26
+ # to the input. If so, they will retrieve the values from the model
27
+ # if any exists. If you want to enable any of those
28
+ # extensions by default, you can change `b.optional` to `b.use`.
29
+
30
+ # Calculates maxlength from length validations for string inputs
31
+ b.optional :maxlength
32
+
33
+ # Calculates pattern from format validations for string inputs
34
+ b.optional :pattern
35
+
36
+ # Calculates min and max from length validations for numeric inputs
37
+ b.optional :min_max
38
+
39
+ # Calculates readonly automatically from readonly attributes
40
+ b.optional :readonly
41
+
42
+ ## Inputs
43
+ b.use :label_input
44
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
45
+ b.use :error, wrap_with: { tag: :span, class: :error }
46
+
47
+ ## full_messages_for
48
+ # If you want to display the full error message for the attribute, you can
49
+ # use the component :full_error, like:
50
+ #
51
+ # b.use :full_error, wrap_with: { tag: :span, class: :error }
52
+ end
53
+
54
+ # The default wrapper to be used by the FormBuilder.
55
+ config.default_wrapper = :default
56
+
57
+ # Define the way to render check boxes / radio buttons with labels.
58
+ # Defaults to :nested for bootstrap config.
59
+ # inline: input + label
60
+ # nested: label > input
61
+ config.boolean_style = :nested
62
+
63
+ # Default class for buttons
64
+ config.button_class = 'btn'
65
+
66
+ # Method used to tidy up errors. Specify any Rails Array method.
67
+ # :first lists the first message for each field.
68
+ # Use :to_sentence to list all errors for each field.
69
+ # config.error_method = :first
70
+
71
+ # Default tag used for error notification helper.
72
+ config.error_notification_tag = :div
73
+
74
+ # CSS class to add for error notification helper.
75
+ config.error_notification_class = 'error_notification'
76
+
77
+ # ID to add for error notification helper.
78
+ # config.error_notification_id = nil
79
+
80
+ # Series of attempts to detect a default label method for collection.
81
+ # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
82
+
83
+ # Series of attempts to detect a default value method for collection.
84
+ # config.collection_value_methods = [ :id, :to_s ]
85
+
86
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
87
+ # config.collection_wrapper_tag = nil
88
+
89
+ # You can define the class to use on all collection wrappers. Defaulting to none.
90
+ # config.collection_wrapper_class = nil
91
+
92
+ # You can wrap each item in a collection of radio/check boxes with a tag,
93
+ # defaulting to :span.
94
+ # config.item_wrapper_tag = :span
95
+
96
+ # You can define a class to use in all item wrappers. Defaulting to none.
97
+ # config.item_wrapper_class = nil
98
+
99
+ # How the label text should be generated altogether with the required text.
100
+ # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
101
+
102
+ # You can define the class to use on all labels. Default is nil.
103
+ # config.label_class = nil
104
+
105
+ # You can define the default class to be used on forms. Can be overriden
106
+ # with `html: { :class }`. Defaulting to none.
107
+ # config.default_form_class = nil
108
+
109
+ # You can define which elements should obtain additional classes
110
+ # config.generate_additional_classes_for = [:wrapper, :label, :input]
111
+
112
+ # Whether attributes are required by default (or not). Default is true.
113
+ # config.required_by_default = true
114
+
115
+ # Tell browsers whether to use the native HTML5 validations (novalidate form option).
116
+ # These validations are enabled in SimpleForm's internal config but disabled by default
117
+ # in this configuration, which is recommended due to some quirks from different browsers.
118
+ # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
119
+ # change this configuration to true.
120
+ config.browser_validations = false
121
+
122
+ # Collection of methods to detect if a file type was given.
123
+ # config.file_methods = [ :mounted_as, :file?, :public_filename ]
124
+
125
+ # Custom mappings for input types. This should be a hash containing a regexp
126
+ # to match as key, and the input type that will be used when the field name
127
+ # matches the regexp as value.
128
+ # config.input_mappings = { /count/ => :integer }
129
+
130
+ # Custom wrappers for input types. This should be a hash containing an input
131
+ # type as key and the wrapper that will be used for all inputs with specified type.
132
+ # config.wrapper_mappings = { string: :prepend }
133
+
134
+ # Namespaces where SimpleForm should look for custom input classes that
135
+ # override default inputs.
136
+ # config.custom_inputs_namespaces << "CustomInputs"
137
+
138
+ # Default priority for time_zone inputs.
139
+ # config.time_zone_priority = nil
140
+
141
+ # Default priority for country inputs.
142
+ # config.country_priority = nil
143
+
144
+ # When false, do not use translations for labels.
145
+ # config.translate_labels = true
146
+
147
+ # Automatically discover new inputs in Rails' autoload path.
148
+ # config.inputs_discovery = true
149
+
150
+ # Cache SimpleForm inputs discovery
151
+ # config.cache_discovery = !Rails.env.development?
152
+
153
+ # Default class for inputs
154
+ # config.input_class = nil
155
+
156
+ # Define the default class of the input wrapper of the boolean input.
157
+ config.boolean_label_class = 'checkbox'
158
+
159
+ # Defines if the default input wrapper class should be included in radio
160
+ # collection wrappers.
161
+ # config.include_default_input_wrapper_class = true
162
+
163
+ # Defines which i18n scope will be used in Simple Form.
164
+ # config.i18n_scope = 'simple_form'
165
+ end