angular_form_validation 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98cfb756a2202bbceeeeae0fe06dd77c8c8aac77
4
+ data.tar.gz: e4446124184c01ed9f8d345d4dab04b903db533d
5
+ SHA512:
6
+ metadata.gz: a281d56510050a3440d4eac16b30f1099396e94189f7a000e42ab032c15f9fe847d3390c6380a409ef375aab084c29600456613499d4a51bee5740c752b2b1bb
7
+ data.tar.gz: efe6cc74da0e42bf2b141c3eb70c42b91103e9ac134006b3cc9ab7f03ea9877f8d35fa1eca90f674f003030e331d9087737b2452057cb26e65f817cb80072b27
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in angular_form_validation.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Olivier Robert
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.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Angular Form Validation Gem
2
+
3
+ Ruby gem to easily implement angular validation via form_form and form_tag helpers
4
+
5
+ ## Installation
6
+
7
+ gem 'angular_form_validation'
8
+
9
+ ## What it does
10
+
11
+ - Implements Angular attributes on form inputs (ng-model, ng-init) and form buttons (ng-disabled) automatically when using the helper form_for
12
+ - Provides helpers methods to perform the same when using the helper form_tag
13
+
14
+ As a result, you can easily have JavaScript validation on all forms with a minimum effort, nice real-time visual feedback on form inputs and take advantage of two-way bindings.
15
+
16
+ ## Usage for form_tag
17
+
18
+ When using the helper form_tag, it is required to use the following helpers:
19
+
20
+ ### ng_model_opts(object, attribute)
21
+
22
+ This helper can be used on form inputs to add the ng-model and ng-init attributes:
23
+
24
+ Example:
25
+
26
+ <%= text_field_tag :name, params[:name], { required: true }.merge(ng_model_opts(@user, :name)
27
+
28
+ ### ng_submit_opts(object)
29
+
30
+ This helper can be used on form buttons to add the ng-disabled attribute:
31
+
32
+ Example:
33
+
34
+ <%= button_tag t("common.form.actions.save_btn"), ng_submit_opts(@product_config) %
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'angular_form_validation/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "angular_form_validation"
8
+ spec.version = AngularFormValidation::VERSION
9
+ spec.authors = ["Olivier Robert", "Nimbl3"]
10
+ spec.email = ["olivier@nimbl3.com"]
11
+ spec.summary = "Implement easily angular validation via form_form and form_tag helpers"
12
+ spec.description = ""
13
+ spec.homepage = "http://nimbl3.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,9 @@
1
+ require "angular_form_validation/version"
2
+ require "angular_form_validation/form/builder"
3
+ require "angular_form_validation/helpers/form_tag"
4
+ require "angular_form_validation/helpers"
5
+ require "angular_form_validation/railtie"
6
+
7
+ module AngularFormValidation
8
+
9
+ end
@@ -0,0 +1,49 @@
1
+ module AngularFormValidation
2
+
3
+ class FormBuilder < ActionView::Helpers::FormBuilder
4
+
5
+ FIELD_HELPERS = %w{color_field date_field datetime_field datetime_local_field
6
+ email_field month_field number_field password_field phone_field
7
+ range_field search_field telephone_field text_area text_field time_field
8
+ url_field week_field}
9
+
10
+ FIELD_HELPERS.each do |method_name|
11
+ define_method(method_name) do |method, options = {}|
12
+ options.merge!({"ng-model" => "#{@object_name}.#{method.to_s}", "ng-init" => "#{@object_name}.#{method.to_s}='#{@object[method.to_s]}'"})
13
+ super(method, options)
14
+ end
15
+ end
16
+
17
+ def submit(value=nil, options={})
18
+ options.merge!({"ng-disabled" =>"#{@options[:html][:method].to_s}#{@template.controller_name.classify}.$invalid"})
19
+ super(value, options)
20
+ end
21
+
22
+ def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
23
+ html_options.merge!({"ng-model" => "#{@object_name}.#{method.to_s}", "ng-init" => "#{@object_name}.#{method.to_s}='#{@object[method.to_s]}'"})
24
+ super(method, collection, value_method, text_method, options, html_options)
25
+ end
26
+
27
+ def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
28
+ html_options.merge!({"ng-model" => "#{@object_name}.#{method.to_s}", "ng-init" => "#{@object_name}.#{method.to_s}='#{@object[method.to_s]}'"})
29
+ super(method, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
30
+ end
31
+
32
+ def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
33
+ html_options.merge!({"ng-model" => "#{@object_name}.#{method.to_s}", "ng-init" => "#{@object_name}.#{method.to_s}='#{@object[method.to_s]}'"})
34
+ super(method, priority_zones = nil, options, html_options)
35
+ end
36
+
37
+ def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
38
+ html_options.merge!({"ng-model" => "#{@object_name}.#{method.to_s}", "ng-init" => "#{@object_name}.#{method.to_s}='#{@object[method.to_s]}'"})
39
+ super(method, collection, value_method, text_method, options = {}, html_options, &block)
40
+ end
41
+
42
+ def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
43
+ html_options.merge!({"ng-model" => "#{@object_name}.#{method.to_s}", "ng-init" => "#{@object_name}.#{method.to_s}='#{@object[method.to_s]}'"})
44
+ super(method, collection, value_method, text_method, options = {}, html_options, &block)
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,5 @@
1
+ module AngularFormValidation
2
+ module Helpers
3
+ include FormTag
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ module AngularFormValidation
2
+
3
+ module Helpers
4
+
5
+ module FormTag
6
+
7
+ # Add form name attribute (id is added by default)
8
+ def form_tag(url_for_options = {}, options = {}, &block)
9
+ options.merge!({"name" => "#{( options[:method] || controller.action_name )}#{controller_name.classify}"})
10
+ super(url_for_options, options, &block)
11
+ end
12
+
13
+ def ng_model_opts(object, attribute)
14
+ object_name = object.class.model_name.singular
15
+ init_value = params[object_name.to_sym][attribute.to_s] if params[object_name.to_sym].present?
16
+ opts = {}
17
+ opts["ng-model"] = "#{object_name}.#{attribute.to_s}"
18
+ opts["ng-init"] = "#{object_name}.#{attribute.to_s}='#{init_value}'"
19
+ opts
20
+ end
21
+
22
+ def ng_submit_opts(object)
23
+ opts = {"ng-disabled" =>"#{controller.action_name}#{object.class.model_name}.$invalid"}
24
+ opts
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails'
2
+
3
+ module AngularFormValidation
4
+ class Railtie < ::Rails::Railtie
5
+ initializer "angular_form_validation.setup_view_helpers" do
6
+ ActionView::Base.default_form_builder = ::AngularFormValidation::FormBuilder
7
+ ActiveSupport.on_load(:action_view) do
8
+ include ::AngularFormValidation::Helpers
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module AngularFormValidation
2
+ VERSION = "0.1.5"
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular_form_validation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Olivier Robert
8
+ - Nimbl3
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-10-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ description: ''
43
+ email:
44
+ - olivier@nimbl3.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - angular_form_validation.gemspec
55
+ - lib/angular_form_validation.rb
56
+ - lib/angular_form_validation/form/builder.rb
57
+ - lib/angular_form_validation/helpers.rb
58
+ - lib/angular_form_validation/helpers/form_tag.rb
59
+ - lib/angular_form_validation/railtie.rb
60
+ - lib/angular_form_validation/version.rb
61
+ homepage: http://nimbl3.com
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Implement easily angular validation via form_form and form_tag helpers
85
+ test_files: []