0.3.4 • Published 10 years ago

rode v0.3.4

Weekly downloads
188
License
-
Repository
github
Last release
10 years ago

rode.js

Packet-Oriented Framework for ES6 and Express.

##Table of Contents:

ECMAScript 6

rode.js framework is a stable way to use ES6 today. ES6 support is provided by traceur, es6-shim and es6-module-loader.

rode.js is based on Express, but we not rewrite it, you can still using all the features of Express.

Getting started

Install rode.js globally and generate a new project:

# npm install -g rode
$ rode new --view ejs --css less --sessions myProject

Install project dependencies:

$ npm install

Start the server:

$ node app

Usage of rode new:

Usage: rode new [options] [dir]

Options:

  -h, --help          output usage information
  -V, --version       output the version number
  -v, --view          add view engine support (jade|ejs|hogan|soy) (defaults to jade)
  -c, --css           add stylesheet support (less|stylus|css) (defaults to plain css)

Packages

A package (or bundle) is a component of your application with its own MVC.

You can simply create a new package with the command:

$ rode generate PackageName

Usage: rode generate package <package>

Options:

  -h, --help   output usage information
  -r, --rest   config rest api for this package
  -f, --force  force on existing package

Models

In a model you should add all your business logic:

import { Model } from 'rode/loader';

export class MyModel extends Model {

  /**
   * Sample method, converts a string to upper case
   */
  sampleMethod(str) {
    return str.toUpperCase();
  }

}

You can generate a Model myModel for a package User with the command:

$ rode generate User:model myModel

Controllers

Controllers and Routes works together to facilitate the routing of the application.

A controller looks like:

export class HelloController {

  /**
   * sayHello Action
   */
  sayHello(req, res) {
    res.render('index', {
      title: 'Hello World!'
    });
  }

}

You can generate a Controller myController for a package User with the command:

$ rode generate User:controller myController

Routes

A route for the above controller looks like:

import { Router } from 'rode/loader';
var router = new Router();

/**
 * [GET] /
 * Calls HelloController.sayHello
 */
router.add({
  controller: 'Hello', // defaults 'Main'
  pattern: '/hello',
  action: 'sayHello',
  method: 'GET' // defaults 'GET'
});

export {router};

Middleware on Routes

Here's an example of how to define a middleware on routes:

export class UserController {
  showPrivateData() {
    return [
      (req, res, next) => {
        // Check permissions
        next();
      },
      (req, res) => {
        // Show Private Data
      }
    ];
  }
}

Restful APIs

Make a Restful API can not be more easy.

Create your REST package with the command:

$ rode generate package PackageName --rest

Or add router.restApi = '/api/products'; on the routes.js of any package.

Now you should create methods on your RestController.js following simple naming conventions.

Here are some examples:

// [GET] /api/products
get(req, res) { ... }

// [POST] /api/products
post(req, res) { ... }

// [GET] /api/products/sponsored
getSponsored(req, res) { ... }

// [PUT] /api/products/sponsored
putSponsored(req, res) { ... }

// [POST] /api/products/sponsored/today
postSponsoredToday(req, res) { ... }

// [GET] /api/products/:id
getById(req, res) { ... }

// [POST] /api/products/:id
postById(req, res) { ... }

// [DELETE] /api/products/:id
deleteById(req, res) { ... }

// [GET] /api/products/:id/comments
getByIdComments(req, res) { ... }

// [PUT] /api/products/:id/comments/:id2
putByIdCommentsById(req, res) { ... }

You can create as many combinations as you like. Remember that each package can have its own RestController.js

Templates engines

rode.js supports all this templates engines:

Tests

You can run the test with the command:

$ grunt test

License

MIT

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.12

10 years ago

0.2.11

10 years ago

0.2.10

10 years ago

0.2.9

10 years ago

0.2.8

10 years ago

0.2.7

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.22

10 years ago

0.1.21

10 years ago

0.1.20

10 years ago

0.1.19

10 years ago

0.1.18

10 years ago

0.1.17

10 years ago

0.1.16

10 years ago

0.1.15

10 years ago

0.1.14

10 years ago

0.1.13

10 years ago

0.1.12

10 years ago

0.1.11

10 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago