index.coffee | |
|---|---|
CreamerA flatiron http plugin that adds install
usage
require coffeecup http://github.com/gradus/coffeecup | cc = require 'coffeecup'
hardcode = require 'coffeecup-helpers'
fs = require 'fs'
wrench = require 'wrench' |
| broadway plug attach method Plugin Options | exports.attach = (options={}) ->
self = this |
load views by view directoryby passing the viewDir as an option creamer will load your views | registeredViews = {}
if options.views?
items = wrench.readdirSyncRecursive(options.views)
for view in items
if view.match /(.js|.coffee)/
fn = require options.views + '/' + view
name = view.split('.').shift()
registeredViews[name] = fn |
load controllers by controller directoryby passing the controllers as an option creamer will load your controllers | if options.controllers?
items = wrench.readdirSyncRecursive(options.controllers)
for controller in items
if controller.match /(.js|.coffee)/
fn = require options.controllers + '/' + controller |
| mount controllers | @router.mount fn |
app.bind(page, data) | @bind = (page, data) ->
page = registeredViews[page] if typeof page is 'string'
if options.layout? and typeof page is 'function'
hardcode.content = page
cc.render(options.layout, data, { hardcode, locals: true })
else if typeof page is 'function'
cc.render(page, data, { hardcode, locals: true})
else
'<p>Not Found</p>' |
app.registerHelper(name, fn) | @registerHelper = (name, fn) ->
valid = cc.compile(fn, {hardcode, locals: true})
hardcode[name] = fn if typeof fn is 'function' |
app.registerView(name, fn) | @registerView = (name, fn) ->
valid = cc.compile(fn, {hardcode, locals: true})
registeredViews[name] = fn |
| if flatiron router exists, then attach creamers bind function | @router.attach ( -> @bind = self.bind ) if @router?.attach? |
| init plugin method | exports.init = (done) -> done()
|