client_side_validations-formtastic 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,136 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+ require 'ruby-debug'
4
+
5
+ def rails_validations_path
6
+ File.expand_path('../', $:.grep(/client_side_validations-\d/).first)
7
+ end
8
+
9
+ class AssetPath
10
+ def initialize(app, options={})
11
+ @app = app
12
+ @urls = options[:urls] || ["/favicon.ico"]
13
+ @index = options[:index]
14
+ root = options[:root] || Dir.pwd
15
+ cache_control = options[:cache_control]
16
+ @file_server = Rack::File.new(root, cache_control)
17
+ end
18
+
19
+ def overwrite_file_path(path)
20
+ @urls.kind_of?(Hash) && @urls.key?(path) || @index && path == '/'
21
+ end
22
+
23
+ def route_file(path)
24
+ @urls.kind_of?(Array) && @urls.any? { |url| path.index(url) == 0 }
25
+ end
26
+
27
+ def can_serve(path)
28
+ route_file(path) || overwrite_file_path(path)
29
+ end
30
+
31
+ def call(env)
32
+ path = env["PATH_INFO"]
33
+
34
+ if can_serve(path)
35
+ env["PATH_INFO"] = (path == '/' ? @index : @urls[path]) if overwrite_file_path(path)
36
+ response = @file_server.call(env)
37
+ if response.first == 404
38
+ @app.call(env)
39
+ else
40
+ response
41
+ end
42
+ else
43
+ @app.call(env)
44
+ end
45
+ end
46
+ end
47
+
48
+ use AssetPath, :urls => ['/vendor/assets/javascripts/'], :root => rails_validations_path
49
+ use AssetPath, :urls => ['/vendor/assets/javascripts/'], :root => File.expand_path('../..', settings.root)
50
+
51
+ JQUERY_VERSIONS = %w[ 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.7 1.7.1 ].freeze
52
+
53
+ helpers do
54
+ def jquery_link version
55
+ if params[:version] == version
56
+ "[#{version}]"
57
+ else
58
+ "<a href='/?version=#{version}'>#{version}</a>"
59
+ end
60
+ end
61
+
62
+ def jquery_src
63
+ if params[:version] == 'edge'
64
+ '/vendor/jquery.js'
65
+ else
66
+ "http://code.jquery.com/jquery-#{params[:version]}.js"
67
+ end
68
+ end
69
+
70
+ def test_base
71
+ names = ['/vendor/qunit.js', 'settings']
72
+ names.map { |name| script_tag name }.join("\n")
73
+ end
74
+
75
+ def test *types
76
+ types.map do |type|
77
+ Dir.glob(File.expand_path("public/test/#{type}", settings.root) + '/*.js').map { |file| File.basename(file) }.map do |file|
78
+ script_tag "/test/#{type}/#{file}"
79
+ end.join("\n")
80
+ end.join("\n")
81
+ end
82
+
83
+ def script_tag src
84
+ src = "/test/#{src}.js" unless src.index('/')
85
+ %(<script src='#{src}' type='text/javascript'></script>)
86
+ end
87
+
88
+ def jquery_versions
89
+ JQUERY_VERSIONS
90
+ end
91
+ end
92
+
93
+ get '/' do
94
+ params[:version] ||= '1.7.1'
95
+ erb :index
96
+ end
97
+
98
+ get '/validators/uniqueness' do
99
+ content_type 'application/json'
100
+
101
+ if user = params[:user2]
102
+ status 500
103
+ 'error'
104
+ elsif user = params['active_record_test_module/user2']
105
+ status 200
106
+ 'false'
107
+ elsif scope = params[:scope]
108
+ if scope[:name] == 'test name' || scope[:name] == 'taken name'
109
+ status 200
110
+ 'false'
111
+ else
112
+ status 404
113
+ 'true'
114
+ end
115
+ elsif params[:case_sensitive] == 'false' && (params[:user][:email] || params[:users][:email]) == 'taken@test.com'
116
+ status 200
117
+ 'false'
118
+ else
119
+ status 404
120
+ 'true'
121
+ end
122
+
123
+ end
124
+
125
+ post '/users' do
126
+ data = { :params => params }.update(request.env)
127
+ payload = data.to_json.gsub('<', '&lt;').gsub('>', '&gt;')
128
+ <<-HTML
129
+ <script>
130
+ if (window.top && window.top !== window)
131
+ window.top.jQuery.event.trigger('iframe:loaded', #{payload})
132
+ </script>
133
+ <p id="response">Form submitted</p>
134
+ HTML
135
+ end
136
+
@@ -0,0 +1,22 @@
1
+ <% @title = "client_side_validations-formtastic test" %>
2
+
3
+ <%= test_base %>
4
+ <%= test :form_builders %>
5
+
6
+ <h1 id="qunit-header"><%= @title %></h1>
7
+
8
+ <div id="jquery-version">
9
+ jQuery version:
10
+
11
+ <% jquery_versions.each do |v| %>
12
+ <%= ' • ' if v != jquery_versions.first %>
13
+ <%= jquery_link v %>
14
+ <% end %>
15
+ <%= (' • ' + jquery_link('edge')) if File.exist?(settings.root + '/public/vendor/jquery.js') %>
16
+ </div>
17
+ <h2 id="qunit-banner"></h2>
18
+ <div id="qunit-testrunner-toolbar"></div>
19
+ <h2 id="qunit-userAgent"></h2>
20
+ <ol id="qunit-tests"></ol>
21
+
22
+ <div id="qunit-fixture"></div>
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html id="html">
3
+ <head>
4
+ <title><%= @title %></title>
5
+ <link href="/vendor/qunit.css" media="screen" rel="stylesheet" type="text/css" media="screen, projection" />
6
+ <style>
7
+ #jquery-version {
8
+ color: #8699A4; text-align: right; font-family: sans-serif; line-height: 1;
9
+ margin-top: -1.8em; padding: 0 2em .8em 0;
10
+ }
11
+ #jquery-version a { color: white; text-decoration: underline; }
12
+ </style>
13
+
14
+ <%= script_tag jquery_src %>
15
+ <%= script_tag '/vendor/assets/javascripts/rails.validations.js' %>
16
+ <%= script_tag '/vendor/assets/javascripts/rails.validations.formtastic.js' %>
17
+ </head>
18
+
19
+ <body id="body">
20
+ <%= yield %>
21
+ </body>
22
+ </html>
@@ -0,0 +1,4 @@
1
+ # Sanity check to make sure the entire library loads OK
2
+
3
+ require 'base_helper'
4
+ require 'client_side_validations'
@@ -0,0 +1,19 @@
1
+ ClientSideValidations.formBuilders['Formtastic::FormBuilder'] = {
2
+ add: function(element, settings, message) {
3
+ if (element.data('valid') !== false) {
4
+ var wrapper = element.closest('li');
5
+ wrapper.addClass('error');
6
+ var errorElement = $('<p class="' + settings.inline_error_class + '">' + message + '</p>');
7
+ wrapper.append(errorElement);
8
+ } else {
9
+ element.parent().find('p.' + settings.inline_error_class).text(message);
10
+ }
11
+ },
12
+ remove: function(element, settings) {
13
+ var wrapper = element.closest('li.error');
14
+ wrapper.removeClass('error');
15
+ var errorElement = wrapper.find('p.' + settings.inline_error_class);
16
+ errorElement.remove();
17
+ }
18
+ }
19
+
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: client_side_validations-formtastic
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.beta.1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Brian Cardarella
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: client_side_validations
16
+ requirement: &70247173167380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0.beta.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70247173167380
25
+ - !ruby/object:Gem::Dependency
26
+ name: formtastic
27
+ requirement: &70247173166240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70247173166240
36
+ - !ruby/object:Gem::Dependency
37
+ name: actionpack
38
+ requirement: &70247173164940 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 3.2.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70247173164940
47
+ - !ruby/object:Gem::Dependency
48
+ name: sinatra
49
+ requirement: &70247173164160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70247173164160
58
+ - !ruby/object:Gem::Dependency
59
+ name: shotgun
60
+ requirement: &70247173163340 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70247173163340
69
+ - !ruby/object:Gem::Dependency
70
+ name: thin
71
+ requirement: &70247173162480 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70247173162480
80
+ - !ruby/object:Gem::Dependency
81
+ name: json
82
+ requirement: &70247173155440 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70247173155440
91
+ description: Formtastic Plugin for ClientSideValidaitons
92
+ email:
93
+ - bcardarella@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - client_side_validations-formtastic.gemspec
99
+ - lib/client_side_validations/formtastic.rb
100
+ - lib/client_side_validations/formtastic/form_builder.rb
101
+ - lib/client_side_validations/formtastic/helpers.rb
102
+ - lib/client_side_validations/formtastic/helpers/input_helper.rb
103
+ - lib/client_side_validations/formtastic/version.rb
104
+ - vendor/assets/javascripts/rails.validations.formtastic.js
105
+ - test/action_view/models.rb
106
+ - test/action_view/models/post.rb
107
+ - test/action_view/test_helper.rb
108
+ - test/base_helper.rb
109
+ - test/formtastic/cases/helper.rb
110
+ - test/formtastic/cases/test_form_builder.rb
111
+ - test/formtastic/cases/test_form_helpers.rb
112
+ - test/javascript/config.ru
113
+ - test/javascript/public/test/form_builders/validateFormtastic.js
114
+ - test/javascript/public/test/settings.js
115
+ - test/javascript/public/vendor/jquery.metadata.js
116
+ - test/javascript/public/vendor/qunit.css
117
+ - test/javascript/public/vendor/qunit.js
118
+ - test/javascript/server.rb
119
+ - test/javascript/views/index.erb
120
+ - test/javascript/views/layout.erb
121
+ - test/test_loader.rb
122
+ homepage: https://github.com/dockyard/client_side_validations-formtastic
123
+ licenses: []
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>'
138
+ - !ruby/object:Gem::Version
139
+ version: 1.3.1
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 1.8.10
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Formtastic Plugin for ClientSideValidations
146
+ test_files:
147
+ - test/action_view/models.rb
148
+ - test/action_view/models/post.rb
149
+ - test/action_view/test_helper.rb
150
+ - test/base_helper.rb
151
+ - test/formtastic/cases/helper.rb
152
+ - test/formtastic/cases/test_form_builder.rb
153
+ - test/formtastic/cases/test_form_helpers.rb
154
+ - test/javascript/config.ru
155
+ - test/javascript/public/test/form_builders/validateFormtastic.js
156
+ - test/javascript/public/test/settings.js
157
+ - test/javascript/public/vendor/jquery.metadata.js
158
+ - test/javascript/public/vendor/qunit.css
159
+ - test/javascript/public/vendor/qunit.js
160
+ - test/javascript/server.rb
161
+ - test/javascript/views/index.erb
162
+ - test/javascript/views/layout.erb
163
+ - test/test_loader.rb