Costa
Built with CoffeeClasskit & FlowCoffee. Inspired by Rails. Is kept tiny to be fast as fire.
How can it look like
Controller
Post = require '../models/post'parse_params = require '../lib/parse_params' module.exports = './application_controller' @extendsWithProto @beforeFilter 'authenticate'only: 'new''create''edit''destroy' @beforeFilter 'findItem'only: 'show''edit''update''destroy' # actions : -> params = @searchParams Postsearch params@handleErrors posts = for item in items if item then itemexportFor 'api' else item @render posts: postsparams: params : -> @render post: : -> item = @itemParams item.account_id = @reqaccountid itemsave if err if itemerrorshasAny @resformat : -> @status422json itemexportFor 'api' # unprocessable_entity : -> @flash 'error'itemerrorsfirst @redirect '/posts/new' else @nexterr else url = "/posts/" @resformat : -> @status201set'Location'urljson itemexportFor 'api' # created : -> @flash 'Post created' @redirect url : -> @render post: @itemexportFor 'api' : -> @render post: @itemexportFor 'api' : -> item = @itemupdate @itemParams setImmediate => if err if itemerrorshasAny @resformat : -> @status422json itemexportFor 'api' # unprocessable_entity : -> @flash 'error'itemerrorsfirst @redirect "/posts//edit" else @nexterr else @resformat : -> if @reqquery_response? || @reqbody_response? @json post: itemexportFor 'api' else @status204end # no_content : -> @flash 'notice''Post saved' @redirect "/posts//edit" : -> @itemdestroy @handleErrors => @resformat : -> @status204end # no_content : -> @flash 'Post deleted' @redirect '/posts' # filters : Postfind @reqparamsid@handleErrors @item = item callback # strong params : -> result = @params PostexportedAttrs... result.image = image if image = @fileParam 'image' result : -> str: @reqquerystr
And now just call PostsController.dispatch(action, req, res, next)
the way you like with action
one of index, new, create, show, edit, update, destroy
.
Model
module.exports = './base_record' @extendsWithProto @include require './concerns/with_image' @exportAttrs 'author_id' 'title' 'content' 'is_published' 'tags' @validatesPresenceOf 'author_id''title''content' @beforeSave 'refreshTags' : some_tag_parserparse @content return callback err if err @tags = tags callback
More documentation in tests & source
License
MIT