2.0.5 • Published 9 years ago

rotu v2.0.5

Weekly downloads
3
License
CC0-1.0
Repository
github
Last release
9 years ago

Rotu

Micro page routing for Pug.

v2.0

The Basics

// app.js
const Rotu = require("rotu");
const rotu = new Rotu();
$ npm install rotu
$ node app.js
Rotu running on port 8000

The above micro Node.js® application will respond to the request for http://localhost:8000 by looking in the current directory for a template named index.pug, compile the template and then serve the rendered html.

For example:
http://localhost:8000/home
routes to the ./home.pug template

http://localhost:8000/home/
routes to the ./home/index.pug template

http://localhost:8000/home/blog
routes to the ./home/blog.pug template

Configuration

const rotu = new Rotu(config) | object
An optional configuration object that can be passed as an argument to the Rotu constructor with following default values:

var config = {
    "route": "/",
    "routed": null,
    "root": ".",
    "data": null,
    "options": {
        "pretty": true
    },
    "error": null
};

config.root | string
The root path used to override the default which is the current working directory.

config.root = "./pages";

config.data | json
The first descendent of data must be the template name (without the . extension). This object requires an additional child object named locals containing the data to be bound in the template.

config.data = {
    "index": {
        "locals": {
            "pageTitle": "Welcome",
            "youAreUsingPug": true,
            "youAreUsingRotu": true
        }
    },
    "about": {
        "locals": {
            "pageTitle": "About Rotu"
        }
    }
};

config.options | object
The standard Pug configuration object.
ref: https://pugjs.org

config.options = {
    "pretty": true,
    "debug": true
};

config.error(error) | callback method
A callback that runs if an exception is thrown during routing or template compilation.

config.error = function(error) {
    response.end("There was a problem processing your template");
    console.log(error.message);
};
2.0.5

9 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.1.8

9 years ago

1.1.7

9 years ago

1.1.6

9 years ago

1.1.5

9 years ago

1.1.4

9 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago