judge 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +2 -1
  3. data/Gemfile +1 -10
  4. data/Rakefile +9 -44
  5. data/judge.gemspec +17 -164
  6. data/lib/generators/judge/templates/json2.js +46 -42
  7. data/lib/generators/judge/templates/judge.js +42 -41
  8. data/lib/generators/judge/templates/underscore.js +219 -97
  9. data/lib/judge.rb +6 -4
  10. data/lib/judge/form_builder.rb +75 -0
  11. data/lib/judge/{utils.rb → message_collection.rb} +45 -28
  12. data/lib/judge/validator.rb +21 -0
  13. data/lib/judge/validator_collection.rb +28 -0
  14. data/lib/judge/version.rb +3 -0
  15. data/spec/javascripts/JudgeSpec.js +25 -23
  16. data/test/expected_elements.rb +235 -0
  17. data/test/factories.rb +23 -0
  18. data/test/setup.rb +70 -0
  19. data/test/test_form_builder.rb +69 -0
  20. data/test/test_helper.rb +8 -20
  21. data/test/test_message_collection.rb +84 -0
  22. data/test/test_validator.rb +37 -0
  23. data/test/test_validator_collection.rb +19 -0
  24. metadata +46 -137
  25. data/.document +0 -5
  26. data/Gemfile.lock +0 -116
  27. data/VERSION +0 -1
  28. data/docs/docco.css +0 -196
  29. data/docs/judge.html +0 -280
  30. data/lib/judge/form.rb +0 -59
  31. data/test/dummy/Gemfile +0 -3
  32. data/test/dummy/Gemfile.lock +0 -75
  33. data/test/dummy/Rakefile +0 -7
  34. data/test/dummy/app/controllers/application_controller.rb +0 -3
  35. data/test/dummy/app/controllers/foos_controller.rb +0 -11
  36. data/test/dummy/app/helpers/application_helper.rb +0 -2
  37. data/test/dummy/app/models/city.rb +0 -5
  38. data/test/dummy/app/models/continent.rb +0 -4
  39. data/test/dummy/app/models/country.rb +0 -6
  40. data/test/dummy/app/models/fake.rb +0 -2
  41. data/test/dummy/app/models/foo.rb +0 -19
  42. data/test/dummy/app/views/foos/new.html.erb +0 -71
  43. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  44. data/test/dummy/config.ru +0 -4
  45. data/test/dummy/config/application.rb +0 -45
  46. data/test/dummy/config/boot.rb +0 -10
  47. data/test/dummy/config/database.yml +0 -22
  48. data/test/dummy/config/environment.rb +0 -5
  49. data/test/dummy/config/environments/development.rb +0 -26
  50. data/test/dummy/config/environments/production.rb +0 -49
  51. data/test/dummy/config/environments/test.rb +0 -35
  52. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  53. data/test/dummy/config/initializers/inflections.rb +0 -10
  54. data/test/dummy/config/initializers/mime_types.rb +0 -5
  55. data/test/dummy/config/initializers/secret_token.rb +0 -7
  56. data/test/dummy/config/initializers/session_store.rb +0 -8
  57. data/test/dummy/config/locales/en.yml +0 -12
  58. data/test/dummy/config/routes.rb +0 -3
  59. data/test/dummy/db/development.sqlite3 +0 -0
  60. data/test/dummy/db/migrate/20110624115516_create_foos.rb +0 -26
  61. data/test/dummy/db/migrate/20110724201117_create_fake_collections.rb +0 -14
  62. data/test/dummy/db/migrate/20110724201548_rename_fake_collection_to_fake.rb +0 -9
  63. data/test/dummy/db/migrate/20110725082530_create_continent_country_and_city_tables.rb +0 -24
  64. data/test/dummy/db/schema.rb +0 -55
  65. data/test/dummy/db/test.sqlite3 +0 -0
  66. data/test/dummy/log/server.log +0 -0
  67. data/test/dummy/public/404.html +0 -26
  68. data/test/dummy/public/422.html +0 -26
  69. data/test/dummy/public/500.html +0 -26
  70. data/test/dummy/public/favicon.ico +0 -0
  71. data/test/dummy/public/javascripts/application.js +0 -2
  72. data/test/dummy/public/javascripts/controls.js +0 -965
  73. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  74. data/test/dummy/public/javascripts/effects.js +0 -1123
  75. data/test/dummy/public/javascripts/prototype.js +0 -6001
  76. data/test/dummy/public/javascripts/rails.js +0 -175
  77. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  78. data/test/dummy/script/rails +0 -6
  79. data/test/judge_test.rb +0 -186
