forked from omarshammas/jquery.formance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned, and added some documentation
- Loading branch information
1 parent
dda9e9c
commit d51cceb
Showing
30 changed files
with
2,022 additions
and
1,907 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
*.DS_Store | ||
lib/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,50 @@ | ||
{print} = require 'util' | ||
{spawn} = require 'child_process' | ||
|
||
task 'build', 'Build lib/ from src/', -> | ||
coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src'] | ||
coffee.stderr.on 'data', (data) -> | ||
process.stderr.write data.toString() | ||
coffee.stdout.on 'data', (data) -> | ||
print data.toString() | ||
coffee.on 'exit', (code) -> | ||
callback?() if code is 0 | ||
# Adapted from http://kgn.github.io/wheel.coffee/Cakefile.html | ||
|
||
{spawn, exec} = require 'child_process' | ||
{log, error} = console; print = log | ||
fs = require 'fs' | ||
|
||
run = (name, args...) -> | ||
proc = spawn(name, args) | ||
proc.stdout.on 'data', (buffer) -> print buffer if buffer = buffer.toString().trim() | ||
proc.stderr.on 'data', (buffer) -> error buffer if buffer = buffer.toString().trim() | ||
proc.on 'exit', (status) -> process.exit(1) if status isnt 0 | ||
|
||
shell = (cmds, callback) -> | ||
cmds = [cmds] if Object::toString.apply(cmds) isnt '[object Array]' | ||
exec cmds.join(' && '), (err, stdout, stderr) -> | ||
print trimStdout if trimStdout = stdout.trim() | ||
error stderr.trim() if err | ||
callback() if callback | ||
|
||
|
||
# task 'coffee', 'Build lib/ from src/', -> | ||
# run 'coffee', '-co', 'lib', 'src' | ||
|
||
task 'coffee', 'Builds lib/jquery.formance.js from src/', -> | ||
run 'coffee', '-j', 'lib/jquery.formance.js', '-c', 'src' | ||
|
||
task 'watch', 'Watch src/ for changes', -> | ||
coffee = spawn 'coffee', ['-w', '-c', '-o', 'lib', 'src'] | ||
coffee.stderr.on 'data', (data) -> | ||
process.stderr.write data.toString() | ||
coffee.stdout.on 'data', (data) -> | ||
print data.toString() | ||
run 'coffee', '-wj', 'lib/jquery.formance.js', '-c', 'src' | ||
|
||
task 'test', 'Run tests', -> | ||
mocha = spawn 'mocha', ['--compilers', 'coffee:coffee-script'] | ||
mocha.stderr.on 'data', (data) -> | ||
process.stderr.write data.toString() | ||
mocha.stdout.on 'data', (data) -> | ||
print data.toString() | ||
run 'mocha', '--recursive', '--compilers', 'coffee:coffee-script', '-c' | ||
|
||
task 'minify', 'Minifies any js file in the lib/ folder.', -> | ||
dir = 'lib' | ||
fs.readdir dir, (err, files) -> | ||
throw err if err | ||
for file in files | ||
continue if not /\.js$/.test(file) or /\.min\.js$/.test(file) | ||
|
||
nameparts = file.split '.' | ||
nameparts[nameparts.length-1] = 'min' | ||
nameparts.push 'js' | ||
newname = nameparts.join '.' | ||
print "minify: #{file} -> #{newname}" | ||
|
||
shell "uglifyjs --output #{dir}/#{newname} #{dir}/#{file}" | ||
|
||
task 'build', 'Builds lib/jquery.formance.js and minifies it.', -> | ||
invoke 'coffee' | ||
invoke 'minify' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Copyright (c) 2012 Stripe ([email protected]) | ||
Copyright (c) 2013 Omar Shammas ([email protected]) | ||
and Stripe ([email protected]) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
# jQuery.formance | ||
|
||
A general purpose library for formatting and validating form fields, based on Stripe's jQuery.payment library. | ||
|
||
## Getting Started | ||
|
||
## Installation | ||
Coming soon, in the mean time checkout the example. | ||
|
||
``` | ||
npm install jquery | ||
npm install mocha | ||
npm install coffeescript | ||
npm install https://github.com/omarshammas/jquery.formance.git | ||
``` | ||
## Example | ||
|
||
Make sure your node path is setup correctly. | ||
Look in ```./example/index.html``` | ||
|
||
``` | ||
export NODE_PATH=/usr/local/lib/node_modules | ||
``` | ||
## Adding A New Field | ||
|
||
## Cake | ||
To can create your own formatters and validators, simply add a new file under ```src/zfields/``` with the name of the field type. It is probably best to look at how the other fields were written before starting your own. You can even use them as a base. | ||
|
||
Cake is the equivalent of make and rake for coffeescript, and accepts the following commands. | ||
It is important to write tests for the new field to ensure it works as expected. Each field should have a corresponding file under ```test/fields/```. | ||
|
||
## Set up Project Locally | ||
|
||
### Installation | ||
|
||
``` | ||
cake build | ||
cake watch | ||
cake test | ||
npm install -g jquery | ||
npm install -g mocha | ||
npm install -g coffee-script | ||
npm install -g uglify-js | ||
npm install https://github.com/omarshammas/jquery.formance.git | ||
``` | ||
|
||
## Compiling | ||
### Cake | ||
|
||
You can compile the coffeescript files into a single file (formance.js) using | ||
Cake is the equivalent of make and rake for coffeescript, and provides the following tasks. | ||
|
||
``` | ||
coffee --join lib/formance.js --compile src/* | ||
cake coffee # Builds lib/jquery.formance.js from src/ | ||
cake watch # Watch src/ for changes | ||
cake test # Runs all tests | ||
cake minify # Minifies any js files in lib/ | ||
cake build # Builds lib/jquery.formance.js and minifies it | ||
``` | ||
|
||
### Side Notes | ||
|
||
## Side Notes | ||
|
||
src/fields was renamed to src/zfields to ensure that jquery.formance.coffee was compiled first otherwise the fields wouldn't be able to access $.fn.formance. | ||
|
||
```src/fields``` was renamed to ```src/zfields``` to ensure that jquery.formance.coffee is compiled first when concatenating all fields otherwise the fields wouldn't be able to access $.fn.formance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.