organic-express-staticpages

0.0.3 • Public • Published

organic-express-staticpages

Organelle for mounting and rendering each of expressjs views/templates within directory recursively.

dna

{
  "source": "node_modules/organic-express-staticpages",
  "reactOn": "ExpressServer",
  "pattern": "/**/*.jade",
  "path": "path/relative/to/cwd/pages",
  "exclude": undefined,
  "log": false,
  "emitReady": undefined
}

reactOn property

Should be either ExpressServer chemical with expected structure or array of chemicals where the first one is mapped as ExpressServer chemical.

path property

Directory which will be 'glob'-ed with pattern and each file will be mounted as get handler having this form:

app.get("path/to/page", function(req, res){
  res.render("path/to/page")
})

exclude property

Every file having exclude contents in its path will be ignored and not mounted. Support array or string input. Example:

having {
  exclude: "layouts"
}

will ignore files having `layouts` in its file path

haveing {
  exclude: ["layouts", "partials"]
}

will ignore files having `layouts` and/or `partials` in its file path

emitReady property

Once all pages are mounted and if value is present will be emitted as type of chemical

example usage

Given directory tree

/-context/pages
 |- index.jade
 |- about.jade
 |- examples
  |- index.jade
  |- example1.jade
  |- example2.jade

Requests to the server render static context/pages templates:

  • GET / -> /context/pages/index.jade
  • GET /about -> /context/pages/about.jade
  • GET /examples -> /context/pages/examples/index.jade
  • GET /examples/example1.jade -> /context/pages/examples/example1.jade
  • GET /examples/example2.jade -> /context/pages/examples/example2.jade

using expressjs app setup

var jade = require("jade")
var express = require("express")

var app = express()
app.set("views", path.join(process.cwd(), "context/pages"))
app.set("view engine", "jade")
app.engine('jade', jade.__express);

// ...

// construct organelle's container plasma
var plasma = new (require("organic-plasma"))()

// construct organelle with dna
require("organic-express-staticpages")(plasma, {
  "reactOn": "ExpressServer",
  "path": "context/pages",
  "pattern": "**/*.jade",
  "log": true
})

// trigger organelle's reaction
plasma.emit({type: "ExpressServer", data: app})

// ...

Readme

Keywords

none

Package Sidebar

Install

npm i organic-express-staticpages

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • outbounder