0.16.0 • Published 6 years ago

complate-express v0.16.0

Weekly downloads
29
License
Apache-2.0
Repository
github
Last release
6 years ago

complate-express

Express adaptor for complate

Getting Started

Install complate-express in your Express application:

$ npm install complate-express

Register complate's middleware, then use Response#complate for rendering:

let express = require("express");
let complate = require("complate-express");

let app = express();
// register complate middleware
app.use(complate("/path/to/views.js")));

app.get("/", (req, res) => {
    res.complate("MyView", { title: "Hello World" });
});

Views are typically generated from JSX modules:

import { createElement } from "complate-stream";

export function MyView({ title }) {
    return <article>
        <h1>{title}</h1>
        <p>lorem ipsum dolor sit amet</p>
    </article>;
}

// host API
export default (view, params, stream, fragment, callback) => {
    return renderer.renderView(view, params, stream, { fragment }, callback);
};

These JSX modules are then combined into a single views.js bundle, e.g. using faucet - see complate-sample-express for details.

API

Request#complate(viewName, params, options)

  • viewName identifies the view within the bundle
  • params is an object passed to the respective view macro
  • options is an optional object with the following members:
    • fragment, if true, indicates that an HTML fragment (omitting doctype and layout)
    • statusCode sets the HTTP status code (defaults to 200)
    • contentType sets the corresponding HTTP response header (defaults to "text/html")

If Express's view cache is disabled, the bundle will be reloaded for each requests (useful for development).

0.16.0

6 years ago

0.15.0

7 years ago

0.14.0

7 years ago

0.13.0

7 years ago

0.12.1

7 years ago

0.12.0

7 years ago

0.11.0

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.0

7 years ago