2.0.5 • Published 8 years ago

rotu v2.0.5

Weekly downloads
3
License
CC0-1.0
Repository
github
Last release
8 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

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.8

8 years ago

1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago