github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

rpbertp13 / kiwi

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 133
    • 5
  • Source
  • Commits
  • Network (5)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Kiwi is an MVC framework built on top of jQuery that makes it dead easy to write tidy, short javascript — Read more

  cancel

http://robertothais.com/kiwi_docs

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

added the possibility of pre-processing params on a per request basis 
before final serialization 
rpbertp13 (author)
Tue Nov 17 17:01:36 -0800 2009
commit  f033fce043e6d1e326874adc42aacdc777e6678a
tree    d8caef58e8be748b9d29237d8fb175df2c1bfbaf
parent  a304eff94419ef73559d127f3bd9222c13d4cf7a
kiwi /
name age
history
message
file LICENSE Tue Nov 10 14:19:44 -0800 2009 Added MIT License [rpbertp13]
file README.rdoc Tue Nov 17 00:32:21 -0800 2009 fixed typo in last commit, added a snippet abou... [rpbertp13]
directory docs/ Wed Jul 15 08:26:41 -0700 2009 updated docs [rpbertp13]
directory lib/ Tue Nov 17 17:01:36 -0800 2009 added the possibility of pre-processing params ... [rpbertp13]
README.rdoc

Kiwi

Kiwi likes HTTP. Kiwi likes REST. Kiwi doesn’t like it when you have to do tedious things like writing down url’s to get data from your server.

Models map to Resources

We can define a couple of models

 $m('Post', {
     resource: 'posts',
     has: {'comments':'Comment'}
   })

 $m('Comment', {resource: 'comments'})

So now we can say, in a controller

  $m.Post.find('all', this.publish)

or

  $m.Post.find(1).comments.find('all', this.publish)

or perhaps

  $m.Post.find(1).comments.find(12).destroy(this.publish)

The http requests that get fired are, respectively:

  http://domain.com/posts (GET)
  http://domain.com/posts/1/comments (GET)
  http://domain.com/posts/1/comments/12 (DELETE)

HTTP error codes rule

If our server returns a different status code for each server error (or error class), we can easily react differently in the front end:

In a view:

  $v('CommentList', {
    listeners: {
      '.more click': {action: 'Comments.get', on_error: 'errors'}
    },
    errors: {
      404: function(){
        alert("Sorry, not found!")
      },
      403: function(status_code, message){
        alert(message)
      }
    }
  })

We can also define a catch all error handler in case none of them are defined in our view:

  $k.options.global_error_handler.base = function(){
    alert("You got some random error!")
  }

Concise and flexible parameter passing

In a controller

  $m.Post.create(this.params, this.publish)

This will automatically serialize the parameters in the form of the calling view and send it over the wire. Currently this.params assumes that you have only one form per view.

If you need to set a prefix to your parameters, simply set:

  this.options.param_prefix = 'post'

before calling the model.

You can also set as the parameter argument a jQuery object representing a form, or a function that returns either jQuery-ized form, an arbitrary object you want to serialize, or a string.

Please fork if you like this

Kiwi is good for this and other things. It can be improved in many ways, and I would love some help :)

Check out the official docs at:

robertothais.com/kiwi_docs

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server