@maizzle/framework 3.7.3 → 4.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/nodejs.yml +0 -1
- package/package.json +15 -13
- package/src/commands/build.js +32 -0
- package/src/commands/serve.js +139 -0
- package/src/functions/plaintext.js +5 -0
- package/src/functions/render.js +5 -0
- package/src/generators/output/to-disk.js +208 -167
- package/src/generators/output/to-string.js +5 -2
- package/src/generators/plaintext.js +49 -52
- package/src/generators/posthtml.js +61 -60
- package/src/generators/tailwindcss.js +114 -84
- package/src/index.js +13 -163
- package/src/transformers/{attribute-to-style.js → attributeToStyle.js} +0 -0
- package/src/transformers/baseUrl.js +45 -0
- package/src/transformers/{extra-attributes.js → extraAttributes.js} +0 -0
- package/src/transformers/index.js +57 -57
- package/src/transformers/{inline.js → inlineCss.js} +0 -0
- package/src/transformers/{posthtml-mso.js → posthtmlMso.js} +0 -0
- package/src/transformers/{prevent-widows.js → preventWidows.js} +0 -0
- package/src/transformers/{remove-attributes.js → removeAttributes.js} +1 -1
- package/src/transformers/{remove-inline-bgcolor.js → removeInlineBackgroundColor.js} +0 -0
- package/src/transformers/{remove-inline-sizes.js → removeInlineSizes.js} +0 -0
- package/src/transformers/{remove-unused-css.js → removeUnusedCss.js} +0 -0
- package/src/transformers/{replace-strings.js → replaceStrings.js} +0 -0
- package/src/transformers/{safe-class-names.js → safeClassNames.js} +8 -2
- package/src/transformers/{six-hex.js → sixHex.js} +0 -0
- package/src/transformers/transform.js +4 -6
- package/src/transformers/{url-params.js → urlParameters.js} +0 -0
- package/src/utils/helpers.js +2 -8
- package/test/expected/transformers/base-image-url.html +82 -6
- package/test/expected/transformers/transform-postcss.html +19 -0
- package/test/expected/useConfig.html +9 -0
- package/test/fixtures/basic.html +9 -9
- package/test/fixtures/transformers/base-image-url.html +84 -6
- package/test/fixtures/useConfig.html +9 -0
- package/test/stubs/tailwind/preserve.html +1 -0
- package/test/test-tailwind.js +68 -24
- package/test/test-todisk.js +497 -418
- package/test/test-tostring.js +132 -124
- package/test/test-transformers.js +25 -2
- package/xo.config.js +3 -0
- package/src/transformers/base-image-url.js +0 -9
package/test/test-tostring.js
CHANGED
|
@@ -1,124 +1,132 @@
|
|
|
1
|
-
const test = require('ava')
|
|
2
|
-
const Maizzle = require('../src')
|
|
3
|
-
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const {readFileSync} = require('fs')
|
|
6
|
-
|
|
7
|
-
const fixture = file => readFileSync(path.join(__dirname, 'fixtures', `${file}.html`), 'utf8')
|
|
8
|
-
const expected = file => readFileSync(path.join(__dirname, 'expected', `${file}.html`), 'utf8')
|
|
9
|
-
|
|
10
|
-
const renderString = (string, options = {}) => Maizzle.render(string, options).then(({html}) => html)
|
|
11
|
-
|
|
12
|
-
test('compiles HTML string if no options are passed', async t => {
|
|
13
|
-
const source = fixture('basic')
|
|
14
|
-
|
|
15
|
-
const html = await renderString(source)
|
|
16
|
-
|
|
17
|
-
t.is(html, source)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
test('
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
1
|
+
const test = require('ava')
|
|
2
|
+
const Maizzle = require('../src')
|
|
3
|
+
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const {readFileSync} = require('fs')
|
|
6
|
+
|
|
7
|
+
const fixture = file => readFileSync(path.join(__dirname, 'fixtures', `${file}.html`), 'utf8')
|
|
8
|
+
const expected = file => readFileSync(path.join(__dirname, 'expected', `${file}.html`), 'utf8')
|
|
9
|
+
|
|
10
|
+
const renderString = (string, options = {}) => Maizzle.render(string, options).then(({html}) => html)
|
|
11
|
+
|
|
12
|
+
test('compiles HTML string if no options are passed', async t => {
|
|
13
|
+
const source = fixture('basic')
|
|
14
|
+
|
|
15
|
+
const html = await renderString(source)
|
|
16
|
+
|
|
17
|
+
t.is(html, source)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('uses environment config file(s) if available', async t => {
|
|
21
|
+
const source = fixture('useConfig')
|
|
22
|
+
|
|
23
|
+
const html = await renderString(source, {maizzle: {env: 'maizzle-ci'}})
|
|
24
|
+
|
|
25
|
+
t.is(html, expected('useConfig'))
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('inheritance', async t => {
|
|
29
|
+
let html = await renderString(fixture('inheritance'))
|
|
30
|
+
html = html.replace(/[^\S\r\n]+$/gm, '').trim()
|
|
31
|
+
|
|
32
|
+
t.is(html, expected('inheritance').trim())
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('throws if first argument is not an HTML string', async t => {
|
|
36
|
+
await t.throwsAsync(async () => {
|
|
37
|
+
await renderString(false)
|
|
38
|
+
}, {instanceOf: TypeError, message: 'first argument must be an HTML string, received false'})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('throws if first argument is an empty string', async t => {
|
|
42
|
+
await t.throwsAsync(async () => {
|
|
43
|
+
await renderString('')
|
|
44
|
+
}, {instanceOf: RangeError, message: 'received empty string'})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('runs the `beforeRender` event', async t => {
|
|
48
|
+
const html = await renderString(`<div>{{ page.foo }}</div>`, {
|
|
49
|
+
beforeRender(html, config) {
|
|
50
|
+
config.foo = 'bar'
|
|
51
|
+
|
|
52
|
+
return html
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
t.is(html, `<div>bar</div>`)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('runs the `afterRender` event', async t => {
|
|
60
|
+
const result = await renderString(`<div>foo</div>`, {
|
|
61
|
+
afterRender(html, config) {
|
|
62
|
+
config.replaceStrings = {
|
|
63
|
+
foo: 'baz'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return html
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
t.is(result, `<div>baz</div>`)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('runs the `afterTransformers` event', async t => {
|
|
74
|
+
const result = await renderString(`<div>foo</div>`, {
|
|
75
|
+
maizzle: {
|
|
76
|
+
title: 'bar'
|
|
77
|
+
},
|
|
78
|
+
afterTransformers(html, config) {
|
|
79
|
+
return html.replace('foo', config.title)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
t.is(result, `<div>bar</div>`)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('multiple locals', async t => {
|
|
87
|
+
const result = await renderString(`{{ page.one }}, {{ two }}, {{ three }}`, {
|
|
88
|
+
maizzle: {
|
|
89
|
+
one: 1,
|
|
90
|
+
build: {
|
|
91
|
+
posthtml: {
|
|
92
|
+
expressions: {
|
|
93
|
+
locals: {
|
|
94
|
+
two: 2
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
locals: {
|
|
100
|
+
three: 3
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
t.is(result, `1, 2, 3`)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('prevents overwriting page object', async t => {
|
|
109
|
+
const result = await renderString(`{{ page.one }}, {{ two }}, {{ three }}`, {
|
|
110
|
+
maizzle: {
|
|
111
|
+
one: 1,
|
|
112
|
+
build: {
|
|
113
|
+
posthtml: {
|
|
114
|
+
expressions: {
|
|
115
|
+
locals: {
|
|
116
|
+
page: {
|
|
117
|
+
two: 2
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
locals: {
|
|
124
|
+
page: {
|
|
125
|
+
three: 3
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
t.is(result, `1, undefined, undefined`)
|
|
132
|
+
})
|
|
@@ -191,12 +191,23 @@ test('extra attributes (disabled)', async t => {
|
|
|
191
191
|
t.is(html, '<img src="example.jpg">')
|
|
192
192
|
})
|
|
193
193
|
|
|
194
|
-
test('base
|
|
194
|
+
test('base URL (string)', async t => {
|
|
195
195
|
const html = await Maizzle.applyBaseImageUrl(fixture('base-image-url'), 'https://example.com/')
|
|
196
196
|
|
|
197
197
|
t.is(html, expected('base-image-url'))
|
|
198
198
|
})
|
|
199
199
|
|
|
200
|
+
test('base URL (object)', async t => {
|
|
201
|
+
const html = await Maizzle.applyBaseImageUrl(fixture('base-image-url'), {
|
|
202
|
+
url: 'https://example.com/',
|
|
203
|
+
allTags: true,
|
|
204
|
+
styleTag: true,
|
|
205
|
+
inlineCss: true
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
t.is(html, expected('base-image-url'))
|
|
209
|
+
})
|
|
210
|
+
|
|
200
211
|
test('prettify', async t => {
|
|
201
212
|
// eslint-disable-next-line
|
|
202
213
|
const html = await Maizzle.prettify('<div><p>test</p></div>', {indent_inner_result: true})
|
|
@@ -261,12 +272,24 @@ test('six digit hex (disabled)', async t => {
|
|
|
261
272
|
t.is(html, '<td style="color: #ffc" bgcolor="#000"></td>');
|
|
262
273
|
})
|
|
263
274
|
|
|
264
|
-
test('transform contents', async t => {
|
|
275
|
+
test('transform contents (javascript)', async t => {
|
|
265
276
|
const html = await Maizzle.transformContents('<div uppercase>test</div>', {uppercase: string => string.toUpperCase()})
|
|
266
277
|
|
|
267
278
|
t.is(html, '<div>TEST</div>')
|
|
268
279
|
})
|
|
269
280
|
|
|
281
|
+
test('transform contents (postcss)', async t => {
|
|
282
|
+
const html = await Maizzle.transformContents(
|
|
283
|
+
`<style postcss>
|
|
284
|
+
div {
|
|
285
|
+
@apply hidden container;
|
|
286
|
+
}
|
|
287
|
+
</style>`
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
t.is(html, expected('transform-postcss').trim())
|
|
291
|
+
})
|
|
292
|
+
|
|
270
293
|
test('url parameters', async t => {
|
|
271
294
|
const html = await Maizzle.addURLParams('<a href="https://example.com">test</a>', {bar: 'baz', qix: 'qux'})
|
|
272
295
|
|
package/xo.config.js
CHANGED
|
@@ -3,11 +3,14 @@ module.exports = {
|
|
|
3
3
|
rules: {
|
|
4
4
|
semi: 0,
|
|
5
5
|
complexity: 0,
|
|
6
|
+
'max-params': 0,
|
|
6
7
|
'no-lonely-if': 0,
|
|
7
8
|
'unicorn/no-reduce': 0,
|
|
8
9
|
'import/extensions': 0,
|
|
9
10
|
'operator-linebreak': 0,
|
|
10
11
|
'max-nested-callbacks': 0,
|
|
12
|
+
'unicorn/filename-case': 0,
|
|
13
|
+
'unicorn/no-hex-escape': 0,
|
|
11
14
|
'unicorn/prefer-ternary': 0,
|
|
12
15
|
'unicorn/string-content': 0,
|
|
13
16
|
'unicorn/no-array-for-each': 0,
|