green_light 0.1.5 → 0.2.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: ced62afb282a65e3909d66a1ab3f29fbad68b349
4
+ data.tar.gz: 6f320cb4aa083544294cf977e07e238cb1cb248f
5
+ SHA512:
6
+ metadata.gz: c857bc8a9cdad32c9511c2d2e7e992875491d185c23dc554810999d5ed4d64b5b15a94e97cb58314e19a3fbd3752cd11f609752a6566972dd7bb4a6b8a0a7d3d
7
+ data.tar.gz: 5948e644784876607ae588aedc95a829b9ce283aaf945c94ac0c595909bfcafeb958dc30d92e1a0ea413c1e233e7c428afa3aae46d0a5283cc3c8fc76234281e
data/Gemfile CHANGED
@@ -1,18 +1,17 @@
1
1
  source 'http://rubygems.org'
2
- gem 'rails',"3.1.0.rc5"
2
+ gem 'rails',"4.1.4"
3
3
 
4
4
  # Gems used only for assets and not required
5
5
  # in production environments by default.
6
6
  group :assets do
7
- gem 'sass-rails', "~> 3.1.0.rc"
8
- gem 'coffee-rails', "~> 3.1.0.rc"
7
+ gem 'sass-rails', '4.0.3'
8
+ gem 'coffee-rails', '4.0.1'
9
9
  gem 'uglifier'
10
10
  end
11
11
 
12
12
  gem 'jquery-rails'
13
13
 
14
14
  group :test do
15
- gem "activerecord", :require => "active_record"
16
15
  gem 'rspec'
17
16
  gem 'supermodel'
18
17
  end
data/README.rdoc CHANGED
@@ -9,13 +9,8 @@ Add green_light to your Gemfile and run the <tt>bundle install</tt> command.
9
9
 
10
10
  gem 'green_light'
11
11
 
12
-
13
12
  == Usage
14
13
 
15
- Generate the required green_light configuration:-
16
-
17
- rails g green_light:install
18
-
19
14
  Include the JQuery validation plugin in your <tt>app/assets/javascripts/application.js</tt> file:-
20
15
 
21
16
  //= require jquery.validate
@@ -24,10 +19,6 @@ Since the validation rules are creating dynmically they need to be included in t
24
19
 
25
20
  <%= javascript_include_tag "green_light" %>
26
21
 
27
- Specify which models you want to have client-side validation in the <tt>config/green_light.yml</tt> file e.g.:-
28
-
29
- validate_models: ['ModelName1', 'ModelName2']
30
-
31
22
  Add the <tt>green_light</tt> class to the forms that you wish to have client side validation:-
32
23
 
33
24
  <%= form_for(@model, :html => { :class => 'green_light' }) do |f| %>
@@ -36,7 +27,7 @@ And finally, add some validations to your models!
36
27
 
37
28
 
38
29
  == Currently Supports these validations
39
-
30
+
40
31
  validates_presence_of
41
32
  validates_length_of
42
33
  validates_format_of
@@ -1,8 +1,9 @@
1
1
  class AssetsController < ApplicationController
2
+ skip_before_action :verify_authenticity_token
2
3
  respond_to :js
3
4
 
4
5
  def green_light
5
- @rules = GreenLight::Rules.generate(GREEN_LIGHT[:validate_models])
6
+ @rules = GreenLight::Rules.generate(GreenLight.validatable_models)
6
7
  respond_with(@rules, :layout => false)
7
8
  end
8
9
  end
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Build validation rules based on models specified in the green_light config
3
- */
3
+ */
4
4
  <% if @rules %>
