Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules
/.eslintcache
/example/dist

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

... and yet you included example/dist/bundle.js - I assume that's unintentional?

Ah, I just noticed ba2c92c removes that file again - I wouldn't want to see it in the history at all though. (Don't worry about it for now; I'll probably rewrite some history anyway before merging this.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

exactly, and ok, i'm not that fan of rewriting the hist, but sure.

/package-lock.json
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# complate-express

Server-side rendered component based template-engine for express.

This library is based on [complate-stream](https://github.com/complate/complate-stream).

## Quick Start Guide

Install complate-express in your express application

```
npm install complate-express
```

```
const express = require('express')
const complate = require('complate-express')

const app = express();

// add complate middleware
app.use(complate('PATH_TO_COMPLATE_RENDERER_BUNDLE'))


app.get('/', (req, res) => {
// after adding the middleware, `res.complate` is available for rendering
res.complate('my-component', { config })
})
```

## API

#### complate(bundlePath: String, options: Object)

**@param bundlePath**: is a path to the complate renderer Module.
The module will not be cached if `app.enabled("view cache")` is false, like it is in dev-mode.

**@param options**: `{ cache = false }`

Options:

- cache: forces the given bundle to be cached if set to `true` (otherwise `app.enabled('view cache')` kicks in)
8 changes: 8 additions & 0 deletions example/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends:
- fnd
- plugin:react/recommended
plugins:
- react
settings:
react:
pragma: createElement
20 changes: 20 additions & 0 deletions example/faucet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const config = {
targetDir: "dist",
manifest: false,
bundles: [{
entryPoint: "./views/bundle.js",
target: "bundle.js",
format: "cjs",
moduleName: "render",
transpiler: {
features: ["es2015", "jsx"],
jsx: {
"pragma": "createElement"
}
}
}]
};

module.exports = {
js: config
};
20 changes: 20 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
const path = require("path");
const express = require("express");
const complate = require("complate-express");

const app = express();

// view cache is set by default to true in production
// app.set('view cache', true)

// just hand in the complate middleware, to register the complate
// rendering function. In dev-env the bundle is not cached, so that
// it can be updated between incoming requests.
app.use(complate(path.resolve(__dirname, "dist", "bundle.js")));

app.get("/", (req, res) => {
return res.complate("site-index", { title: "Hello World!" });
});

app.listen(5000);
Loading