Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better:

Register complate's middleware and use Response#complate for rendering:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, adopted (with a slight tweak) in 0d4389a.


```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 <article>
<h1>{title}</h1>
<p>lorem ipsum dolor sit amet</p>
</article>;
}

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that URL is not correct - need to discuss with @moonglum

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

faucet-pipeline.org is the correct URL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed in 0d4389a.

[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).