bootstrap_validator_rails 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17bf5fba7766d8d384757dcf4508412bb2aaede4
4
- data.tar.gz: 3f8a4feddc93d5b330f2fd472e6362d44d1ffe80
3
+ metadata.gz: d5351ac2346898b17cf3897340b29c99bb05a11f
4
+ data.tar.gz: f9e351fd754463402e123fce7c491edcd36cff58
5
5
  SHA512:
6
- metadata.gz: 0cc4f39b0b66d2b6249fc552ede911a04b2e621e172d766e48a7e0aab5fae1ef2cae56214f5977a6e91718b5637c125cfea8f8cee229d305a8626b34793da427
7
- data.tar.gz: ed31e239fac037c907ec6cc7451c3bf49f6bc48737f74e56c27563f6ea322b057bdcf1add9f2c5bca85fee28ae3f56a85e5b8355307489943d5261891e243efa
6
+ metadata.gz: 7ebfd07c88ce626e04fa56bac64567ef3a888ea50bfddb79d0c408a0d1b2a1010318fbbb2fdee26f7b8f05d0cbf8992dcce627ea7bc1b430cd1e0716288e6dc2
7
+ data.tar.gz: d1ac7e64f46f0e80998791dbcdbaaa51a9df3ea0a05c5f680863aac0e707ed6386365d44841a53de0d155a7c6df5ed78422e19cd5ef40f270974df1e0113bafc
@@ -0,0 +1,9 @@
1
+ /***
2
+ * BootstrapValidatorRails
3
+ *
4
+ * @author Jack A. Huang
5
+ * @url http://github.com/huynhquancam/bootstrap_validator_rails/
6
+ */
7
+ var bv_form = function(form_selector, options) {
8
+ $(form_selector).bootstrapValidator(options);
9
+ };
@@ -4,5 +4,29 @@ module BootstrapValidatorRails
4
4
  options.reverse_merge!({builder: BootstrapValidatorRails::FormBuilder})
5
5
  bootstrap_form_for(object, options, &block)
6
6
  end
