Permalink
Browse files

Initial add, imported regular coffeescript from ClientSideValidations

  • Loading branch information...
0 parents commit c28d4610c1cad8e1ae145c6b6f2f63487b14749e @bcardarella bcardarella committed Jan 25, 2012
Showing with 4,405 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +9 −0 .travis.yml
  3. +12 −0 Gemfile
  4. +77 −0 README.md
  5. +104 −0 Rakefile
  6. +27 −0 client_side_validations-simple_form.gemspec
  7. +35 −0 coffeescript/processor.rb
  8. +306 −0 coffeescript/rails.validations.backbone.coffee
  9. +7 −0 gemfiles/Gemfile
  10. +6 −0 lib/client_side_validations-backbone.rb
  11. +1 −0 lib/client_side_validations/backbone.rb
  12. +2 −0 lib/client_side_validations/backbone/engine.rb
  13. +5 −0 lib/client_side_validations/backbone/version.rb
  14. +17 −0 lib/client_side_validations/generators/backbone.rb
  15. +8 −0 test/base_helper.rb
  16. +80 −0 test/generators/cases/test_generators.rb
  17. +3 −0 test/javascript/config.ru
  18. +54 −0 test/javascript/public/test/callbacks/elementAfter.js
  19. +54 −0 test/javascript/public/test/callbacks/elementBefore.js
  20. +70 −0 test/javascript/public/test/callbacks/elementFail.js
  21. +70 −0 test/javascript/public/test/callbacks/elementPass.js
  22. +45 −0 test/javascript/public/test/callbacks/formAfter.js
  23. +45 −0 test/javascript/public/test/callbacks/formBefore.js
  24. +51 −0 test/javascript/public/test/callbacks/formFail.js
  25. +50 −0 test/javascript/public/test/callbacks/formPass.js
  26. +77 −0 test/javascript/public/test/form_builders/validateForm.js
  27. +15 −0 test/javascript/public/test/settings.js
  28. +296 −0 test/javascript/public/test/validateElement.js
  29. +42 −0 test/javascript/public/test/validators/acceptance.js
  30. +25 −0 test/javascript/public/test/validators/confirmation.js
  31. +41 −0 test/javascript/public/test/validators/exclusion.js
  32. +27 −0 test/javascript/public/test/validators/format.js
  33. +42 −0 test/javascript/public/test/validators/inclusion.js
  34. +76 −0 test/javascript/public/test/validators/length.js
  35. +151 −0 test/javascript/public/test/validators/numericality.js
  36. +21 −0 test/javascript/public/test/validators/presence.js
  37. +107 −0 test/javascript/public/test/validators/uniqueness.js
  38. +122 −0 test/javascript/public/vendor/jquery.metadata.js
  39. +196 −0 test/javascript/public/vendor/qunit.css
  40. +1,374 −0 test/javascript/public/vendor/qunit.js
  41. +134 −0 test/javascript/server.rb
  42. +23 −0 test/javascript/views/index.erb
  43. +21 −0 test/javascript/views/layout.erb
  44. +4 −0 test/test_loader.rb
  45. +419 −0 vendor/assets/javascripts/rails.validations.backbone.js
  46. +37 −0 vendor/assets/javascripts/rails.validations.simple_form.js
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,9 @@
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
+ - ree
+ - jruby
+ - rbx-2.0
+gemfile:
+ - gemfiles/Gemfile
12 Gemfile
@@ -0,0 +1,12 @@
+source 'http://rubygems.org'
+
+gemspec
+
+ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
+if ruby_minor_version == 8
+ gem 'minitest'
+ gem 'ruby-debug'
+elsif ruby_minor_version == 9
+ gem 'ruby-debug19', :require => 'ruby-debug'
+end
+
@@ -0,0 +1,77 @@
+# ClientSideValidations-Backbone #
+
+[![Build Status](http://travis-ci.org/dockyard/client_side_validations-backbone.png)](http://travis-ci.org/dockyard/client_side_validations-backbone)
+
+[Backbone](https://github.com/documentcloud/backbone) plugin for [ClientSideValidations](https://github.com/bcardarella/client_side_validations)
+
+## Installation ##
+
+In your Gemfile add the following:
+
+```ruby
+gem 'client_side_validations'
+gem 'client_side_validations-backbone'
+```
+
+Order matters here. `ClientSideValidations` need to be
+required **before** `ClientSideValidations-Backbone`.
+
+[Follow the remaining installation instructions for ClientSideValidations](https://github.com/bcardarella/client_side_validations/README.markdown)
+
+Add the following line to `app/assets/javascripts/application.js`
+
+```javascript
+//= require rails.validations.backbone
+```
+Again, order matters. You should add this line after the require for `rails.validations` as described in the `ClientSideValidations` installation instructions.
+
+If the asset pipeline is disabled the asset file will be copied
+into `public/javascripts` when the `ClientSideValidations` install generator is run.
+
+At any time you can copy the asset file into your project by running:
+
+```
+rails g client_side_validations:copy_assets
+```
+
+If the asset pipeline is disabled the asset file will be copied
+into `public/javascripts`. Otherwise the asset file will be copied into
+`app/assets/javascripts` (or whatever asset directory you have
+defined)
+
+## Usage ##
+
+TODO
+
+## Authors ##
+
+[Brian Cardarella](http://twitter.com/bcardarella)
+
+## Versioning ##
+
+This gem follows [Semantic Versioning](http://semver.org)
+
+Major and minor version numbers will follow `Backbone`'s major and
+minor version numbers. For example,
+`client_side_validations-backbone-0.5.0` will be compatible with
+`~> Backbone 0.5.0`
+
+## Want to help? ##
+
+Stable branches are created based upon each minor version. Please make
+pull requests to specific branches rather than master.
+
+Please make sure you include tests!
+
+Unles Rails drops support for Ruby 1.8.7 we will continue to use the
+hash-rocket syntax. Please respect this.
+
+Don't use tabs to indent, two spaces are the standard.
+
+## Legal ##
+
+[DockYard](http://dockyard.com), LLC © 2012
+
+[@dockyard](http://twitter.com/dockyard)
+
+[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
104 Rakefile
@@ -0,0 +1,104 @@
+require 'bundler'
+require File.join(File.expand_path('..', __FILE__), 'coffeescript/processor')
+Bundler::GemHelper.install_tasks
+
+multitask :default => 'test:ruby'
+
+require 'rake/testtask'
+namespace :test do
+ desc %(Run all tests)
+ multitask :all => ['test:ruby', 'test:js']
+
+ desc %(Test Ruby code)
+ Rake::TestTask.new(:ruby) do |test|
+ test.libs << 'lib' << 'test'
+ test.test_files = Dir.glob("#{File.dirname(__FILE__)}/test/**/test_*.rb").sort
+ end
+
+ desc %(Test Javascript code)
+ multitask :js => ['test:server', 'test:open']
+
+ desc %(Starts the test server)
+ task :server do
+ system 'bundle exec ruby test/javascript/server.rb'
+ end
+
+ desc %(Starts the test server which reloads everything on each refresh)
+ task :reloadable do
+ exec "bundle exec shotgun test/javascript/config.ru -p #{PORT} --server thin"
+ end
+
+ task :open do
+ url = "http://localhost:#{PORT}"
+ puts "Opening test app at #{url} ..."
+ sleep 3
+ system( *browse_cmd(url) )
+ end
+end
+
+desc %{Regenerate and commit JavaScript file}
+task :regenerate_javascript do
+ regenerate_javascript
+end
+
+Rake::Task[:build].instance_eval { @actions.clear }
+task :build do
+ regenerate_javascript
+ perform_git_commit
+ Bundler::GemHelper.new(Dir.pwd).build_gem
+end
+
+def perform_git_commit
+ sh_with_code('git add vendor')
+ out, code = sh_with_code('git commit -m "Regenerated JavaScript"')
+ if code == 0
+ puts "Committed changes"
+ else
+ puts "Nothing to commit"
+ end
+end
+
+def regenerate_javascript
+ ClientSideValidations::Processor.run
+ puts 'Regenerated JavaScript'
+end
+
+def sh_with_code(cmd, &block)
+ cmd << " 2>&1"
+ outbuf = ''
+ Bundler.ui.debug(cmd)
+ Dir.chdir(Dir.pwd) {
+ outbuf = `#{cmd}`
+ if $? == 0
+ block.call(outbuf) if block
+ end
+ }
+ [outbuf, $?]
+end
+
+PORT = 4567
+
+# Returns an array e.g.: ['open', 'http://example.com']
+def browse_cmd(url)
+ require 'rbconfig'
+ browser = ENV['BROWSER'] ||
+ (RbConfig::CONFIG['host_os'].include?('darwin') && 'open') ||
+ (RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw|windows/ && 'start') ||
+ %w[xdg-open x-www-browser firefox opera mozilla netscape].find { |comm| which comm }
+
+ abort('ERROR: no web browser detected') unless browser
+ Array(browser) << url
+end
+
+# which('ruby') #=> /usr/bin/ruby
+def which cmd
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
+ exts.each { |ext|
+ exe = "#{path}/#{cmd}#{ext}"
+ return exe if File.executable? exe
+ }
+ end
+ return nil
+end
+
@@ -0,0 +1,27 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/client_side_validations/backbone/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Brian Cardarella"]
+ gem.email = ["bcardarella@gmail.com"]
+ gem.description = %q{Backbone Plugin for ClientSideValidaitons}
+ gem.summary = %q{Backbone Plugin for ClientSideValidations}
+ gem.homepage = 'https://github.com/dockyard/client_side_validations-backbone'
+
+ gem.files = `git ls-files -- {lib/*,vendor/*,*.gemspec}`.split("\n")
+ gem.name = 'client_side_validations-backbone'
+ gem.require_paths = ['lib']
+ gem.version = ClientSideValidations::Backbone::VERSION
+
+ gem.add_dependency 'client_side_validations', '~> 3.2.0.beta.1'
+
+ gem.add_development_dependency 'rails', '~> 3.2.0'
+ gem.add_development_dependency 'mocha'
+
+ # For QUnit testing
+ gem.add_development_dependency 'sinatra', '~> 1.0'
+ gem.add_development_dependency 'shotgun'
+ gem.add_development_dependency 'thin'
+ gem.add_development_dependency 'json'
+ gem.add_development_dependency 'coffee-script'
+end
@@ -0,0 +1,35 @@
+$:.unshift(File.expand_path('../../lib', __FILE__))
+
+require 'client_side_validations/backbone/version'
+require 'coffee_script'
+require 'erb'
+
+module ClientSideValidations
+ class Processor
+ def self.run
+ write_file
+ end
+
+ def self.root_path
+ File.expand_path('../..', __FILE__)
+ end
+
+ def self.file_name
+ 'rails.validations.backbone'
+ end
+
+ def self.template
+ ERB.new(File.open(File.join(root_path, 'coffeescript', "#{file_name}.coffee")).read)
+ end
+
+ def self.compiled_coffeescript
+ CoffeeScript.compile(template.result(binding))
+ end
+
+ def self.write_file
+ file = File.new(File.join(root_path, "vendor/assets/javascripts/#{file_name}.js"), 'w')
+ file << compiled_coffeescript
+ file.close
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit c28d461

Please sign in to comment.