Permalink
Browse files

Ported test backend from PHP to Ruby using Sinatra

git-svn-id: https://svn.cjohansen.no/validatious2/trunk@2667 1ed5ca13-5fb8-644a-9ef7-ad08ef2e8add
  • Loading branch information...
1 parent 4b751ad commit e2a2e5442848ee2406338a99321e1e744a89d269 christian committed Dec 30, 2008
Showing with 993 additions and 5,722 deletions.
  1. +5 −1 {doc → }/Changelog.txt
  2. 0 {doc → }/License.txt
  3. +26 −59 Rakefile
  4. +54 −0 Readme.rdoc
  5. +6 −1 lib/vbuilder/file_extra.rb
  6. +23 −0 lib/vbuilder/validator.rb
  7. +22 −3 lib/vbuilder/vbuilder.rb
  8. +1 −0 src/bridge/mootools.js
  9. +1 −0 src/bridge/prototype.js
  10. +0 −4,221 src/lib/prototype-1.6.0.2.js
  11. +0 −1 src/lib/prototype.min.js
  12. +0 −26 test/bridge/foreach_filter.js
  13. +0 −346 test/bridge/test_standalone_utf8.php
  14. +0 −26 test/core/remove.js
  15. +0 −48 test/core/test_fieldset.php
  16. +0 −92 test/core/test_form.php
  17. +0 −57 test/core/test_interface.php
  18. +0 −58 test/extensions/test_html2.php
  19. 0 test/{utils → public}/test_helper.js
  20. +0 −52 test/test_suite.php
  21. +0 −58 test/utils/core.php
  22. +133 −0 test/validatious-suite.rb
  23. +75 −86 test/{bridge/test_mootools.php → views/bridge/test_mootools.erb}
  24. +74 −85 test/{bridge/test_prototype.php → views/bridge/test_prototype.erb}
  25. +74 −85 test/{bridge/test_standalone.php → views/bridge/test_standalone.erb}
  26. +3 −14 test/{core/test_composite_form_item.php → views/core/test_composite_form_item.erb}
  27. +32 −43 test/{core/test_field.php → views/core/test_field.erb}
  28. +84 −95 test/{core/test_field_element.php → views/core/test_field_element.erb}
  29. +8 −19 test/{core/test_field_validator.php → views/core/test_field_validator.erb}
  30. +37 −0 test/views/core/test_fieldset.erb
  31. +81 −0 test/views/core/test_form.erb
  32. +4 −15 test/{core/test_message.php → views/core/test_message.erb}
  33. +9 −20 test/{core/test_validator.php → views/core/test_validator.erb}
  34. +35 −44 test/{extensions/test_dsl.php → views/extensions/test_dsl.erb}
  35. +77 −85 test/{extensions/test_html.php → views/extensions/test_html.erb}
  36. +47 −55 test/{extensions/test_reporting.php → views/extensions/test_reporting.erb}
  37. +11 −0 test/views/index.erb
  38. +14 −0 test/views/layout.erb
  39. +41 −0 test/views/test_suite.erb
  40. +16 −27 test/{test_validators.php → views/test_validators.erb}
