run_cl 1.6.2 → 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
  SHA1:
3
- metadata.gz: 6a17e5a29daeca5dfdc021df36397c9999a472d8
4
- data.tar.gz: 4e71f0fc8392d0e8d9ba3a274d0bed4947533756
3
+ metadata.gz: 8cb54bf640f468045189e333724a16708ec2306c
4
+ data.tar.gz: eed3a1e1e9cb2dc131063a0c31af223ad6fc5708
5
5
  SHA512:
6
- metadata.gz: 91a7f3ac29364d5259cd66d8abfd81f1ecf8fdb29de0f748365fd536073a55f58e6d12b9f18d40477d682c6f7c8bf95980abcdc4e2a1e1398e7a2802af9359e0
7
- data.tar.gz: 819802be60bf82ccdb50325b2cc120e3b72e16a87f5a0a8d455fb3a09689f3174ecb3670ad3f82798098474f2f75969f277fa51f4679f19c97d345667d97fcb7
6
+ metadata.gz: efb616461479286f591c5871326521fd855c7204e14e51616a956bf01341dbd5e304856fb11099132519444b50453d459dbffddefc80dc3faa174adc0a435264
7
+ data.tar.gz: efab342c30156068757bb193c94d43496713ec5dd8112c765ccd420293da23150dd200b9bba74a98c95b6043c273330d1875d33c0b9c0c4d212b335c3e5419ad
data/README.md CHANGED
@@ -97,6 +97,23 @@ If you need to remove a RUN format:
97
97
  Run.remove_format('11.111.111-1', false)
98
98
  ====>> 11111111
99
99
 
