faraday
v1.12.0
Published
A lightweight MVC framework
Downloads
92
Readme
Faraday
A lightweight MVC framework.
To begin, run the following the in the root of your app:
Now you can access faraday throught the folders models, views, and controllers.
The Server
To run the server, run
If you get this:
Run this:
This gives develop executable permission. To get develop to work, you may need to install the ruby gem called sass.
Models and Modooses
I have abandoned the old models folder in favor of the modooses model. You can still use models, but they are deprecated and will be removed in subsequent versions.
A modoose is a humorous malamoneau of "model" and "mongoose". (I can hear you laughing). Each modoose corresponds to a mongoose model in a coffee file in the modooses folder. To create a modoose called Foo, save the file ./modooses/Foo.cofffee:
Faraday will create this model in the database and you can access it asynchronously as:
Views
In your views folder, put files the form filename.html.underscorecoffee. These will be compiled as underscore.js (HTML) templates. You can invoke them as require('faraday').view.filename(scope). The scope object will become the scope in the underscore.js template. That way you can pass variables and data for the template to render.
Controllers
In your controller folder, put coffeescript files. If you create a file ./controllers/foo.coffee with the following:
Then navigate to localhost:3000/foo, myRequestHandler will be invoked with two arguments: the node.js request object and response object. I commonly require views in a controller and invoke some corresponding view.
Faraday will map directories in the controllers folder to path components in the url. For example, if you save the aforementioned coffescript as ./controllers/several/nested/directories/foo.coffee myRequestHandler will be invoked when you navigate to localhost:3000/several/nested/directories/foo. You can also create path components by nesting the routing object:
You can inspect how this works by reading node_modules/faraday/route.coffee.