Skip to content

Commit

Permalink
Breaking change: the renderer doesn't export a template() anymore b…
Browse files Browse the repository at this point in the history
…ut the dom-engine `load()`
  • Loading branch information
Lcfvs committed Sep 13, 2021
1 parent 8874d34 commit 5453530
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2.0.0
* Breaking change: the renderer doesn't export a `template()` anymore but the dom-engine `load()`
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "anticore-server",
"version": "1.0.0",
"version": "2.0.0",
"description": "A low learning curve anticore server",
"type": "module",
"exports": {
Expand All @@ -15,7 +15,7 @@
},
"author": "Lcf.vs",
"dependencies": {
"@lcf.vs/dom-engine": "^5.3.2",
"@lcf.vs/dom-engine": "^5.4.0",
"fastify": "^3.20.2",
"fastify-compress": "^3.6.0",
"fastify-multipart": "^4.0.7",
Expand Down
24 changes: 14 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ const application = app({

#### src/templates/layout/layout.js
```js
import { template } from 'anticore-server/renderer.js'
import { load } from 'anticore-server/renderer.js'

// loads the ./template.html and associates the provided properties
export default await template(import.meta, {
export default await load(import.meta, {}, {
branding: 'anticore-server',
view: null // just to know which properties can be filled later, on every clone
})
Expand All @@ -87,9 +87,9 @@ export default await template(import.meta, {
#### src/templates/fragment/fragment.js
```js
import { template } from 'anticore-server/renderer.js'
import { load } from 'anticore-server/renderer.js'

export default await template(import.meta, {
export default await load(import.meta, {}, {
view: null
})
```
Expand All @@ -104,9 +104,9 @@ export default await template(import.meta, {
#### src/templates/error/error.js
```js
import { template } from 'anticore-server/renderer.js'
import { load } from 'anticore-server/renderer.js'

export default await template(import.meta, {
export default await load(import.meta, {}, {
name: null,
message: null
})
Expand All @@ -123,9 +123,9 @@ export default await template(import.meta, {
#### src/templates/views/home/home.js
```js
import { template } from 'anticore-server/renderer.js'
import { load } from 'anticore-server/renderer.js'

export default await template(import.meta, {
export default await load(import.meta, {}, {
class: 'home',
description: 'A homepage description',
title: 'A homepage title'
Expand All @@ -141,9 +141,9 @@ export default await template(import.meta, {
#### src/templates/sse/message/message.js
```js
import { template } from 'anticore-server/renderer.js'
import { load } from 'anticore-server/renderer.js'

export default await template(import.meta, {
export default await load(import.meta, {}, {
content: null
})
```
Expand Down Expand Up @@ -269,6 +269,10 @@ await serve(app)
See it in action into the [anticore](https://github.com/Lcfvs/anticore) [demo](https://glitch.com/edit/#!/anticore-demo?path=src%2Fserve.js%3A1%3A0)
## Changelog
[changelog](./changelog.md)
## License
[MIT](./license.md)
10 changes: 1 addition & 9 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const renderXHR = ({
}
}

export { serialize, source }
export { load, serialize, source }

export const sse = async ({ error }, template, data, errors) =>
eol(await serialize(renderEvent({ error }, template, data, errors)))
Expand All @@ -100,11 +100,3 @@ export const view = async ({
return serialize(method({ error, fragment, layout }, view, data, errors))
}

export const template = async ({ url }, { ...data } = {}) => {
const path = resolve(dirname(fileURLToPath(url)), './template.html')

return {
[source]: `${await readFile(path)}`,
...data
}
}

0 comments on commit 5453530

Please sign in to comment.