autocomplete_zipcode 1.2.0 → 2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ed94117dbf296bba2829260f28b1a92b7df85ed10267690ee721c4a4b2c3641
4
- data.tar.gz: 89b6e967285c45a59f06bcb365eac064dcfababb0f796c79c94eed70f605f746
3
+ metadata.gz: f8b7aefc93d38da2a23783246342051799bae1e0cee0beb842e80c85e10afde8
4
+ data.tar.gz: f0a528f4432d060b5c3518cc268a8278facf36bfae9ce8c8e1e701a8db282373
5
5
  SHA512:
6
- metadata.gz: d25c3f1436c6e5d4026fde2a173a84b35cd4d63e0b45abc3c5ca8292d167017d4d0bcfa9792e2c52170b5e2d5a364382876093499cd5506b16007c7af880c5ad
7
- data.tar.gz: b7a77efed2f32bed42d43503e52a6650439bd8888857eeb2c7551697b4a6e1099a31e4875f65cfbbfc440a50bc0a0ee3a1c9ad9c0f204be468f82bfced584cb4
6
+ metadata.gz: 5aaa4ea4c71395e3b013f101f69590f9c94f453ff220169957627f6f894039bc571fe9a11e436114d1fde4873fed8f9ef69c7fea7f277b19a171b06862e2a3a7
7
+ data.tar.gz: '0893608e98e986999b174ded384a14f881be7e2113074691293d3d5f8021fb920748ddc68e96df20e0a62f8c75f0ef57e188eb57d9402b39181133cb87c1d2bd'
data/.codeclimate.yml ADDED
@@ -0,0 +1,10 @@
1
+ version: "2"
2
+ plugins:
3
+ rubocop:
4
+ enabled: true
5
+ channel: rubocop-0-60
6
+ config:
7
+ file: ".rubocop.yml"
8
+ exclude_patterns:
9
+ - "spec/"
10
+ - "!spec/support/helpers"
@@ -0,0 +1,19 @@
1
+ # Overview
2
+
3
+ ## Implementation Details
4
+
5
+ ## Required Documentation Updates
6
+
7
+ None.
8
+
9
+ ## Testing Notes
10
+
11
+ None.
12
+
13
+ ## API Changes
14
+
15
+ None.
16
+
17
+ ## External Dependency Changes
18
+
19
+ None.
data/.gitignore CHANGED
@@ -1,9 +1,13 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
9
+
10
+ spec/dummy/log/*.log
11
+ spec/dummy/tmp
12
+ spec/dummy/test
13
+ spec/dummy/db/*.sqlite3
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ AllCops:
2
+ SuggestExtensions: false
3
+ Exclude:
4
+ - 'spec/**/*.rb'
5
+ - 'spec/dummy/**/*'
6
+ Style/Documentation:
7
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ autocomplete_zipcode
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/.travis.yml CHANGED
@@ -1,4 +1,15 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=$CODE_CLIMATE_TOKEN
1
4
  language: ruby
2
5
  rvm:
3
6
  - 2.6.3
