Skip to content

Commit

Permalink
Allow passing a separate data file into the main template (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop authored May 7, 2020
1 parent e272e1b commit ec005ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ const scriptFile = buildJs({

💡 The `debug` option will ensure the bundle contains a sourcemap

💡 If `fakeDataPath` is not provided, make sure to provide a separate `dataFile` to the [main template](#templates).

### `buildCss(opts = {})`
Returns a PostCSS bundle (Promise)

Expand All @@ -109,7 +111,7 @@ const styleFile = buildCss({
***

## Templates
Templates use stream-templates to interpolate streams, promises and strings into a common template without the need to buffer them first.
Templates use [`stream-template`](https://github.com/almost/stream-template) to interpolate streams, promises and strings into a common template without the need to buffer them first.

### `mainTemplate(opts = {})`
Returns a streamTemplate (Readable Stream)
Expand All @@ -127,6 +129,7 @@ const outputFile = mainTemplate({
favicon: 'URI', (String)
title: 'Title', (String)
styles: styleFile, (Readable Stream)
data: dataFile, (Readable Stream)
script: scriptFile, (Promise)
headerLogoUrl: 'https://github.com/somewhere', (String)
headerLogoTitle: 'Logo title', (String)
Expand All @@ -140,6 +143,8 @@ const outputFile = mainTemplate({
})
```

💡 `opts.data` can be provided to place the JSON output of the analysis into its own script tag. When not provided, analysis data should be bundled in the `scriptFile` by the user.

***

## Styles
Expand Down
3 changes: 3 additions & 0 deletions templates/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const main = (opts = {}) => streamTemplate`
${header(opts)}
${opts.body}
${askTray(opts)}
${opts.data ? streamTemplate`
<script type="application/json" id="clinic-data">${opts.data}</script>
` : ''}
<script>${opts.script}</script>
</body>
</html>
Expand Down

0 comments on commit ec005ec

Please sign in to comment.