data/lib/judge/form.rb DELETED
@@ -1,59 +0,0 @@
1
- module Judge
2
-
3
- module FormBuilder
4
-
5
- include ActionView::Helpers::TagHelper
6
-
7
- %w{text_field text_area password_field}.each do |type|
8
- helper = <<-END
9
- def validated_#{type}(method, options = {})
10
- options = { "data-validate" => Judge::Utils.validators_to_json(self.object, method) }.merge(options)
11
- @template.#{type}(self.object_name, method, options)
12
- end
13
- END
14
- class_eval helper, __FILE__, __LINE__
15
- end
16
-
17
- def validated_radio_button(method, tag_value, options = {})
18
- options = { "data-validate" => Judge::Utils.validators_to_json(self.object, method) }.merge(options)
19
- @template.radio_button(@object_name, method, tag_value, objectify_options(options))
20
- end
21
-
22
- def validated_check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
23
- options = { "data-validate" => Judge::Utils.validators_to_json(self.object, method) }.merge(options)
24
- @template.check_box(self.object_name, method, objectify_options(options), checked_value, unchecked_value)
25
- end
26
-
27
- def validated_select(method, choices, options = {}, html_options = {})
28
- html_options = { "data-validate" => Judge::Utils.validators_to_json(self.object, method) }.merge(html_options)
29
- @template.select(self.object_name, method, choices, objectify_options(options), @default_options.merge(html_options))
30
- end
31
-
32
- def validated_collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
33
- html_options = { "data-validate" => Judge::Utils.validators_to_json(self.object, method) }.merge(html_options)
34
- @template.collection_select(self.object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options))
35
- end
36
-
37
- def validated_grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
38
- html_options = { "data-validate" => Judge::Utils.validators_to_json(self.object, method) }.merge(html_options)
39
- @template.grouped_collection_select(self.object_name, method, collection, group_method, group_label_method, option_key_method, option_value_method, objectify_options(options), @default_options.merge(html_options))
40
- end
41
-
42
- %w{date_select datetime_select time_select}.each do |type|
43
- helper = <<-END
44
- def validated_#{type}(method, options = {}, html_options = {})
45
- html_options = { "data-validate" => Judge::Utils.validators_to_json(self.object, method) }.merge(html_options)
46
- @template.#{type}(self.object_name, method, objectify_options(options), html_options)
47
- end
48
- END
49
- class_eval helper, __FILE__, __LINE__
50
- end
51
-
52
- def validated_time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
53
- html_options = { "data-validate" => Judge::Utils.validators_to_json(self.object, method) }.merge(html_options)
54
- @template.time_zone_select(@object_name, method, priority_zones, objectify_options(options), @default_options.merge(html_options))
55
- end
56
-
57
- end
58
-
59
- end
data/test/dummy/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- gem "rails", "~> 3.0.3"
2
- gem "sqlite3-ruby", "~> 1.3.2"
3
- gem "judge"
@@ -1,75 +0,0 @@
1
- GEM
2
- specs:
3
- abstract (1.0.0)
4
- actionmailer (3.0.3)
5
- actionpack (= 3.0.3)
6
- mail (~> 2.2.9)
7
- actionpack (3.0.3)
8
- activemodel (= 3.0.3)
9
- activesupport (= 3.0.3)
10
- builder (~> 2.1.2)
11
- erubis (~> 2.6.6)
12
- i18n (~> 0.4)
13
- rack (~> 1.2.1)
14
- rack-mount (~> 0.6.13)
15
- rack-test (~> 0.5.6)
16
- tzinfo (~> 0.3.23)
17
- activemodel (3.0.3)
18
- activesupport (= 3.0.3)
19
- builder (~> 2.1.2)
20
- i18n (~> 0.4)
21
- activerecord (3.0.3)
22
- activemodel (= 3.0.3)
23
- activesupport (= 3.0.3)
24
- arel (~> 2.0.2)
25
- tzinfo (~> 0.3.23)
26
- activeresource (3.0.3)
27
- activemodel (= 3.0.3)
28
- activesupport (= 3.0.3)
29
- activesupport (3.0.3)
30
- arel (2.0.10)
31
- builder (2.1.2)
32
- erubis (2.6.6)
33
- abstract (>= 1.0.0)
34
- i18n (0.5.0)
35
- judge (0.4.3)
36
- mail (2.2.15)
37
- activesupport (>= 2.3.6)
38
- i18n (>= 0.4.0)
39
- mime-types (~> 1.16)
40
- treetop (~> 1.4.8)
41
- mime-types (1.16)
42
- polyglot (0.3.2)
43
- rack (1.2.4)
44
- rack-mount (0.6.14)
45
- rack (>= 1.0.0)
46
- rack-test (0.5.7)
47
- rack (>= 1.0)
48
- rails (3.0.3)
49
- actionmailer (= 3.0.3)
50
- actionpack (= 3.0.3)
51
- activerecord (= 3.0.3)
52
- activeresource (= 3.0.3)
53
- activesupport (= 3.0.3)
54
- bundler (~> 1.0)
55
- railties (= 3.0.3)
56
- railties (3.0.3)
57
- actionpack (= 3.0.3)
58
- activesupport (= 3.0.3)
59
- rake (>= 0.8.7)
60
- thor (~> 0.14.4)
61
- rake (0.9.2)
62
- sqlite3-ruby (1.3.2)
63
- thor (0.14.6)
64
- treetop (1.4.10)
65
- polyglot
66
- polyglot (>= 0.3.1)
67
- tzinfo (0.3.30)
68
-
69
- PLATFORMS
70
- ruby
71
-
72
- DEPENDENCIES
73
- judge
74
- rails (~> 3.0.3)
75
- sqlite3-ruby (~> 1.3.2)
data/test/dummy/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
-
7
- Dummy::Application.load_tasks
@@ -1,3 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
- end
@@ -1,11 +0,0 @@
1
- class FoosController < ApplicationController
2
- def new
3
- @foo = Foo.new
4
-
5
- continent = Continent.new(:id => 1, :name => "Europe")
6
- country = Country.new(:id => 1, :name => "Germany")
7
- country.cities << City.new(:id => 1, :name => "Hamburg")
8
- continent.countries << country
9
- @continents = [continent]
10
- end
11
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,5 +0,0 @@
1
- class City < ActiveRecord::Base
2
- belongs_to :country
3
- end
4
-
5
-
@@ -1,4 +0,0 @@
1
- class Continent < ActiveRecord::Base
2
- has_many :countries
3
- end
4
-
@@ -1,6 +0,0 @@
1
- class Country < ActiveRecord::Base
2
- belongs_to :continent
3
- has_many :cities
4
- end
5
-
6
-
@@ -1,2 +0,0 @@
1
- class Fake < ActiveRecord::Base
2
- end
@@ -1,19 +0,0 @@
1
- class Foo < ActiveRecord::Base
2
-
3
- validates :one, :presence => true
4
- validates :two, :length => { :in => 5..10, :allow_blank => true }
5
- validates :three, :exclusion => { :in => %w{foo bar} }
6
- validates :four, :numericality => { :only_integer => true, :odd => true, :less_than_or_equal_to => 7 },
7
- :exclusion => { :in => [3,12] }
8
- validates :five, :format => { :without => /[A-Za-z]+/ }
9
- validates :six, :acceptance => true
10
- validates :seven, :confirmation => true
11
- validates :eight, :confirmation => true
12
-
13
- validates :nine, :presence => true, :uniqueness => true
14
- validates :ten, :presence => true
15
- validates :eleven, :presence => true
16
- validates :twelve, :presence => true
17
-
18
- end
19
-
@@ -1,71 +0,0 @@
1
- <h1>New foo</h1>
2
-
3
- <%= form_for(@foo) do |f| %>
4
- <% if @foo.errors.any? %>
5
- <div id="error_explanation">
6
- <h2><%= pluralize(@foo.errors.count, "error") %> prohibited this foo from being saved:</h2>
7
-
8
- <ul>
9
- <% @foo.errors.full_messages.each do |msg| %>
10
- <li><%= msg %></li>
11
- <% end %>
12
- </ul>
13
- </div>
14
- <% end %>
15
-
16
- <div class="field">
17
- <%= f.label :one %><br />
18
- <%= f.validated_select :one, [["hello", "HELLO"],["goodbye", "GOODBYE"]] %>
19
- </div>
20
- <div class="field">
21
- <%= f.label :two %><br />
22
- <%= f.validated_radio_button :two, "FOOBAR" %>
23
- </div>
24
- <div class="field">
25
- <%= f.label :three %><br />
26
- <%= f.validated_collection_select :three, [Fake.new(:text => "Dave", :value => 24), Fake.new(:text => "Alice", :value => 30)], :value, :text %>
27
- </div>
28
- <div class="field">
29
- <%= f.label :four %><br />
30
- <%= f.validated_text_area :four %>
31
- </div>
32
- <div class="field">
33
- <%= f.label :five %><br />
34
- <%= f.validated_grouped_collection_select :five, @continents, :countries, :name, :id, :name %>
35
- </div>
36
- <div class="field">
37
- <%= f.label :six %><br />
38
- <%= f.validated_check_box :six %>
39
- </div>
40
- <div class="field">
41
- <%= f.label :seven %><br />
42
- <%= f.validated_text_field :seven %>
43
- </div>
44
- <div class="field">
45
- <%= f.label :eight %><br />
46
- <%= f.validated_password_field :eight %>
47
- </div>
48
- <div class="field">
49
- <%= f.label :nine %><br />
50
- <%= f.validated_time_zone_select :nine, ActiveSupport::TimeZone.us_zones, :include_blank => true %>
51
- </div>
52
- <div class="field">
53
- <%= f.label :ten %><br />
54
- <%= f.validated_time_select :ten, :include_blank => true, :ignore_date => true %>
55
- </div>
56
- <div class="field">
57
- <%= f.label :eleven %><br />
58
- <%= f.validated_datetime_select :eleven, :include_blank => true %>
59
- </div>
60
- <div class="field">
61
- <%= f.label :twelve %><br />
62
- <%= f.validated_date_select :twelve, :include_blank => true %>
63
- </div>
64
-
65
- <div class="actions">
66
- <%= f.submit %>
67
- </div>
68
- <% end %>
69
-
70
-
71
- <%= link_to 'Back', foos_path %>
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag :all %>
6
- <%= javascript_include_tag :defaults %>
7
- <%= csrf_meta_tag %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
data/test/dummy/config.ru DELETED
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run Dummy::Application
@@ -1,45 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require "active_model/railtie"
4
- require "active_record/railtie"
5
- require "action_controller/railtie"
6
- require "action_view/railtie"
7
- require "action_mailer/railtie"
8
-
9
- Bundler.require
10
- #require "dummy"
11
-
12
- module Dummy
13
- class Application < Rails::Application
14
- # Settings in config/environments/* take precedence over those specified here.
15
- # Application configuration should go into files in config/initializers
16
- # -- all .rb files in that directory are automatically loaded.
17
-
18
- # Custom directories with classes and modules you want to be autoloadable.
19
- # config.autoload_paths += %W(#{config.root}/extras)
20
-
21
- # Only load the plugins named here, in the order given (default is alphabetical).
22
- # :all can be used as a placeholder for all plugins not explicitly named.
23
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
-
25
- # Activate observers that should always be running.
26
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
-
28
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
- # config.time_zone = 'Central Time (US & Canada)'
31
-
32
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
- # config.i18n.default_locale = :de
35
-
36
- # JavaScript files you want as :defaults (application.js is always included).
37
- # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
38
-
39
- # Configure the default encoding used in templates for Ruby 1.9.
40
- config.encoding = "utf-8"
41
-
42
- # Configure sensitive parameters which will be filtered from the log file.
43
- config.filter_parameters += [:password]
44
- end
45
- end
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- if File.exist?(gemfile)
5
- ENV['BUNDLE_GEMFILE'] = gemfile
6
- require 'bundler'
7
- Bundler.setup
8
- end
9
-
10
- $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,22 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
- development:
4
- adapter: sqlite3
5
- database: db/development.sqlite3
6
- pool: 5
7
- timeout: 5000
8
-
9
- # Warning: The database defined as "test" will be erased and
10
- # re-generated from your development database when you run "rake".
11
- # Do not set this db to the same as development or production.
12
- test:
13
- adapter: sqlite3
14
- database: db/test.sqlite3
15
- pool: 5
16
- timeout: 5000
17
-
18
- production:
19
- adapter: sqlite3
20
- database: db/production.sqlite3
21
- pool: 5
22
- timeout: 5000
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- Dummy::Application.initialize!
@@ -1,26 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.consider_all_requests_local = true
14
- config.action_view.debug_rjs = true
15
- config.action_controller.perform_caching = false
16
-
17
- # Don't care if the mailer can't send
18
- config.action_mailer.raise_delivery_errors = false
19
-
20
- # Print deprecation notices to the Rails logger
21
- config.active_support.deprecation = :log
22
-
23
- # Only use best-standards-support built into browsers
24
- config.action_dispatch.best_standards_support = :builtin
25
- end
26
-
@@ -1,49 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The production environment is meant for finished, "live" apps.
5
- # Code is not reloaded between requests
6
- config.cache_classes = true
7
-
8
- # Full error reports are disabled and caching is turned on
9
- config.consider_all_requests_local = false
10
- config.action_controller.perform_caching = true
11
-
12
- # Specifies the header that your server uses for sending files
13
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
-
15
- # For nginx:
16
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
-
18
- # If you have no front-end server that supports something like X-Sendfile,
19
- # just comment this out and Rails will serve the files
20
-
21
- # See everything in the log (default is :info)
22
- # config.log_level = :debug
23
-
24
- # Use a different logger for distributed setups
25
- # config.logger = SyslogLogger.new
26
-
27
- # Use a different cache store in production
28
- # config.cache_store = :mem_cache_store
29
-
30
- # Disable Rails's static asset server
31
- # In production, Apache or nginx will already do this
32
- config.serve_static_assets = false
33
-
34
- # Enable serving of images, stylesheets, and javascripts from an asset server
35
- # config.action_controller.asset_host = "http://assets.example.com"
36
-
37
- # Disable delivery errors, bad email addresses will be ignored
38
- # config.action_mailer.raise_delivery_errors = false
39
-
40
- # Enable threaded mode
41
- # config.threadsafe!
42
-
43
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
- # the I18n.default_locale when a translation can not be found)
45
- config.i18n.fallbacks = true
46
-
47
- # Send deprecation notices to registered listeners
48
- config.active_support.deprecation = :notify
49
- end