4
- before_install: gem install bundler:2.1.4
7
+ before_script:
8
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
+ - chmod +x ./cc-test-reporter
10
+ - ./cc-test-reporter before-build
11
+ - gem install bundler:2.1.4
12
+ script:
13
+ - bundle exec rspec
14
+ after_script:
15
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  # Specify your gem's dependencies in autocomplete_zipcode.gemspec
3
5
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,209 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ autocomplete_zipcode (2.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actioncable (6.1.3.1)
10
+ actionpack (= 6.1.3.1)
11
+ activesupport (= 6.1.3.1)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailbox (6.1.3.1)
15
+ actionpack (= 6.1.3.1)
16
+ activejob (= 6.1.3.1)
17
+ activerecord (= 6.1.3.1)
18
+ activestorage (= 6.1.3.1)
19
+ activesupport (= 6.1.3.1)
20
+ mail (>= 2.7.1)
21
+ actionmailer (6.1.3.1)
22
+ actionpack (= 6.1.3.1)
23
+ actionview (= 6.1.3.1)
24
+ activejob (= 6.1.3.1)
25
+ activesupport (= 6.1.3.1)
26
+ mail (~> 2.5, >= 2.5.4)
27
+ rails-dom-testing (~> 2.0)
28
+ actionpack (6.1.3.1)
29
+ actionview (= 6.1.3.1)
30
+ activesupport (= 6.1.3.1)
31
+ rack (~> 2.0, >= 2.0.9)
32
+ rack-test (>= 0.6.3)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
+ actiontext (6.1.3.1)
36
+ actionpack (= 6.1.3.1)
37
+ activerecord (= 6.1.3.1)
38
+ activestorage (= 6.1.3.1)
39
+ activesupport (= 6.1.3.1)
40
+ nokogiri (>= 1.8.5)
41
+ actionview (6.1.3.1)
42
+ activesupport (= 6.1.3.1)
43
+ builder (~> 3.1)
44
+ erubi (~> 1.4)
45
+ rails-dom-testing (~> 2.0)
46
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
+ activejob (6.1.3.1)
48
+ activesupport (= 6.1.3.1)
49
+ globalid (>= 0.3.6)
50
+ activemodel (6.1.3.1)
51
+ activesupport (= 6.1.3.1)
52
+ activerecord (6.1.3.1)
53
+ activemodel (= 6.1.3.1)
54
+ activesupport (= 6.1.3.1)
55
+ activestorage (6.1.3.1)
56
+ actionpack (= 6.1.3.1)
57
+ activejob (= 6.1.3.1)
58
+ activerecord (= 6.1.3.1)
59
+ activesupport (= 6.1.3.1)
60
+ marcel (~> 1.0.0)
61
+ mini_mime (~> 1.0.2)
62
+ activesupport (6.1.3.1)
63
+ concurrent-ruby (~> 1.0, >= 1.0.2)
64
+ i18n (>= 1.6, < 2)
65
+ minitest (>= 5.1)
66
+ tzinfo (~> 2.0)
67
+ zeitwerk (~> 2.3)
68
+ ast (2.4.2)
69
+ builder (3.2.4)
70
+ coderay (1.1.3)
71
+ concurrent-ruby (1.1.8)
72
+ crass (1.0.6)
73
+ diff-lcs (1.4.4)
74
+ docile (1.3.5)
75
+ erubi (1.10.0)
76
+ globalid (0.4.2)
77
+ activesupport (>= 4.2.0)
78
+ i18n (1.8.10)
79
+ concurrent-ruby (~> 1.0)
80
+ jquery-rails (4.4.0)
81
+ rails-dom-testing (>= 1, < 3)
82
+ railties (>= 4.2.0)
83
+ thor (>= 0.14, < 2.0)
84
+ loofah (2.9.0)
85
+ crass (~> 1.0.2)
86
+ nokogiri (>= 1.5.9)
87
+ mail (2.7.1)
88
+ mini_mime (>= 0.1.1)
89
+ marcel (1.0.1)
90
+ method_source (1.0.0)
91
+ mini_mime (1.0.3)
92
+ mini_portile2 (2.5.0)
93
+ minitest (5.14.4)
94
+ nio4r (2.5.7)
95
+ nokogiri (1.11.2)
96
+ mini_portile2 (~> 2.5.0)
97
+ racc (~> 1.4)
98
+ parallel (1.20.1)
99
+ parser (3.0.0.0)
100
+ ast (~> 2.4.1)
101
+ pry (0.14.0)
102
+ coderay (~> 1.1)
103
+ method_source (~> 1.0)
104
+ racc (1.5.2)
105
+ rack (2.2.3)
106
+ rack-test (1.1.0)
107
+ rack (>= 1.0, < 3)
108
+ rails (6.1.3.1)
109
+ actioncable (= 6.1.3.1)
110
+ actionmailbox (= 6.1.3.1)
111
+ actionmailer (= 6.1.3.1)
112
+ actionpack (= 6.1.3.1)
113
+ actiontext (= 6.1.3.1)
114
+ actionview (= 6.1.3.1)
115
+ activejob (= 6.1.3.1)
116
+ activemodel (= 6.1.3.1)
117
+ activerecord (= 6.1.3.1)
118
+ activestorage (= 6.1.3.1)
119
+ activesupport (= 6.1.3.1)
120
+ bundler (>= 1.15.0)
121
+ railties (= 6.1.3.1)
122
+ sprockets-rails (>= 2.0.0)
123
+ rails-dom-testing (2.0.3)
124
+ activesupport (>= 4.2.0)
125
+ nokogiri (>= 1.6)
126
+ rails-html-sanitizer (1.3.0)
127
+ loofah (~> 2.3)
128
+ railties (6.1.3.1)
129
+ actionpack (= 6.1.3.1)
130
+ activesupport (= 6.1.3.1)
131
+ method_source
132
+ rake (>= 0.8.7)
133
+ thor (~> 1.0)
134
+ rainbow (3.0.0)
135
+ rake (13.0.3)
136
+ regexp_parser (2.1.1)
137
+ rexml (3.2.4)
138
+ rspec-core (3.10.1)
139
+ rspec-support (~> 3.10.0)
140
+ rspec-expectations (3.10.1)
141
+ diff-lcs (>= 1.2.0, < 2.0)
142
+ rspec-support (~> 3.10.0)
143
+ rspec-mocks (3.10.2)
144
+ diff-lcs (>= 1.2.0, < 2.0)
145
+ rspec-support (~> 3.10.0)
146
+ rspec-rails (5.0.1)
147
+ actionpack (>= 5.2)
148
+ activesupport (>= 5.2)
149
+ railties (>= 5.2)
150
+ rspec-core (~> 3.10)
151
+ rspec-expectations (~> 3.10)
152
+ rspec-mocks (~> 3.10)
153
+ rspec-support (~> 3.10)
154
+ rspec-support (3.10.2)
155
+ rubocop (1.12.0)
156
+ parallel (~> 1.10)
157
+ parser (>= 3.0.0.0)
158
+ rainbow (>= 2.2.2, < 4.0)
159
+ regexp_parser (>= 1.8, < 3.0)
160
+ rexml
161
+ rubocop-ast (>= 1.2.0, < 2.0)
162
+ ruby-progressbar (~> 1.7)
163
+ unicode-display_width (>= 1.4.0, < 3.0)
164
+ rubocop-ast (1.4.1)
165
+ parser (>= 2.7.1.5)
166
+ ruby-progressbar (1.11.0)
167
+ simple_form (5.1.0)
168
+ actionpack (>= 5.2)
169
+ activemodel (>= 5.2)
170
+ simplecov (0.20.0)
171
+ docile (~> 1.1)
172
+ simplecov-html (~> 0.11)
173
+ simplecov_json_formatter (~> 0.1)
174
+ simplecov-html (0.12.3)
175
+ simplecov_json_formatter (0.1.2)
176
+ sprockets (4.0.2)
177
+ concurrent-ruby (~> 1.0)
178
+ rack (> 1, < 3)
179
+ sprockets-rails (3.2.2)
180
+ actionpack (>= 4.0)
181
+ activesupport (>= 4.0)
182
+ sprockets (>= 3.0.0)
183
+ sqlite3 (1.4.2)
184
+ thor (1.1.0)
185
+ tzinfo (2.0.4)
186
+ concurrent-ruby (~> 1.0)
187
+ unicode-display_width (2.0.0)
188
+ websocket-driver (0.7.3)
189
+ websocket-extensions (>= 0.1.0)
190
+ websocket-extensions (0.1.5)
191
+ zeitwerk (2.4.2)
192
+
193
+ PLATFORMS
194
+ ruby
195
+
196
+ DEPENDENCIES
197
+ autocomplete_zipcode!
198
+ jquery-rails (~> 4.4.0)
199
+ pry (~> 0.14.0)
200
+ rails (>= 4.2.0)
201
+ rake (~> 13.0.3)
202
+ rspec-rails (~> 5.0.0)
203
+ rubocop (~> 1.12.0)
204
+ simple_form (>= 5.1.0)
205
+ simplecov (~> 0.20.0)
206
+ sqlite3 (~> 1.4.2)
207
+
208
+ BUNDLED WITH
209
+ 2.1.4
data/Makefile ADDED
@@ -0,0 +1,2 @@
1
+ default:
2
+ ./bin/console
data/README.md CHANGED
@@ -2,9 +2,16 @@
2
2
 
3
3
  This gem was built to "automagically" fills an address form, for Rails version >= 3.1.
4
4
 
5
+ ## Status
6
+
7
+ [![Build Status](https://api.travis-ci.com/marcelobarreto/autocomplete_zipcode.svg?branch=master)](https://travis-ci.org/marcelobarreto/autocomplete_zipcode)
8
+ [![Maintainability](https://api.codeclimate.com/v1/badges/37008f3eeaaf2ea47122/maintainability)](https://codeclimate.com/github/marcelobarreto/autocomplete_zipcode/maintainability)
9
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/37008f3eeaaf2ea47122/test_coverage)](https://codeclimate.com/github/marcelobarreto/autocomplete_zipcode/test_coverage)
10
+ [![RubyGems](http://img.shields.io/gem/dt/autocomplete_zipcode.svg?style=flat)](http://rubygems.org/gems/autocomplete_zipcode)
11
+
5
12
  ## Try it
6
13
 
7
- [HerokuApp](http://autocompletezipcode.herokuapp.com)
14
+ [Online](http://autocompletezipcode.herokuapp.com)
8
15
 
9
16
  ## Installation
10
17
 
@@ -17,20 +24,26 @@ gem 'autocomplete_zipcode'
17
24
  And then execute:
18
25
 
19
26
  ```bash
20
- $ bundle install
27
+ bundle install
21
28
  ```
22
29
 
23
- ## Usage
30
+ ## Simple Usage
24
31
 
25
32
  In app/assets/javascripts/application.js, you should add as follows:
26
33
 
27
34
  ```js
35
+ // app/assets/javascripts/application.js
28
36
  //= require ...
29
37
  //= require turbolinks
38
+ //= require jquery
30
39
  //= require autocomplete_zipcode
40
+
41
+ $(document).on('ready', () => {
42
+ AutocompleteZipcode.mount();
43
+ });
31
44
  ```
32
45
 
33
- Basic Example:
46
+ ## Basic Example
34
47
 
35
48
  ```erb
36
49
  <%= simple_form_for :example do |f| %>
@@ -49,8 +62,8 @@ If you are not using simple_form, then simply add the `data-provider="zipcode"`
49
62
  ```erb
50
63
  <%= form_for :example do |f| %>
51
64
  ...
52
- <%= f.text_field :zipcode, data: {provider: :zipcode} %>
53
- <%= f.text_field :street, data: {provider: :street} %>
65
+ <%= f.text_field :zipcode, data: { autocomplete_zipcode_provider: :zipcode } %>
66
+ <%= f.text_field :street, data: { autocomplete_zipcode_provider: :street } %>
54
67
  ...
55
68
  <% end %>
56
69
  ```
@@ -60,15 +73,46 @@ If you are not using simple_form, then simply add the `data-provider="zipcode"`
60
73
  Simply add an event listener callback to `zipcode.error`, for example:
61
74
 
62
75
  ```js
63
- document.addEventListener('zipcode.error', function(e) {
76
+ // app/assets/javascripts/application.js
77
+
78
+ document.addEventListener('zipcode.error', () => {
64
79
  alert('Invalid zipcode!!!')
65
80
  });
66
81
  ```
67
82
 
68
- ## Sample projects
83
+ ## Advanced Usage
69
84
 
70
- For an example, take a look at [this repository](https://github.com/marcelobarreto/autocomplete_zipcode_example).
85
+ ```js
86
+ // app/assets/javascripts/application.js
87
+ //= require ...
88
+ //= require turbolinks
89
+ //= require jquery
90
+ //= require autocomplete_zipcode
91
+
92
+ $(document).on('ready', () => {
93
+ AutocompleteZipcode.mount({
94
+ onSuccess: (containerEl, zipcodeEl) => {
95
+ console.log(containerEl, zipcodeEl);
96
+ },
97
+ onFail: (containerEl, zipcodeEl) => {
98
+ console.log(containerEl, zipcodeEl);
99
+ },
100
+ });
101
+
102
+ document.addEventListener('zipcode.success', () => {
103
+ console.log('zipcode fetched successfully');
104
+ });
105
+
106
+ document.addEventListener('zipcode.error', () => {
107
+ console.log('zipcode fetch failed');
108
+ });
109
+ });
110
+ ```
111
+
112
+ ## Sample projects
71
113
 
114
+ For an online example, take a look at [this repository](https://github.com/marcelobarreto/autocomplete_zipcode_example).
115
+ You can also see it working on the dummy application (`spec/dummy`)
72
116
 
73
117
  ## Contributing
74
118
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AutocompleteZipcode::CityInput < SimpleForm::Inputs::StringInput
4
+ def input(wrapper_options)
5
+ input_html_options[:data] ||= {}
6
+ input_html_options[:data].merge!({ autocomplete_zipcode_provider: :city })
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AutocompleteZipcode::IbgeInput < SimpleForm::Inputs::StringInput
4
+ def input(wrapper_options)
5
+ input_html_options[:data] ||= {}
6
+ input_html_options[:data].merge!({ autocomplete_zipcode_provider: :ibge })
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AutocompleteZipcode::NeighborhoodInput < SimpleForm::Inputs::StringInput
4
+ def input(wrapper_options)
5
+ input_html_options[:data] ||= {}
6
+ input_html_options[:data].merge!({ autocomplete_zipcode_provider: :neighborhood })
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AutocompleteZipcode::StateInput < SimpleForm::Inputs::StringInput
4
+ def input(wrapper_options)
5
+ input_html_options[:data] ||= {}
6
+ input_html_options[:data].merge!({ autocomplete_zipcode_provider: :state })
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AutocompleteZipcode::StateSelectInput < SimpleForm::Inputs::CollectionSelectInput
4
+ def input(wrapper_options)
5
+ input_html_options[:data] ||= {}
6
+ input_html_options[:data].merge!({ autocomplete_zipcode_provider: :state })
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AutocompleteZipcode::StreetInput < SimpleForm::Inputs::StringInput
4
+ def input(wrapper_options)
5
+ input_html_options[:data] ||= {}
6
+ input_html_options[:data].merge!({ autocomplete_zipcode_provider: :street })
7
+ super
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AutocompleteZipcode::ZipcodeInput < SimpleForm::Inputs::StringInput
4
+ def input(wrapper_options)
5
+ input_html_options[:data] ||= {}
6
+ input_html_options[:data].merge!({ autocomplete_zipcode_provider: :zipcode })
7
+ super
8
+ end
9
+ end
@@ -1,22 +1,32 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'autocomplete_zipcode/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "autocomplete_zipcode"
8
+ spec.name = 'autocomplete_zipcode'
8
9
  spec.version = AutocompleteZicode::VERSION
9
- spec.authors = ["Marcelo Barreto"]
10
- spec.email = ["marcelobarretojunior@gmail.com"]
10
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6')
11
+ spec.authors = ['Marcelo Barreto (@marcelobarreto)']
12
+ spec.email = ['marcelobarretojunior@gmail.com']
11
13
 
12
- spec.summary = %q{Fill in your brazillian addresses automagically}
13
- spec.homepage = "https://github.com/marcelobarreto/autocomplete_zipcode"
14
+ spec.summary = 'Fill in your brazillian addresses automagically'
15
+ spec.homepage = 'https://github.com/marcelobarreto/autocomplete_zipcode'
14
16
 
15
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
- spec.bindir = "exe"
18
+ spec.bindir = 'exe'
17
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'rails', '>= 4.2.0'
19
23
 
20
- spec.add_development_dependency "bundler", "~> 2.1"
21
- spec.add_development_dependency "rake", "~> 13.0"
24
+ spec.add_development_dependency 'jquery-rails', '~> 4.4.0'
25
+ spec.add_development_dependency 'pry', '~> 0.14.0'
26
+ spec.add_development_dependency 'rake', '~> 13.0.3'
27
+ spec.add_development_dependency 'rspec-rails', '~> 5.0.0'
28
+ spec.add_development_dependency 'rubocop', '~> 1.12.0'
29
+ spec.add_development_dependency 'simplecov', '~> 0.20.0'
30
+ spec.add_development_dependency 'simple_form', '>= 5.1.0'
31
+ spec.add_development_dependency 'sqlite3', '~> 1.4.2'
22
32
  end
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "sweetalert"
4
+ require 'bundler/setup'
5
+ require 'rails'
6
+ require 'simple_form'
7
+ require 'autocomplete_zipcode'
5
8
 
6
9
  # You can add fixtures and/or initialization code here to make experimenting
7
10
  # with your gem easier. You can also use a different console, if you like.
8
11
 
9
12
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
13
+ require 'pry'
14
+ Pry.start
data/bin/rails ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This command will automatically be run when you run "rails" with Rails gems
5
+ # installed from the root of your application.
6
+
7
+ APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
11
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
12
+
13
+ require 'rails'
14
+ # Pick the frameworks you want:
15
+ require 'active_model/railtie'
16
+ require 'active_job/railtie'
17
+ require 'active_record/railtie'
18
+ require 'action_controller/railtie'
19
+ require 'rails/engine/commands'
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Uncomment this and change the path if necessary to include your own
4
+ # components.
5
+ # See https://github.com/heartcombo/simple_form#custom-components to know
6
+ # more about custom components.
7
+ Dir[Rails.root.join('app/inputs/**/*.rb')].each { |f| require f }
8
+ #
9
+ # Use this setup block to configure all options available in SimpleForm.
10
+
11
+ SimpleForm.setup do |config|
12
+ config.custom_inputs_namespaces << "AutocompleteZipcode"
13
+ end
@@ -1,9 +1,16 @@
1
- require "autocomplete_zipcode/version"
1
+ # frozen_string_literal: true
2
2
 
3
- [:zipcode, :street, :neighborhood, :city, :state, :ibge].each do |input|
4
- autoload :"#{input.capitalize}Input", "autocomplete_zipcode/simple_form/#{input}_input"
5
- end
3
+ require 'autocomplete_zipcode/version'
4
+ require 'rails'
6
5
 
7
- module AutocompleteZicode
8
- class Engine < ::Rails::Engine; end
6
+ module AutocompleteZipcode
7
+ if defined?(SimpleForm)
8
+ autoload :ZipcodeInput, 'app/inputs/autocomplete_zipcode/zipcode_input'
9
+ autoload :StreetInput, 'app/inputs/autocomplete_zipcode/street_input'
10
+ autoload :NeighborhoodInput, 'app/inputs/autocomplete_zipcode/neighborhood_input'
11
+ autoload :CityInput, 'app/inputs/autocomplete_zipcode/city_input'
12
+ autoload :StateInput, 'app/inputs/autocomplete_zipcode/state_input'
13
+ autoload :StateSelectInput, 'app/inputs/autocomplete_zipcode/state_select_input'
14
+ autoload :IbgeInput, 'app/inputs/autocomplete_zipcode/ibge_input'
15
+ end
9
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AutocompleteZicode
2
- VERSION = "1.2.0"
4
+ VERSION = '2.0.0'
3
5
  end
@@ -1,37 +1,47 @@
1
- const inputs = {
2
- street: 'logradouro',
3
- neighborhood: 'bairro',
4
- city: 'localidade',
5
- state: 'uf',
6
- ibge: 'ibge',
7
- };
1
+ const AutocompleteZipcode = {
2
+ config: {
3
+ container: 'form',
4
+ selectorPrefix: 'data-autocomplete-zipcode-provider',
5
+ serviceUrl: ({ zipcode }) => `https://viacep.com.br/ws/${zipcode}/json`,
6
+ },
7
+ inputs: {
8
+ street: 'logradouro',
9
+ neighborhood: 'bairro',
10
+ city: 'localidade',
11
+ state: 'uf',
12
+ ibge: 'ibge',
13
+ },
14
+ mount: ({ onSuccess, onFail, config = AutocompleteZipcode.config }) => {
15
+ if (typeof jQuery === 'undefined') {
16
+ console.error('jQuery is required by autocomplete_zipcode gem')
17
+ return;
18
+ }
19
+ const { inputs } = AutocompleteZipcode;
20
+ const { container, selectorPrefix, serviceUrl } = config;
8
21
 
9
- const ready = () => {
10
- const zipCodeInput = $('[data-provider="zipcode"]');
11
- zipCodeInput.keyup(() => {
12
- const zipcode = zipCodeInput.val().replace(/[^0-9]/g, '');
22
+ const observable = $(container).find(`[${selectorPrefix}="zipcode"]`);
13
23
 
14
- if(zipcode.length === 8) {
15
- $.get(`https://viacep.com.br/ws/${zipcode}/json`).then(response => {
16
- let event;
17
- if (response.erro) {
18
- event = new Event('zipcode.error');
19
- } else {
20
- event = new Event('zipcode.success');
21
- }
24
+ observable.keyup((e) => {
25
+ e.preventDefault();
26
+ e.stopPropagation();
22
27
 
23
- document.dispatchEvent(event);
28
+ const { target: { value } } = e;
29
+ const $el = $(e.target);
30
+ const $container = $el.parents().closest($(container));
31
+ const zipcode = value.replace(/[^0-9]/g, '');
24
32
 
25
- for(var key in inputs) {
26
- $(`[data-provider="'${key}'"]`).val(response[inputs[key]]);
27
- }
28
- });
29
- };
30
- })
33
+ if (zipcode.length === 8) {
34
+ $.get(serviceUrl({ zipcode })).then(response => {
35
+ if (response.erro) {
36
+ onFail?.call(this, $container[0], $el[0]);
37
+ document.dispatchEvent(new Event('zipcode.error'));
38
+ } else {
39
+ for (var key in inputs) $container.find(`[${selectorPrefix}="${key}"]`).val(response[inputs[key]]);
40
+ onSuccess?.call(this, $container[0], $el[0]);
41
+ document.dispatchEvent(new Event('zipcode.success'));
42
+ }
43
+ });
44
+ }
45
+ });
46
+ },
31
47
  };
32
-
33
- if (typeof Turbolinks == "undefined") {
34
- $(document).ready(ready);
35
- } else {
36
- $(document).on("turbolinks:load", ready);
37
- }
metadata CHANGED
@@ -1,43 +1,141 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autocomplete_zipcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Marcelo Barreto
7
+ - Marcelo Barreto (@marcelobarreto)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-29 00:00:00.000000000 Z
11
+ date: 2021-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: jquery-rails
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '2.1'
33
+ version: 4.4.0
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '2.1'
40
+ version: 4.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.14.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.14.0
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - "~>"
32
60
  - !ruby/object:Gem::Version
33
- version: '13.0'
61
+ version: 13.0.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 13.0.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 5.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 5.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.12.0
34
90
  type: :development
35
91
  prerelease: false
36
92
  version_requirements: !ruby/object:Gem::Requirement
37
93
  requirements:
38
94
  - - "~>"
39
95
  - !ruby/object:Gem::Version
40
- version: '13.0'
96
+ version: 1.12.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.20.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.20.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simple_form
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 5.1.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 5.1.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.4.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.4.2
41
139
  description:
42
140
  email:
43
141
  - marcelobarretojunior@gmail.com
@@ -45,21 +143,32 @@ executables: []
45
143
  extensions: []
46
144
  extra_rdoc_files: []
47
145
  files:
146
+ - ".codeclimate.yml"
147
+ - ".github/pull_request_template.md"
48
148
  - ".gitignore"
149
+ - ".rspec"
150
+ - ".rubocop.yml"
151
+ - ".ruby-gemset"
152
+ - ".ruby-version"
49
153
  - ".travis.yml"
50
154
  - Gemfile
155
+ - Gemfile.lock
156
+ - Makefile
51
157
  - README.md
52
158
  - Rakefile
159
+ - app/inputs/autocomplete_zipcode/city_input.rb
160
+ - app/inputs/autocomplete_zipcode/ibge_input.rb
161
+ - app/inputs/autocomplete_zipcode/neighborhood_input.rb
162
+ - app/inputs/autocomplete_zipcode/state_input.rb
163
+ - app/inputs/autocomplete_zipcode/state_select_input.rb
164
+ - app/inputs/autocomplete_zipcode/street_input.rb
165
+ - app/inputs/autocomplete_zipcode/zipcode_input.rb
53
166
  - autocomplete_zipcode.gemspec
54
167
  - bin/console
168
+ - bin/rails
55
169
  - bin/setup
170
+ - config/initializers/simple_form_autocomplete_zipcode.rb
56
171
  - lib/autocomplete_zipcode.rb
57
- - lib/autocomplete_zipcode/simple_form/city_input.rb
58
- - lib/autocomplete_zipcode/simple_form/ibge_input.rb
59
- - lib/autocomplete_zipcode/simple_form/neighborhood_input.rb
60
- - lib/autocomplete_zipcode/simple_form/state_input.rb
61
- - lib/autocomplete_zipcode/simple_form/street_input.rb
62
- - lib/autocomplete_zipcode/simple_form/zipcode_input.rb
63
172
  - lib/autocomplete_zipcode/version.rb
64
173
  - vendor/assets/javascripts/.keep
65
174
  - vendor/assets/javascripts/autocomplete_zipcode.js
@@ -74,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
183
  requirements:
75
184
  - - ">="
76
185
  - !ruby/object:Gem::Version
77
- version: '0'
186
+ version: '2.6'
78
187
  required_rubygems_version: !ruby/object:Gem::Requirement
79
188
  requirements:
80
189
  - - ">="
@@ -1,7 +0,0 @@
1
- class CityInput < SimpleForm::Inputs::StringInput
2
- def input(wrapper_options)
3
- input_html_options[:data] ||= {}
4
- input_html_options[:data].merge!({ provider: 'city' })
5
- super
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- class IbgeInput < SimpleForm::Inputs::StringInput
2
- def input(wrapper_options)
3
- input_html_options[:data] ||= {}
4
- input_html_options[:data].merge!({ provider: 'ibge' })
5
- super
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- class NeighborhoodInput < SimpleForm::Inputs::StringInput
2
- def input(wrapper_options)
3
- input_html_options[:data] ||= {}
4
- input_html_options[:data].merge!({ provider: 'neighborhood' })
5
- super
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- class StateInput < SimpleForm::Inputs::StringInput
2
- def input(wrapper_options)
3
- input_html_options[:data] ||= {}
4
- input_html_options[:data].merge!({ provider: 'state' })
5
- super
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- class StreetInput < SimpleForm::Inputs::StringInput
2
- def input(wrapper_options)
3
- input_html_options[:data] ||= {}
4
- input_html_options[:data].merge!({ provider: 'street' })
5
- super
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- class ZipcodeInput < SimpleForm::Inputs::StringInput
2
- def input(wrapper_options)
3
- input_html_options[:data] ||= {}
4
- input_html_options[:data].merge!({ provider: 'zipcode' })
5
- super
6
- end
7
- end