5
5
  $().ready(function() {
6
6
  $(".green_light").validate(<%= @rules.html_safe %>);
@@ -9,7 +9,7 @@
9
9
 
10
10
  /**
11
11
  * Custom code for regex validation
12
- */
12
+ */
13
13
  $.validator.addMethod(
14
14
  "regex",
15
15
  function(value, element, regexp) {
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  Rails.application.routes.draw do
2
- match "/assets/green_light" => "assets#green_light"
3
- match "/javascripts/check_for_uniqueness" => "javascripts#check_for_uniqueness"
2
+ match "/javascripts/green_light" => "assets#green_light", via: [:get, :post]
3
+ match "/javascripts/check_for_uniqueness" => "javascripts#check_for_uniqueness", via: [:get, :post]
4
4
  end
data/green_light.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "green_light/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "green_light"
6
+ s.name = "green_light"
7
7
  s.version = GreenLight::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Phil McClure"]
@@ -1,4 +1,11 @@
1
1
  module GreenLight #:nodoc:
2
2
  class Engine < ::Rails::Engine #:nodoc:
3
+
4
+ config.to_prepare do
5
+ GreenLight.define_singleton_method :validatable_models do
6
+ ActiveRecord::Base.subclasses.map(&:to_s)
7
+ end
8
+ end
9
+
3
10
  end
4
11
  end
@@ -8,8 +8,8 @@ module GreenLight
8
8
 
9
9
  def self.generate(models)
10
10
  data, rules = {}, {}
11
- models.each do |model|
12
- model.constantize._validators.each do |field_name, validations|
11
+ models.each do |model|
12
+ model.constantize._validators.each do |field_name, validations|
13
13
  rules["#{model.to_s.underscore.downcase}[#{field_name}]"] = parse_each_validation(model, field_name, validations)
14
14
  data[:rules] = rules
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module GreenLight
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  describe GreenLight do
4
4
  before(:all) do
5
5
  end
6
-
6
+
7
7
  it "should return a valid json string when validating the format of a field" do
8
8
  rules = GreenLight::Rules.generate(['FormatOfModel'])
9
9
  rules.should == "{\"errorElement\":\"span\",\"rules\":{\"format_of_model[title]\":{\"regex\":\"(^[A-Za-z]$)\"}}}"
metadata CHANGED
@@ -1,35 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: green_light
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 5
9
- version: 0.1.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Phil McClure
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2011-09-12 00:00:00 +01:00
18
- default_executable:
11
+ date: 2014-08-18 00:00:00.000000000 Z
19
12
  dependencies: []
20
-
21
13
  description: Simple client side validation that keeps validation in the models
22
- email:
14
+ email:
23
15
  - pmcclure@rumblelabs.com
24
16
  executables: []
25
-
26
17
  extensions: []
27
-
28
18
  extra_rdoc_files: []
29
-
30
- files:
31
- - .DS_Store
32
- - .gitignore
19
+ files:
20
+ - ".DS_Store"
21
+ - ".gitignore"
33
22
  - Gemfile
34
23
  - README.rdoc
35
24
  - Rakefile
@@ -41,9 +30,6 @@ files:
41
30
  - green_light.gemspec
42
31
  - lib/.DS_Store
43
32
  - lib/generators/green_light/USAGE
44
- - lib/generators/green_light/install_generator.rb
45
- - lib/generators/green_light/templates/green_light.rb
46
- - lib/generators/green_light/templates/green_light.yml
47
33
  - lib/green_light.rb
48
34
  - lib/green_light/.DS_Store
49
35
  - lib/green_light/engine.rb
@@ -59,36 +45,30 @@ files:
59
45
  - vendor/.DS_Store
60
46
  - vendor/assets/.DS_Store
61
47
  - vendor/assets/javascripts/jquery.validate.js
62
- has_rdoc: true
63
48
  homepage: http://www.rumblelabs.com
64
49
  licenses: []
65
-
50
+ metadata: {}
66
51
  post_install_message:
67
52
  rdoc_options: []
68
-
69
- require_paths:
53
+ require_paths:
70
54
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
72
- requirements:
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
73
57
  - - ">="
74
- - !ruby/object:Gem::Version
75
- segments:
76
- - 0
77
- version: "0"
78
- required_rubygems_version: !ruby/object:Gem::Requirement
79
- requirements:
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
80
62
  - - ">="
81
- - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
- version: "0"
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
85
65
  requirements: []
86
-
87
66
  rubyforge_project: green_light
88
- rubygems_version: 1.3.6
67
+ rubygems_version: 2.2.2
89
68
  signing_key:
90
- specification_version: 3
69
+ specification_version: 4
91
70
  summary: Simple client side validation that keeps validation in the models
92
- test_files:
71
+ test_files:
93
72
  - spec/green_light_spec.rb
94
73
  - spec/spec_helper.rb
74
+ has_rdoc:
@@ -1,20 +0,0 @@
1
- require 'rails/generators'
2
-
3
- module GreenLight
4
- class InstallGenerator < Rails::Generators::Base
5
- desc 'Generates config file for green_light'
6
-
7
- def self.source_root
8
- @source_root ||= File.join(File.dirname(__FILE__), 'templates')
9
- end
10
-
11
- def generate_config
12
- copy_file "green_light.yml", "config/green_light.yml"
13
- end
14
-
15
- def generate_initializer
16
- copy_file "green_light.rb", "config/initializers/green_light.rb"
17
- end
18
- end
19
- end
20
-
@@ -1,2 +0,0 @@
1
- config = YAML.load_file(File.join(Rails.root, 'config', 'green_light.yml'))
2
- GREEN_LIGHT = HashWithIndifferentAccess.new(config)
@@ -1 +0,0 @@
1
- validate_models: []