Skip to content

Commit 3c9642c

Browse files
committed
docs(example): managed the example with remark-usage
1 parent edb3cc2 commit 3c9642c

File tree

7 files changed

+169
-35
lines changed

7 files changed

+169
-35
lines changed

.babelrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"presets": [["@travi", {"react": true}]]
3-
}
1+
{"presets": [["@travi", {"react": true}]]}

.eslintrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ overrides:
1010
import/no-extraneous-dependencies:
1111
- error
1212
- devDependencies: true
13+
react/prop-types: off
14+
no-undef: off
1315
- files:
1416
- src/**/*.js
1517
- test/unit/**/*-test.js

.remarkrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ exports.settings = {
66
incrementListMarker: false
77
};
88

9-
exports.plugins = ['remark-preset-lint-travi', [require('remark-toc'), {tight: true}]];
9+
exports.plugins = [
10+
'remark-preset-lint-travi',
11+
[require('remark-toc'), {tight: true}],
12+
['remark-usage', {heading: 'example'}]
13+
];

README.md

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# hapi-react-router
22

33
[hapi](https://hapi.dev/) route to delegate routing for html content to
4-
[react-router](https://github.com/ReactTraining/react-router/tree/v3/docs)
4+
[react-router v3](https://github.com/ReactTraining/react-router/tree/v3/docs)
55

66
[![Build Status](https://img.shields.io/travis/travi/hapi-react-router.svg?style=flat&branch=master)](https://travis-ci.org/travi/hapi-react-router)
77
[![Codecov](https://img.shields.io/codecov/c/github/travi/hapi-react-router.svg)](https://codecov.io/github/travi/hapi-react-router)
@@ -12,6 +12,9 @@
1212
* [Installation](#installation)
1313
* [Register with your Hapi v18+ server](#register-with-your-hapi-v18-server)
1414
* [Example](#example)
15+
* [Dependencies:](#dependencies)
16+
* [Register with the Hapi server](#register-with-the-hapi-server)
17+
* [Optional custom renderer that passes blankie (optional to provide yourself) nonces as a prop](#optional-custom-renderer-that-passes-blankie-optional-to-provide-yourself-nonces-as-a-prop)
1518
* [Dependencies for you to provide](#dependencies-for-you-to-provide)
1619
* [Contribution](#contribution)
1720
* [Install dependencies](#install-dependencies)
@@ -48,37 +51,54 @@ for the current route.
4851

4952
### Example
5053

51-
```js
54+
#### Dependencies:
55+
56+
```javascript
57+
import React from 'react';
58+
import {IndexRoute, Route} from 'react-router';
59+
import {createStore} from 'redux';
60+
import {Provider} from 'react-redux';
61+
```
62+
63+
#### Register with the Hapi server
64+
65+
```javascript
5266
export default {
53-
server: {port: process.env.PORT},
54-
register: {
55-
plugins: [
56-
{plugin: '@travi/hapi-html-request-router'},
57-
{
58-
plugin: '@travi/hapi-react-router',
59-
options: {
60-
respond: (reply, {renderedContent}) => {
61-
reply.view('layout', {renderedContent});
62-
},
63-
routes: (
64-
<Route path="/" component={Wrap}>
65-
<IndexRoute component={Index}/>
66-
<Route path="/foo" component={Foo}/>
67-
<Route path="/bar" component={Bar}/>
68-
<Route path="*" component={NotFound}/>
69-
</Route>
70-
),
71-
Root: ({store, children}) => (
72-
<Provider store={store}>
73-
{children}
74-
</Provider>
75-
),
76-
configureStore: ({session}) => createStore(reducer, composeMiddlewares(session))
77-
}
78-
}
79-
]
80-
}
81-
}
67+
server: {port: process.env.PORT},
68+
register: {
69+
plugins: [
70+
{plugin: '@travi/hapi-html-request-router'},
71+
{
72+
plugin: '@travi/hapi-react-router',
73+
options: {
74+
respond: (reply, {renderedContent}) => {
75+
reply.view('layout', {renderedContent});
76+
},
77+
routes: (
78+
<Route path="/" component={Wrap}>
79+
<IndexRoute component={Index} />
80+
<Route path="/foo" component={Foo} />
81+
<Route path="/bar" component={Bar} />
82+
<Route path="*" component={NotFound} />
83+
</Route>
84+
),
85+
Root: ({store, children}) => (
86+
<Provider store={store}>
87+
{children}
88+
</Provider>
89+
),
90+
configureStore: ({session}) => createStore(reducer, composeMiddlewares(session)),
91+
```
92+
93+
##### Optional custom renderer that passes blankie (optional to provide yourself) nonces as a prop
94+
95+
```javascript
96+
render: (defaultRender, request) => defaultRender({nonces: request.plugins.blankie.nonces})
97+
}
98+
}
99+
]
100+
}
101+
};
82102
```
83103

84104
### Dependencies for you to provide

example/index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// #### Dependencies:
2+
import React from 'react';
3+
import {IndexRoute, Route} from 'react-router';
4+
import {createStore} from 'redux';
5+
import {Provider} from 'react-redux';
6+
7+
// #### Register with the Hapi server
8+
9+
// remark-usage-ignore-next 5
10+
const Wrap = () => null;
11+
const Index = () => null;
12+
const Foo = () => null;
13+
const Bar = () => null;
14+
const NotFound = () => null;
15+
16+
export default {
17+
server: {port: process.env.PORT},
18+
register: {
19+
plugins: [
20+
{plugin: '@travi/hapi-html-request-router'},
21+
{
22+
plugin: '@travi/hapi-react-router',
23+
options: {
24+
respond: (reply, {renderedContent}) => {
25+
reply.view('layout', {renderedContent});
26+
},
27+
routes: (
28+
<Route path="/" component={Wrap}>
29+
<IndexRoute component={Index} />
30+
<Route path="/foo" component={Foo} />
31+
<Route path="/bar" component={Bar} />
32+
<Route path="*" component={NotFound} />
33+
</Route>
34+
),
35+
Root: ({store, children}) => (
36+
<Provider store={store}>
37+
{children}
38+
</Provider>
39+
),
40+
configureStore: ({session}) => createStore(reducer, composeMiddlewares(session)),
41+
42+
// ##### Optional custom renderer that passes blankie (optional to provide yourself) nonces as a prop
43+
render: (defaultRender, request) => ({html: defaultRender({nonces: request.plugins.blankie.nonces})})
44+
}
45+
}
46+
]
47+
}
48+
};

package-lock.json

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"remark-cli": "^7.0.1",
8282
"remark-preset-lint-travi": "^1.3.0",
8383
"remark-toc": "^7.0.0",
84+
"remark-usage": "^7.0.1",
8485
"rollup": "^1.20.2",
8586
"rollup-plugin-babel": "^4.3.3",
8687
"sinon": "^9.0.0",

0 commit comments

Comments
 (0)