100
+ ## Client side validation
101
+ This gem comes with client side validation support using the gem [client_side_validations](https://github.com/DavyJonesLocker/client_side_validations)
102
+
103
+ To enable, add the following javascript to your manifest:
104
+
105
+ //= clientsidevalidation.run
106
+
107
+ ## Client side formatting
108
+ To automaticaly format run inputs, first add the following javascript to your manifest:
109
+
110
+ //= run-formatter
111
+
112
+ Then, add the "run" class to your inputs, For example, if you are using [simple_form](https://github.com/plataformatec/simple_form) gem:
113
+
114
+ = f.input :run, input_html: {class: "rut"}
115
+ = f.input_field, class: "rut"
116
+
100
117
  ## Assumptions
101
118
 
102
119
  You are saving the RUN as a string, and that is keeping raw (without dots and dashes).
@@ -0,0 +1,5 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ run: must be a valid rut
5
+ uniq_run: must be a unique rut
@@ -0,0 +1,5 @@
1
+ es-CL:
2
+ errors:
3
+ messages:
4
+ run: debe ser un rut válido
5
+ uniq_run: debe ser un rut único
@@ -0,0 +1,5 @@
1
+ es:
2
+ errors:
3
+ messages:
4
+ run: debe ser un rut válido
5
+ uniq_run: debe ser un rut único
@@ -5,7 +5,8 @@ require 'run_cl/uniq_run_validator'
5
5
 
6
6
 
7
7
  module RunCl
8
-
8
+ class Engine < ::Rails::Engine
9
+ end
9
10
  module ActAsRun
10
11
  extend ActiveSupport::Concern
11
12
 
@@ -79,7 +79,7 @@ module Run
79
79
  def valid? run
80
80
  if run
81
81
  run_copy = run.clone
82
- run_copy = run_copy.match(/^(\d+)\.{1}\d{3}\.{1}\d{3}-{1}(\d|k|K)$|^(\d+)\d{6}\-{1}(\d|k|K)|^(\d+)\d{6}(\d|k|K)$/i).to_s
82
+ run_copy = run_copy.match(/^(\d{1,3})\.{1}\d{3}\.{1}\d{3}-{1}(\d|k|K)$|^\d{7,9}\-{1}(\d|k|K)|^\d{7,9}(\d|k|K)$/i).to_s
83
83
  return false unless run_copy
84
84
  run_copy = remove_format(run_copy)
85
85
  check_run run_copy.chop, run_copy.last
@@ -1,10 +1,5 @@
1
- # encoding: utf-8
2
-
3
1
  class RunValidator < ActiveModel::EachValidator
4
2
  def validate_each(record, attribute, value)
5
- record.errors[attribute] << (options[:message] || 'no es válido') unless Run.valid?(value)
3
+ record.errors[attribute] << (options[:message] || I18n.t(:run, scope: [:errors, :messages])) unless Run.valid?(value)
6
4
  end
7
-
8
- # TODO - locales
9
- # record.errors[attribute.to_sym] << I18n.t('run.invalid') unless Run.valid? record.send(attribute)
10
5
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  class UniqRunValidator < ActiveModel::EachValidator
4
2
  def validate_each(record, attribute, value)
5
3
  run = Run.remove_format value
@@ -15,9 +13,6 @@ class UniqRunValidator < ActiveModel::EachValidator
15
13
  matchers = matchers.where(options[:scope] => record.send(options[:scope]))
16
14
  end
17
15
 
18
- record.errors[attribute.to_sym] << (options[:message] || 'ya está en uso') if matchers.any?
16
+ record.errors[attribute.to_sym] << (options[:message] || I18n.t(:uniq_run, scope: [:errors, :messages])) if matchers.any?
19
17
  end
20
-
21
- # TODO - locales
22
- # record.errors[attribute.to_sym] << I18n.t('run.in_use') unless Run.valid? record.send(attribute)
23
- end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module RunCl
2
- VERSION = "1.6.2"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -0,0 +1,10 @@
1
+ // The validator variable is a JSON Object
2
+ // The selector variable is a jQuery Object
3
+ window.ClientSideValidations.validators.local['run'] = function(element, options) {
4
+ // Your validator code goes in here
5
+ if (!/^(\d{1,3})\.{1}\d{3}\.{1}\d{3}-{1}(\d|k|K)$|^\d{7,9}\-{1}(\d|k|K)|^\d{7,9}(\d|k|K)$/i.test(element.val())) {
6
+ // When the value fails to pass validation you need to return the error message.
7
+ // It can be derived from validator.message
8
+ return options.message;
9
+ }
10
+ }
@@ -0,0 +1,49 @@
1
+ $ ->
2
+ window.format_run = (value) ->
3
+ nPos = 0
4
+ sRut1 = value
5
+ aRut = sRut1.split('-')
6
+ sRut1 = aRut.join('')
7
+ aRut = sRut1.split('.')
8
+ sRut1 = aRut.join('')
9
+ sInvertido = ""
10
+
11
+ i = sRut1.length - 1
12
+
13
+ while i >= 0
14
+ sInvertido += sRut1.charAt(i)
15
+ if i is sRut1.length - 1
16
+ sInvertido += "-"
17
+ else if nPos is 3
18
+ sInvertido += "."
19
+ nPos = 0
20
+ nPos++
21
+ i--
22
+
23
+ j = sInvertido.length - 1
24
+ sRut = ""
25
+
26
+ while j >= 0
27
+ unless sInvertido.charAt(sInvertido.length - 1) is "."
28
+ sRut += sInvertido.charAt(j)
29
+ else sRut += sInvertido.charAt(j) unless j is sInvertido.length - 1
30
+ j--
31
+
32
+ sRut.toUpperCase()
33
+
34
+ $('.rut').on 'blur', (event) ->
35
+ event.target.value = format_run(event.target.value)
36
+
37
+ window.unformat_run = (value) ->
38
+ sRut = value
39
+ aRut = sRut.split('-')
40
+ sRut = aRut.join('')
41
+ aRut = sRut.split('.')
42
+ sRut = aRut.join('')
43
+
44
+ sRut.toUpperCase()
45
+
46
+ $('.rut').on 'focus', (event) ->
47
+ event.target.value = unformat_run(event.target.value)
48
+
49
+ $('.rut').trigger('blur')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_cl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mespina
@@ -22,12 +22,17 @@ files:
22
22
  - LICENSE.txt
23
23
  - README.md
24
24
  - Rakefile
25
+ - config/locales/run.en.yml
26
+ - config/locales/run.es-CL.yml
27
+ - config/locales/run.es.yml
25
28
  - lib/run_cl.rb
26
29
  - lib/run_cl/run.rb
27
30
  - lib/run_cl/run_validator.rb
28
31
  - lib/run_cl/uniq_run_validator.rb
29
32
  - lib/run_cl/version.rb
30
33
  - run_cl.gemspec
34
+ - vendor/assets/javascripts/clientsidevalidation.run.js
35
+ - vendor/assets/javascripts/run-formatter.js.coffee
31
36
  homepage: https://bitbucket.org/mespina/run
32
37
  licenses: []
33
38
  metadata: {}