Uniform is a view model for CoffeeScript
I present to you a ViewController for the browser. A ViewController (in this case) is a class that describes the behaviour of an element and it's children. It goes well with jQuery but can use whatever you like.
Here's an example:
# Let's describe a contact form# The HTML templatetemplate: """<form><textarea></textarea><button>Send</button></form>"""# On initialise we want to add the form to the body: -> $'body'append@el# We cache some children to properties on this objectelements:msg: 'textarea'btn: 'button'# We delegate the submit event to @sendResponse()events:'': # This empty string means attach to thyself'submit': 'sendResponse'# Do the sending :):epreventDefault@btntext'Sending...'$post 'index.html'msg: @msg=>@msgval''@btntext'Send'# InitialisejQuery ->
You can also use your ViewControllers on elements already in the DOM like so:
# Or use on an existing elementjQuery -> el: $'#contact'
Uniform is best used in compiled CoffeeScript browser environments. Since Uniform is a CoffeeScript class it is easiest to extend and use it if your front end code is also CoffeeScript.
Use it how you like though.
You can simply use the JS found in the dist folder of the Uniform git repo https://github.com/DrPheltRight/uniform
Clone the repository https://github.com/DrPheltRight/uniform.git and then run "cake build" to make a fresh copy of Uniform.