Skip to content

Commit

Permalink
Fix tests and README, pass data
Browse files Browse the repository at this point in the history
  • Loading branch information
backflip committed Sep 25, 2019
1 parent 186b63d commit 69a7500
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ See [./test](./test).
}
```


2. Create examplary `template.htl`:

```html
Expand All @@ -35,15 +34,9 @@ See [./test](./test).
3. Import and run compiled template in your JavaScript:

```js
import template from "./template.htl";

(async () => {
const html = await template({
title: "HTL"
});
import html from "./template.htl?{\"data\":{\"title\":\"Hello\"}}";

document.body.insertAdjacentHTML("beforeend", html);
})();
document.body.insertAdjacentHTML("beforeend", html);
```

## Advanced
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = async function(source) {
model: "default",
useDir: null,
transformSource: null,
transformCompiled: null
transformCompiled: null,
data: {}
},
options,
query
Expand Down Expand Up @@ -54,7 +55,7 @@ module.exports = async function(source) {

// Run
const template = eval(compiledCode);
const html = await template({});
const html = await template(settings.data);

return `module.exports = \`${html}\``;
};
10 changes: 2 additions & 8 deletions test/entry.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import template from "./template.htl";
import html from "./template.htl?{\"data\":{\"title\":\"Hello\"}}";

(async () => {
const html = await template({
title: "HTL"
});

document.body.insertAdjacentHTML("beforeend", html);
})();
document.body.insertAdjacentHTML("beforeend", html);
8 changes: 1 addition & 7 deletions test/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ module.exports = {
{
test: /\.htl$/,
use: {
loader: path.resolve("./index.js"),
options: {
globalName: "htl"
}
loader: path.resolve("./index.js")
}
}
]
},
node: {
fs: "empty"
}
};

0 comments on commit 69a7500

Please sign in to comment.