From 34889d03e6ef21fe12293927c7d1c8e1a5e7062e Mon Sep 17 00:00:00 2001 From: FND Date: Thu, 23 Nov 2017 08:04:06 +0100 Subject: [PATCH] added documentation based on @mechanoid's efforts: https://github.com/complate/complate-express/pull/1 --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ce1c599 --- /dev/null +++ b/README.md @@ -0,0 +1,68 @@ +# complate-express + +[Express](http://expressjs.com) adaptor for [complate](https://complate) + + +Getting Started +--------------- + +Install complate-express in your Express application: + +``` +$ npm install complate-express +``` + +After registering complate's middleware, use `Response#complate` for rendering: + +```javascript +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: + +```jsx +import { createElement } from "complate-stream"; + +export function MyView({ title }) { + return
+

{title}

+

lorem ipsum dolor sit amet

+
; +} + +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](faucet.org) - see +[complate-sample-express](https://github.com/complate/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).