Skip to content

Commit

Permalink
Initial import from ClientSideValidations-3.1 stable
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Jan 22, 2012
0 parents commit 5b756d4
Show file tree
Hide file tree
Showing 31 changed files with 2,395 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
@@ -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
9 changes: 9 additions & 0 deletions .travis.yml
@@ -0,0 +1,9 @@
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- ree
- jruby
- rbx-2.0
gemfile:
- gemfiles/Gemfile
12 changes: 12 additions & 0 deletions 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

77 changes: 77 additions & 0 deletions README.md
@@ -0,0 +1,77 @@
# ClientSideValidations-SimpleForm #

[![Build Status](http://travis-ci.org/dockyard/client_side_validations-simple_form.png)](http://travis-ci.org/dockyard/client_side_validations-simple_form)

SimpleForm plugin for [ClientSideValidations](https://github.com/bcardarella/client_side_validations)

## Installation ##

In your Gemfile add the following:

```ruby
gem 'simple_form'
gem 'client_side_validations'
gem 'client_side_validations-simple_form'
```

Order matters here. `SimpleForm` and `ClientSideValidations` need to be
required **before** `ClientSideValidations-SimpleForm`.

[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.simple_form
```

Again, order matters. You should add this line after the require for `rails.validations` as described in the `ClientSideValidations` installation instructions.

## Usage ##

The usage is the same as `ClientSideValidations`, just pass `:validate => true` to the form builder

```ruby
<%= simple_form_for @book, :validate => true |book| do %>
<%= book.input :name %>
<% end %>
```
Per-input options are done with `:validate`
```ruby
<%= book.input :name, :validate => { :presence => true, :uniqueness => false }
```

## Authors ##

[Brian Cardarella](http://twitter.com/bcardarella)

## Versioning ##

This gem follows [Semantic Versioning](http://semver.org)

Major and minor version numbers will follow `SimpleForm`'s major and
minor version numbers. For example,
`client_side_validations-simple_form-1.5.0` will be compatible with
`~> simple_form-1.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 &copy; 2012

[@dockyard](http://twitter.com/dockyard)

[Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php)
63 changes: 63 additions & 0 deletions Rakefile
@@ -0,0 +1,63 @@
require 'bundler'
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

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

28 changes: 28 additions & 0 deletions client_side_validations-simple_form.gemspec
@@ -0,0 +1,28 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/client_side_validations/simple_form/version', __FILE__)

Gem::Specification.new do |gem|
gem.authors = ["Brian Cardarella"]
gem.email = ["bcardarella@gmail.com"]
gem.description = %q{SimpleForm Plugin for ClientSideValidaitons}
gem.summary = %q{SimpleForm Plugin for ClientSideValidations}
gem.homepage = 'https://github.com/dockyard/client_side_validations-simple_form'

gem.files = `git ls-files -- {lib/*,vendor/*,*.gemspec}`.split("\n")
gem.name = 'client_side_validations-simple_form'
gem.require_paths = ['lib']
gem.version = ClientSideValidations::SimpleForm::VERSION

gem.add_dependency 'client_side_validations', '~> 3.2.0.beta.1'
gem.add_dependency 'simple_form', '~> 1.5.0'

gem.add_development_dependency 'actionpack', '~> 3.2.0'
gem.add_development_dependency 'railties', '~> 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'
end
5 changes: 5 additions & 0 deletions gemfiles/Gemfile
@@ -0,0 +1,5 @@
source 'http://rubygems.org'

gem 'actionpack', '~> 3.2.0'
gem 'simple_form', '~> 1.5.0'
gem 'client_side_validations', '~> 3.2.0.beta.1'
1 change: 1 addition & 0 deletions lib/client_side_validations-simple_form.rb
@@ -0,0 +1 @@
require 'client_side_validations/simple_form'
3 changes: 3 additions & 0 deletions lib/client_side_validations/simple_form.rb
@@ -0,0 +1,3 @@
require 'simple_form'
require 'client_side_validations/simple_form/form_builder'
require 'client_side_validations/simple_form/engine'
2 changes: 2 additions & 0 deletions lib/client_side_validations/simple_form/engine.rb
@@ -0,0 +1,2 @@
class ClientSideValidations::SimpleForm::Engine < ::Rails::Engine; end

34 changes: 34 additions & 0 deletions lib/client_side_validations/simple_form/form_builder.rb
@@ -0,0 +1,34 @@
module ClientSideValidations
module SimpleForm
module FormBuilder

def self.included(base)
base.class_eval do
def self.client_side_form_settings(options, form_helper)
{
:type => self.to_s,
:error_class => ::SimpleForm.error_class,
:error_tag => ::SimpleForm.error_tag,
:wrapper_error_class => ::SimpleForm.wrapper_error_class,
:wrapper_tag => ::SimpleForm.wrapper_tag
}
end
alias_method_chain :input, :client_side_validations
end
end

def input_with_client_side_validations(attribute_name, options = {}, &block)
if options.key?(:validate)
options[:input_html] ||= {}
options[:input_html].merge!(:validate => options[:validate])
options.delete(:validate)
end

input_without_client_side_validations(attribute_name, options, &block)
end

end
end
end

SimpleForm::FormBuilder.send(:include, ClientSideValidations::SimpleForm::FormBuilder)
5 changes: 5 additions & 0 deletions lib/client_side_validations/simple_form/version.rb
@@ -0,0 +1,5 @@
module ClientSideValidations
module SimpleForm
VERSION = '1.5.0.beta.1'
end
end
2 changes: 2 additions & 0 deletions test/action_view/models.rb
@@ -0,0 +1,2 @@
require 'active_model'
require 'action_view/models/post'
35 changes: 35 additions & 0 deletions test/action_view/models/post.rb
@@ -0,0 +1,35 @@
class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
extend ActiveModel::Naming
include ActiveModel::Conversion
extend ActiveModel::Translation

alias_method :secret?, :secret

def persisted=(boolean)
@persisted = boolean
end

def persisted?
@persisted
end

def client_side_validation_hash
{
:cost => {
:presence => {
:message => "can't be blank"
}
}
}
end

attr_accessor :author
def author_attributes=(attributes); end

attr_accessor :comments, :comment_ids
def comments_attributes=(attributes); end

attr_accessor :tags
def tags_attributes=(attributes); end
end

42 changes: 42 additions & 0 deletions test/action_view/test_helper.rb
@@ -0,0 +1,42 @@
require 'base_helper'
require 'action_view'
require 'action_view/models'
require 'client_side_validations/action_view'

module ActionController
class Base
include ActionDispatch::Routing::RouteSet.new.url_helpers
end
end

module ActionViewTestSetup
include ::ClientSideValidations::ActionView::Helpers::FormHelper
include ::ClientSideValidations::ActionView::Helpers::FormTagHelper

def form_for(*)
@output_buffer = super
end

Routes = ActionDispatch::Routing::RouteSet.new
Routes.draw do
resources :posts
end

def _routes
Routes
end

include Routes.url_helpers

def setup
super

@post = Post.new
@post.persisted = true
def @post.id; 123; end
def @post.id_before_type_cast; 123; end
def @post.to_param; '123'; end
end

end

18 changes: 18 additions & 0 deletions test/base_helper.rb
@@ -0,0 +1,18 @@
require 'rubygems'
require 'bundler'
Bundler.setup
require 'test/unit'
require 'mocha'
require 'ruby-debug'

module Rails
def self.env
self
end

def self.development?
false
end
end

module ClientSideValidations; end
3 changes: 3 additions & 0 deletions test/javascript/config.ru
@@ -0,0 +1,3 @@
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
require 'server'
run Sinatra::Application

0 comments on commit 5b756d4

Please sign in to comment.