rotu v2.0.5
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);
};
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago