-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for works with the same extends and modules syntax toge…
…ther with x-tag for easy migration
- Loading branch information
Damir
committed
Oct 13, 2022
1 parent
05582e6
commit d5f665e
Showing
6 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div><content></content></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div><content></content></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<head><title>Extend With Module Layout</title></head> | ||
<body> | ||
<main><block name="content"></block></main> | ||
<footer><block name="footer">footer content</block></footer> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<head><title>Extend Layout</title></head> | ||
<body> | ||
<main><block name="content"></block></main> | ||
<footer><block name="footer">footer content</block></footer> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'); | ||
const plugin = require('../src'); | ||
const posthtml = require('posthtml'); | ||
const clean = html => html.replace(/(\n|\t)/g, '').trim(); | ||
|
||
test('Must work with posthtml-extend syntax', async t => { | ||
const actual = `<extends src="layouts/extend.html"><block name="content">My Content</block></extends>`; | ||
const expected = `<html><head><title>Extend Layout</title></head><body><main>My Content</main><footer>footer content</footer></body></html>`; | ||
|
||
const html = await posthtml([plugin({root: './test/templates', tagName: 'extends', attribute: 'src', slotTagName: 'block'})]).process(actual).then(result => clean(result.html)); | ||
|
||
t.is(html, expected); | ||
}); | ||
|
||
test('Must work with posthtml-modules syntax', async t => { | ||
const actual = `<module href="components/module.html">My Module Content</module>`; | ||
const expected = `<div>My Module Content</div>`; | ||
|
||
const html = await posthtml([plugin({root: './test/templates', tagName: 'module', attribute: 'href', slotTagName: 'content'})]).process(actual).then(result => clean(result.html)); | ||
|
||
t.is(html, expected); | ||
}); | ||
|
||
test('Must work with posthtml-extend and posthtml-modules syntax together', async t => { | ||
const actual = `<extends src="layouts/extend-with-module.html"><block name="content"><module href="components/module-with-extend.html">My Module Content</module></block></extends>`; | ||
const expected = `<html><head><title>Extend With Module Layout</title></head><body><main><div>My Module Content</div></main><footer>footer content</footer></body></html>`; | ||
|
||
const html = await posthtml([plugin({root: './test/templates', tagNames: ['extends', 'module'], attributes: ['src', 'href'], slotTagName: 'block', fallbackSlotTagName: true})]).process(actual).then(result => clean(result.html)); | ||
|
||
t.is(html, expected); | ||
}); |