Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/complate/complate-express
complate integration for Express
https://github.com/complate/complate-express
Last synced: 3 days ago
JSON representation
complate integration for Express
- Host: GitHub
- URL: https://github.com/complate/complate-express
- Owner: complate
- Created: 2017-07-22T16:04:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-30T11:28:46.000Z (over 6 years ago)
- Last Synced: 2024-11-06T05:07:47.560Z (about 2 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# complate-express
[Express](http://expressjs.com) adaptor for [complate](https://complate)
Getting Started
---------------Install complate-express in your Express application:
```
$ npm install complate-express
```Register complate's middleware, then 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
;
}// 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](https://faucet-pipeline.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).