@@ -1,4 +1,4 @@
-### Validatious 0.9.2 - 2008-12-xx
+### Validatious 0.9.2 - 2008-12-30
[Bridges] Added Mootools bridge
@@ -7,6 +7,10 @@
[Core] Cleaned up source - removed some outdated code and files
+[Backend] Ported test backend from PHP to Ruby via Sinatra
+
+[Backend] Cleaned up Rakefile and distribution builder
+
### Validatious 0.9.1 - 2008-10-07
[Core] Added click events to buttons in v2.Form.prototype.addButton to track
File renamed without changes.
View
@@ -4,11 +4,14 @@ require 'tmpdir'
require 'fileutils'
$verbose = true
+bridges = Dir.glob("src/bridge/*.js").collect do |bridge|
+ File.basename(bridge).sub(/\.js$/, "")
+end
task :default => :build
desc 'Builds all files'
-task :build => ['build:standalone:all', 'build:prototype:all'] do
+task :build => ["build:standalone:all"].concat(bridges.collect { |bridge| "build:#{bridge}:all" }) do
# It's all in the prerequisites
end
@@ -19,76 +22,40 @@ namespace :build do
V2::Validator.join(File.join(File.dirname(__FILE__), 'src/validators/standard.js'))
end
- desc 'Builds the minified standalone core (no extensions)'
- task :standalone do
- builder = ValidatiousBuilder.new(File.dirname(__FILE__))
- builder.assemble(File.join(builder.basedir, "dist/v2.standalone#{suffix}"), minify?)
- end
-
- desc 'Builds the minified prototype core (no extensions)'
- task :prototype do
- builder = ValidatiousBuilder.new(File.dirname(__FILE__))
- builder.set_library :prototype
- builder.assemble(File.join(builder.basedir, "dist/v2.prototype#{suffix}"), minify?)
- end
-
- namespace :standalone do
-
- desc 'Builds all the standalone files'
- task :all => ['build:standalone', 'build:standalone:full'] do
- # It's all in the prerequisites...
- end
-
- desc 'Builds the minified standalone core with all extensions'
- task :full do
+ #
+ # Define individual build tasks for each supported library
+ #
+ bridges.each do |bridge|
+ desc "Builds the minified #{bridge} core (no extensions)"
+ task bridge.to_sym do
builder = ValidatiousBuilder.new(File.dirname(__FILE__))
- builder.add_extension(:reporting, :html, :dsl)
- builder.assemble(File.join(builder.basedir, "dist/v2.standalone.full#{suffix}"), minify?)
+ builder.set_library(bridge.to_sym)
+ builder.assemble(File.join(builder.basedir, "dist/v2.#{bridge}#{suffix}"), minify?)
end
- end
- namespace :prototype do
-
- desc 'Builds all the prototype files'
- task :all => ['build:prototype', 'build:prototype:full'] do
- # It's all in the prerequisites...
+ namespace bridge.to_sym do
+ desc "Builds all the #{bridge} files"
+ task :all => ["build:#{bridge}", "build:#{bridge}:full"] do
+ # It's all in the prerequisites...
+ end
+
+ desc "Builds the minified #{bridge} core with all extensions"
+ task :full do
+ builder = ValidatiousBuilder.new(File.dirname(__FILE__))
+ builder.set_library(bridge)
+ builder.add_extension(:reporting, :html, :dsl)
+ builder.assemble(File.join(builder.basedir, "dist/v2.#{bridge}.full#{suffix}"), minify?)
+ end
end
- desc 'Builds the minified prototype core with all extensions'
- task :full do
- builder = ValidatiousBuilder.new(File.dirname(__FILE__))
- builder.set_library :prototype
- builder.add_extension(:reporting, :html, :dsl)
- builder.assemble(File.join(builder.basedir, "dist/v2.prototype.full#{suffix}"), minify?)
- end
end
end
desc 'Produces a new release of validatious'
task :release do
- raise 'Usage: rake release VERSION=x.y.z [TARGET=dir]' unless ENV.key? 'VERSION'
+ raise 'Usage: rake release VERSION=x.y.z' unless ENV.key? 'VERSION'
version = ENV['VERSION']
- if ENV['TARGET']
- # Copy files and create zip
- target = Dir.tmpdir
- target_file = File.expand_path(ENV['TARGET'])
-
- FileUtils.cp_r(File.dirname(__FILE__), target)
- Dir.chdir target
-
- FileUtils.rm_r Dir.glob(File.join('**', '.svn'))
- FileUtils.rm_r Dir.glob(File.join('**', '*interface*js'))
- FileUtils.rm_r Dir.glob(File.join('**', 'lib/*prototype*js'))
- FileUtils.rm_r Dir.glob(File.join('**', 'dist/*js'))
-
- dirname = File.basename(File.dirname(__FILE__))
- `zip -r #{File.join(target_file, 'validatious-' + version + '-src.zip')} #{dirname}`
-
- Dir.chdir File.dirname(__FILE__)
- FileUtils.rm_r File.join(target, dirname)
- end
-
# Tag release in subversion
`svn info` =~ /URL: (.*)\/trunk/
repo = $1
View
@@ -0,0 +1,54 @@
+= Validatious 2.0
+
+Validatious 2.0 is a JavaScript library that provides very flexible unobtrusive
+client side form validation.
+
+== Features
+
+* Library agnostic (there's even a standalone version)
+* Multilingual (just include the right language file alongside the core file)
+* Easy to create custom validators (just use v2.Validator.add())
+* Easy to validate forms with semantic HTML (use class names to annotate
+ validation)
+* Create complex validations using a simple DSL
+* Completely unobtrusive
+* Modular - take only the pieces you need (don't need DSL features? Don't
+ download it!)
+* Easy to configure error reporting
+* Easy to create completely custom error reporting using callbacks (per form,
+ per fieldset, per field - your choice)
+* Can make a lot of good guesses about field names, error messages and more -
+ or you can provide your own.
+* Makes no assumptions you cannot override.
+* Good test coverage
+* Cross browser
+
+== Library agnostic
+
+Validatious was originally built standalone. A small standalone library gives
+Validatious essential tools. However, if you're already using a library there's
+no need to duplicate efforts. For this reason, bridges have been built to both
+MooTools and Prototype.js. These bridges simply map the API of the standalone
+library, allowing you to shave off a few kB's on the total file size.
+
+If Validatious doesn't have a bridge to your favourite library, don't panic! You
+don't actually need one, it's only convenient as a measure to save a few kB's.
+
+Validatious is designed to be truly unobtrusive, meaning it should work
+regardless of what other code you're running on your site. As long as you don't
+override the v2 object, everything should work nicely. You can, for instance,
+use jQuery along with Validatious standalone without problems.
+
+== Tests
+
+To run tests you need Ruby. Because Validatious is shipped both standalone, as
+well with bridges for Prototype.js and Mootools, it's important to be able to
+run the whole test suite against different sets of scripts. For this reason a
+small web application has been built using Sinatra.
+
+* Install Ruby
+* Install RubyGems
+* gem install sinatra
+* gem install juicer
+* ruby test/validatious-suite.rb
+* Go to http://localhost:4567 and click on the suite you'd like to test
@@ -1,5 +1,6 @@
#
# Joins the content of several files with a newline between
+# TODO: Use Juicer API instead
#
def File.cat(*files)
files = files[0] if files.respond_to?(:push)
@@ -9,6 +10,10 @@ def File.cat(*files)
end
end
+#
+# Merge files into a single minified file
+# TODO: Use Juicer API instead
+#
def File.merge(files, target, minify = true)
tmp = "#{target}.tmp"
tmp = target unless minify
@@ -32,7 +37,7 @@ def File.merge(files, target, minify = true)
/**
* TERMS OF USE - Validatious 2.0
* Open source under the BSD License.
- * Copyright 2008 Christian Johansen.
+ * Copyright 2008-2009 Christian Johansen.
* All rights reserved.
*/
EOF
@@ -1,4 +1,7 @@
module V2
+ #
+ # Ruby representation of Validatious validator source
+ #
class Validator
attr_reader :name, :description, :source, :since
@@ -26,6 +29,10 @@ def <=>(other)
name <=> other.name
end
+ #
+ # Reads a Validatious validator source file and creates a V2::Validator
+ # object representing it.
+ #
def self.from_file(file)
comment = ''
name = nil
@@ -62,6 +69,10 @@ def self.from_file(file)
Validator.new(name, comment.strip.gsub(/ /, ' '), source.sub(/\);$/, ''), builtin, since)
end
+ #
+ # Finds all validators in a given directory. All .js files in the given
+ # directory are assumed to be validators.
+ #
def self.find_all(path, builtin = false)
validators = []
@@ -75,6 +86,18 @@ def self.find_all(path, builtin = false)
validators.sort
end
+ #
+ # Joins together several validator files. The point of this operation is to
+ # save a few bytes in the generated JS source. This is achieved by creating
+ # an anonymous closure that holds the uncompressable v2.Validator namespace
+ # in the local variable v, and uses this instead of v2.Validator for each
+ # added validator.
+ #
+ # This technique saves 11 bytes per validator. The overhead is 35 bytes, so
+ # use this when you have 4 or more validators to join.
+ #
+ # Every byte counts! :)
+ #
def self.join(output, names = nil)
dirname = File.dirname(output)
names ||= Validator.find_all(dirname, true).collect { |v| v.filename }
@@ -3,6 +3,9 @@
require 'file_extra'
require 'validator'
+#
+# Builds Validatious distribution files
+#
class ValidatiousBuilder
attr_reader :basedir
@@ -19,33 +22,49 @@ def initialize(basedir)
@language = 'en'
end
+ #
+ # Set which library to base distribution on. Default distribution is
+ # standalone. Parameter should be a symbol representation, like :mootools
+ #
def set_library(library)
if library == :standalone
@library = ['lib/add_dom_load_event', 'lib/Base', 'lib/events', 'bridge/standalone']
- elsif library == :prototype
- @library = ['lib/Base', 'bridge/prototype']
+ else
+ @library = ["lib/Base", "bridge/#{library}"]
end
end
+ #
+ # Add a Validatious extension (like :dsl, :html, :reporting)
+ #
def add_extension(*name)
name = name[0] if name[0].respond_to?(:push)
@extensions.concat(name.collect { |n| "extensions/#{n}" })
end
+ #
+ # Add a validator to the mix
+ #
def add_validator(*name)
name = name[0] if name[0].respond_to?(:push)
@validators = [] if @validators.nil?
@validators.concat name
end
+ #
+ # Set language of default error messages
+ #
def set_language(lang)
@language = lang
end
+ #
+ # Assemble distribution into file and optionally minify it
+ #
def assemble(filename = nil, minify = true)
fname = filename || 'tmp.min.js'
- V2::Validator.join(File.join(@basedir, 'src/validators/standard.js'), @validators)
+ V2::Validator.join(File.join(@basedir, 'src/validators/standard.js'), @validators) unless @validators.nil?
files = (@library + @core + ['validators/standard'] +
["messages/errors.#{@language}"] + @extensions).collect do |file|
@@ -1,5 +1,6 @@
/**
* @fileOverview Mootools bridge for validatious
+ * @depends ../lib/Base.js
*/
// Global namespace
if (typeof v2 === 'undefined' || v2 === null) {
@@ -1,5 +1,6 @@
/**
* @fileOverview Prototype bridge for validatious
+ * @depends ../lib/Base.js
*/
// Global namespace
if (typeof v2 === 'undefined' || v2 === null) {
Oops, something went wrong.

0 comments on commit e2a2e54

Please sign in to comment.