7
+
8
+ def bv_options_for(object)
9
+ validators = object.class.validators
10
+ bv_options = {
11
+ fields: {}
12
+ }
13
+ validators.each do |validator|
14
+ methods = validator.attributes
15
+ methods.each do |method|
16
+ @generator = BootstrapValidatorRails::Validators::Generator.new(object, validator, method)
17
+ json = @generator.generate_json
18
+ bv_options[:fields].deep_merge! json
19
+ end
20
+ end
21
+ bv_options.to_json.html_safe
22
+ end
23
+
24
+ def bv_javascript_for(object)
25
+ javascript_tag("
26
+ $(document).ready(function() {
27
+ bv_form('.bv_form', #{bv_options_for(object)})
28
+ });
29
+ ")
30
+ end
7
31
  end
8
32
  end
@@ -29,6 +29,29 @@ module BootstrapValidatorRails
29
29
 
30
30
  data
31
31
  end
32
+
33
+ def generate_object
34
+ data = {}
35
+ return data if unsupported?
36
+
37
+ options = validator_options
38
+
39
+ regex = options[:with].to_javascript
40
+ regex.sub!('/^', '^')
41
+ regex.sub!('$/', '$')
42
+
43
+ data["regexp"] = {}
44
+
45
+ if options[:with]
46
+ data["regexp"]["regexp"] = regex
47
+ end
48
+
49
+ if options[:message]
50
+ data["regexp"]["message"] = options[:message]
51
+ end
52
+
53
+ {method_key => {validators: data}}
54
+ end
32
55
  end
33
56
  end
34
57
  end
@@ -4,7 +4,6 @@ module BootstrapValidatorRails
4
4
  def initialize(record, validator, method)
5
5
  @record, @validator, @method = record, validator, method
6
6
  @kind = validator.kind
7
- p @kind
8
7
  end
9
8
 
10
9
  def generate_data(options = {})
@@ -13,6 +12,13 @@ module BootstrapValidatorRails
13
12
  bootstrap_validator = klass.new(@record, @method, @validator)
14
13
  bootstrap_validator.generate_data
15
14
  end
15
+
16
+ def generate_json
17
+ return {} unless VALIDATOR_SUPPORTED.include?(@kind)
18
+ klass = "BootstrapValidatorRails::Validators::#{@kind.to_s.capitalize}".constantize
19
+ bootstrap_validator = klass.new(@record, @method, @validator)
20
+ bootstrap_validator.generate_object
21
+ end
16
22
  end
17
23
  end
18
24
  end
@@ -25,6 +25,30 @@ module BootstrapValidatorRails
25
25
 
26
26
  data
27
27
  end
28
+
29
+ def generate_object
30
+ options = @validator.options
31
+
32
+ data = {}
33
+
34
+ data["stringLength"] = {}
35
+
36
+ if options[:minimum]
37
+ data["stringLength"]["min"] = options[:minimum]
38
+ end
39
+
40
+ if options[:maximum]
41
+ data["stringLength"]["max"] = options[:maximum]
42
+ end
43
+
44
+ if options[:is]
45
+ data["stringLength"]["min"] = options[:is]
46
+ data["stringLength"]["max"] = options[:is]
47
+ data["stringLength"]['message'] = @record.errors.generate_message(@method)
48
+ end
49
+
50
+ {method_key => {validators: data}}
51
+ end
28
52
  end
29
53
  end
30
54
  end
@@ -17,6 +17,57 @@ module BootstrapValidatorRails
17
17
  @record.errors.generate_message(@method, :presence, {default: 'should be a number'})
18
18
  end
19
19
 
20
+ def generate_object
21
+ options = @validator.options
22
+
23
+ data = {}
24
+
25
+ if options[:only_integer].present?
26
+ data["integer"] = {}
27
+ data["integer"][:message] = 'should be a number'
28
+ end
29
+
30
+ if options[:greater_than].present?
31
+ data["greaterThan"] = {}
32
+ data["greaterThan"]["inclusive"] = false
33
+ data["greaterThan"]["value"] = options[:greater_than]
34
+ end
35
+
36
+ if options[:greater_than_or_equal_to].present?
37
+ data["greaterThan"] = {}
38
+ data["greaterThan"]["inclusive"] = true
39
+ data["greaterThan"]["value"] = options[:greater_than_or_equal_to]
40
+ end
41
+
42
+ if options[:less_than].present?
43
+ data["lessThan"] = {}
44
+ data["lessThan"]["inclusive"] = false
45
+ data["lessThan"]["value"] = options[:less_than]
46
+ end
47
+
48
+ if options[:less_than_or_equal_to].present?
49
+ data["lessThan"] = {}
50
+ data["lessThan"]["inclusive"] = true
51
+ data["lessThan"]["value"] = options[:less_than_or_equal_to]
52
+ end
53
+
54
+ if options[:odd].present?
55
+ data["step"] = {}
56
+ data["step"]["message"] = 'should be odd'
57
+ data["step"]["base"] = 1
58
+ data["step"]["step"] = 2
59
+ end
60
+
61
+ if options[:even].present?
62
+ data["step"] = {}
63
+ data["step"]["message"] = 'should be odd'
64
+ data["step"]["base"] = 0
65
+ data["step"]["step"] = 2
66
+ end
67
+
68
+ {method_key => {validators: data}}
69
+ end
70
+
20
71
  def generate_options
21
72
  options = @validator.options
22
73
 
@@ -13,6 +13,13 @@ module BootstrapValidatorRails
13
13
  def generate_message
14
14
  @record.errors.generate_message(@method, :blank, default: "can't be blank")
15
15
  end
16
+
17
+ def generate_object(options = {})
18
+ data = {}
19
+ data["notEmpty"] = {}
20
+ data["notEmpty"]["message"] = generate_message
21
+ {method_key => {validators: data}}
22
+ end
16
23
  end
17
24
  end
18
25
  end
@@ -10,6 +10,10 @@ module BootstrapValidatorRails
10
10
  options || {}
11
11
  end
12
12
 
13
+ def generate_object(options = {})
14
+ options
15
+ end
16
+
13
17
  def unsupported?
14
18
  options = validator_options
15
19
  unsupported_options.any? { |opt| options.has_key? opt }
@@ -19,6 +23,10 @@ module BootstrapValidatorRails
19
23
  def unsupported_options
20
24
  BootstrapValidatorRails::CONFIGURATION[:unsupported_options]
21
25
  end
26
+
27
+ def method_key
28
+ "#{@record.class.to_s.downcase.to_sym}[#{@method}]"
29
+ end
22
30
  end
23
31
  end
24
32
  end
@@ -1,3 +1,3 @@
1
1
  module BootstrapValidatorRails
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -2571,3 +2571,221 @@ BootstrapValidatorRailsTest: test_test_will_be_included_later
2571
2571
  ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2572
2572
   (0.1ms) begin transaction
2573
2573
   (0.1ms) rollback transaction
2574
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
2575
+  (0.2ms) begin transaction
2576
+  (0.1ms) rollback transaction
2577
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2578
+  (0.1ms) begin transaction
2579
+  (0.1ms) rollback transaction
2580
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2581
+  (0.1ms) begin transaction
2582
+  (0.1ms) rollback transaction
2583
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2584
+  (0.1ms) begin transaction
2585
+  (0.1ms) rollback transaction
2586
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2587
+  (0.1ms) begin transaction
2588
+  (0.1ms) rollback transaction
2589
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
2590
+  (0.1ms) begin transaction
2591
+  (0.1ms) rollback transaction
2592
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2593
+  (0.1ms) begin transaction
2594
+  (0.1ms) rollback transaction
2595
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2596
+  (0.1ms) begin transaction
2597
+  (0.1ms) rollback transaction
2598
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2599
+  (0.1ms) begin transaction
2600
+  (0.1ms) rollback transaction
2601
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
2602
+  (0.1ms) begin transaction
2603
+  (0.1ms) rollback transaction
2604
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2605
+  (0.1ms) begin transaction
2606
+  (0.1ms) rollback transaction
2607
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2608
+  (0.1ms) begin transaction
2609
+  (0.1ms) rollback transaction
2610
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2611
+  (0.1ms) begin transaction
2612
+  (0.1ms) rollback transaction
2613
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2614
+  (0.1ms) begin transaction
2615
+  (0.1ms) rollback transaction
2616
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2617
+  (0.1ms) begin transaction
2618
+  (0.1ms) rollback transaction
2619
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2620
+  (0.1ms) begin transaction
2621
+  (0.1ms) rollback transaction
2622
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2623
+  (0.1ms) begin transaction
2624
+  (0.1ms) rollback transaction
2625
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2626
+  (0.1ms) begin transaction
2627
+  (0.1ms) rollback transaction
2628
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2629
+  (0.1ms) begin transaction
2630
+  (0.1ms) rollback transaction
2631
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2632
+  (0.1ms) begin transaction
2633
+  (0.1ms) rollback transaction
2634
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2635
+  (0.1ms) begin transaction
2636
+  (0.1ms) rollback transaction
2637
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2638
+  (0.1ms) begin transaction
2639
+  (0.1ms) rollback transaction
2640
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2641
+  (0.1ms) begin transaction
2642
+  (0.1ms) rollback transaction
2643
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2644
+  (0.1ms) begin transaction
2645
+  (0.1ms) rollback transaction
2646
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2647
+  (0.1ms) begin transaction
2648
+  (0.1ms) rollback transaction
2649
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2650
+  (0.1ms) begin transaction
2651
+  (0.1ms) rollback transaction
2652
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2653
+  (0.1ms) begin transaction
2654
+  (0.1ms) rollback transaction
2655
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2656
+  (0.1ms) begin transaction
2657
+  (0.1ms) rollback transaction
2658
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2659
+  (0.1ms) begin transaction
2660
+  (0.1ms) rollback transaction
2661
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2662
+  (0.1ms) begin transaction
2663
+  (0.1ms) rollback transaction
2664
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2665
+  (0.1ms) begin transaction
2666
+  (0.1ms) rollback transaction
2667
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2668
+  (0.1ms) begin transaction
2669
+  (0.1ms) rollback transaction
2670
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2671
+  (0.1ms) begin transaction
2672
+  (0.1ms) rollback transaction
2673
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2674
+  (0.1ms) begin transaction
2675
+  (0.1ms) rollback transaction
2676
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2677
+  (0.1ms) begin transaction
2678
+  (0.1ms) rollback transaction
2679
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
2680
+  (0.1ms) begin transaction
2681
+  (0.1ms) rollback transaction
2682
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2683
+  (0.1ms) begin transaction
2684
+  (0.1ms) rollback transaction
2685
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2686
+  (0.1ms) begin transaction
2687
+  (0.1ms) rollback transaction
2688
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2689
+  (0.1ms) begin transaction
2690
+  (0.1ms) rollback transaction
2691
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2692
+  (0.1ms) begin transaction
2693
+  (0.1ms) rollback transaction
2694
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
2695
+  (0.2ms) begin transaction
2696
+  (0.1ms) rollback transaction
2697
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
2698
+  (0.1ms) begin transaction
2699
+  (0.1ms) rollback transaction
2700
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2701
+  (0.3ms) begin transaction
2702
+  (0.1ms) rollback transaction
2703
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2704
+  (0.1ms) begin transaction
2705
+  (0.1ms) rollback transaction
2706
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2707
+  (0.1ms) begin transaction
2708
+  (0.1ms) rollback transaction
2709
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
2710
+  (0.1ms) begin transaction
2711
+ -------------------------------------------------------------
2712
+ BootstrapValidatorRailsTest: test_test_will_be_included_later
2713
+ -------------------------------------------------------------
2714
+  (0.1ms) rollback transaction
2715
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2716
+  (0.1ms) begin transaction
2717
+  (0.1ms) rollback transaction
2718
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2719
+  (0.1ms) begin transaction
2720
+  (0.1ms) rollback transaction
2721
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2722
+  (0.1ms) begin transaction
2723
+  (0.1ms) rollback transaction
2724
+ ActiveRecord::SchemaMigration Load (0.6ms) SELECT "schema_migrations".* FROM "schema_migrations"
2725
+  (0.1ms) begin transaction
2726
+  (0.1ms) rollback transaction
2727
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
2728
+  (0.1ms) begin transaction
2729
+  (0.1ms) rollback transaction
2730
+  (0.1ms) begin transaction
2731
+  (0.1ms) rollback transaction
2732
+  (0.1ms) begin transaction
2733
+  (0.1ms) rollback transaction
2734
+  (0.1ms) begin transaction
2735
+  (0.1ms) rollback transaction
2736
+  (0.1ms) begin transaction
2737
+  (0.0ms) rollback transaction
2738
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
2739
+  (0.1ms) begin transaction
2740
+  (0.1ms) rollback transaction
2741
+  (0.1ms) begin transaction
2742
+  (0.1ms) rollback transaction
2743
+  (0.1ms) begin transaction
2744
+  (0.1ms) rollback transaction
2745
+  (0.1ms) begin transaction
2746
+  (0.0ms) rollback transaction
2747
+  (0.0ms) begin transaction
2748
+  (0.0ms) rollback transaction
2749
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2750
+  (0.1ms) begin transaction
2751
+  (0.1ms) rollback transaction
2752
+  (0.1ms) begin transaction
2753
+  (0.0ms) rollback transaction
2754
+  (0.0ms) begin transaction
2755
+  (0.0ms) rollback transaction
2756
+  (0.0ms) begin transaction
2757
+  (0.0ms) rollback transaction
2758
+  (0.0ms) begin transaction
2759
+  (0.0ms) rollback transaction
2760
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2761
+  (0.1ms) begin transaction
2762
+ -------------------------------------------------------------
2763
+ BootstrapValidatorRailsTest: test_test_will_be_included_later
2764
+ -------------------------------------------------------------
2765
+  (0.1ms) rollback transaction
2766
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
2767
+  (0.1ms) begin transaction
2768
+ -------------------------------------------------------------
2769
+ BootstrapValidatorRailsTest: test_test_will_be_included_later
2770
+ -------------------------------------------------------------
2771
+  (0.1ms) rollback transaction
2772
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2773
+  (0.2ms) begin transaction
2774
+  (0.1ms) rollback transaction
2775
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2776
+  (0.1ms) begin transaction
2777
+  (0.1ms) rollback transaction
2778
+  (0.0ms) begin transaction
2779
+  (0.1ms) rollback transaction
2780
+  (0.0ms) begin transaction
2781
+  (0.1ms) rollback transaction
2782
+  (0.0ms) begin transaction
2783
+  (0.0ms) rollback transaction
2784
+  (0.0ms) begin transaction
2785
+  (0.0ms) rollback transaction
2786
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2787
+  (0.1ms) begin transaction
2788
+ -------------------------------------------------------------
2789
+ BootstrapValidatorRailsTest: test_test_will_be_included_later
2790
+ -------------------------------------------------------------
2791
+  (0.1ms) rollback transaction
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_validator_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - huynhquancam
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - MIT-LICENSE
78
78
  - Rakefile
79
+ - app/assets/javascripts/bootstrapValidatorRails.js
79
80
  - lib/bootstrap_validator_rails.rb
80
81
  - lib/bootstrap_validator_rails/configuration.rb
81
82
  - lib/bootstrap_validator_rails/engine.rb