@maizzle/framework 4.0.0-alpha.9 → 4.0.0

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.
@@ -1,29 +1,27 @@
1
- /* eslint-disable camelcase */
2
-
3
- const pretty = require('pretty')
4
- const {get, merge, isEmpty} = require('lodash')
5
-
6
- module.exports = async (html, config = {}, direct = false) => {
7
- if (get(config, 'prettify') === false) {
8
- return html
9
- }
10
-
11
- const defaultConfig = {
12
- space_around_combinator: true, // Preserve space around CSS selector combinators
13
- newline_between_rules: false, // Remove empty lines between CSS rules
14
- indent_inner_html: false, // Helps reduce file size
15
- extra_liners: [] // Don't add extra new line before any tag
16
- }
17
-
18
- config = direct ? config : merge(defaultConfig, get(config, 'prettify', {}))
19
-
20
- if (typeof config === 'boolean' && config) {
21
- return pretty(html, defaultConfig)
22
- }
23
-
24
- if (!isEmpty(config)) {
25
- return pretty(html, config)
26
- }
27
-
28
- return html
29
- }
1
+ /* eslint-disable camelcase */
2
+ const pretty = require('pretty')
3
+ const {get, merge, isEmpty, isObject} = require('lodash')
4
+
5
+ module.exports = async (html, config = {}, direct = false) => {
6
+ const defaultConfig = {
7
+ space_around_combinator: true, // Preserve space around CSS selector combinators
8
+ newline_between_rules: false, // Remove empty lines between CSS rules
9
+ indent_inner_html: false, // Helps reduce file size
10
+ extra_liners: [] // Don't add extra new line before any tag
11
+ }
12
+
13
+ config = direct ? config : get(config, 'prettify')
14
+
15
+ // Don't prettify if not explicitly enabled in config
16
+ if (!config || (isObject(config) && isEmpty(config))) {
17
+ return html
18
+ }
19
+
20
+ if (typeof config === 'boolean' && config) {
21
+ return pretty(html, defaultConfig)
22
+ }
23
+
24
+ config = merge(defaultConfig, config)
25
+
26
+ return pretty(html, config)
27
+ }
@@ -0,0 +1,19 @@
1
+ const posthtml = require('posthtml')
2
+ const {get, isObject, isEmpty} = require('lodash')
3
+ const mergeLonghand = require('posthtml-postcss-merge-longhand')
4
+
5
+ module.exports = async (html, config, direct = false) => {
6
+ config = direct ? (isObject(config) ? config : true) : get(config, 'shorthandInlineCSS', [])
7
+
8
+ const posthtmlOptions = get(config, 'build.posthtml.options', {})
9
+
10
+ if (typeof config === 'boolean' && config) {
11
+ html = await posthtml([mergeLonghand()]).process(html, posthtmlOptions).then(result => result.html)
12
+ }
13
+
14
+ if (isObject(config) && !isEmpty(config)) {
15
+ html = await posthtml([mergeLonghand(config)]).process(html, posthtmlOptions).then(result => result.html)
16
+ }
17
+
18
+ return html
19
+ }
@@ -5,7 +5,7 @@ Variable from locals attribute: bar
5
5
 
6
6
  Variable from page: maizzle-ci
7
7
 
8
- Variable from attribute: Nested component
8
+ Variable from attribute: Nested component
9
9
 
10
10
  Variable from locals attribute: bar (nested)
11
11
 
@@ -1,16 +1,15 @@
1
1
  <!doctype html>
2
2
  <html>
3
- <head>
4
- <style>
5
- div {
6
- margin-top: 1px;
7
- margin-right: 2px;
8
- margin-bottom: 3px;
9
- margin-left: 4px;
10
- }
11
- </style>
12
- </head>
13
- <body>
14
- <div>test</div>
15
- </body>
3
+ <head>
4
+ <style>div {
5
+ margin-top: 1px;
6
+ margin-right: 2px;
7
+ margin-bottom: 3px;
8
+ margin-left: 4px;
9
+ }
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <div>test</div>
14
+ </body>
16
15
  </html>
@@ -1,48 +1,36 @@
1
1
  <!doctype html>
2
2
  <html>
3
- <head>
4
- <style data-embed="">
5
- .block {
6
- display: block !important;
7
- }
8
- .inline {
9
- display: inline !important;
10
- }
11
- .table {
12
- display: table !important;
13
- }
14
- .contents {
15
- display: contents !important;
16
- }
17
- .truncate {
18
- overflow: hidden !important;
19
- text-overflow: ellipsis !important;
20
- white-space: nowrap !important;
21
- }
22
- .uppercase {
23
- text-transform: uppercase !important;
24
- }
25
- .lowercase {
26
- text-transform: lowercase !important;
27
- }
28
- .capitalize {
29
- text-transform: capitalize !important;
30
- }
31
- div {
32
- text-transform: uppercase;
33
- }
34
- [data-ogsc] .inexistent {
35
- color: #ef4444;
36
- }
37
- div > u + .body .gmail-android-block {
38
- display: block !important;
39
- }
40
- u + #body a {
41
- color: inherit;
42
- }
43
- </style>
44
- </head>
45
- <body>
46
- <div>test</div>
47
- </body>
3
+ <head>
4
+ <style data-embed="">.block {
5
+ display: block !important;
6
+ } .inline {
7
+ display: inline !important;
8
+ } .table {
9
+ display: table !important;
10
+ } .contents {
11
+ display: contents !important;
12
+ } .truncate {
13
+ overflow: hidden !important;
14
+ text-overflow: ellipsis !important;
15
+ white-space: nowrap !important;
16
+ } .uppercase {
17
+ text-transform: uppercase !important;
18
+ } .lowercase {
19
+ text-transform: lowercase !important;
20
+ } .capitalize {
21
+ text-transform: capitalize !important;
22
+ } div {
23
+ text-transform: uppercase;
24
+ } [data-ogsc] .inexistent {
25
+ color: #ef4444;
26
+ } div > u + .body .gmail-android-block {
27
+ display: block !important;
28
+ } u + #body a {
29
+ color: inherit;
30
+ }
31
+ </style>
32
+ </head>
33
+ <body>
34
+ <div>test</div>
35
+ </body>
48
36
  </html>
@@ -1,9 +1,9 @@
1
1
  <!doctype html>
2
2
  <html>
3
- <head>
4
- <title>test></title>
5
- </head>
6
- <body>
7
- <div>build_production</div>
8
- </body>
3
+ <head>
4
+ <title>test></title>
5
+ </head>
6
+ <body>
7
+ <div>build_production</div>
8
+ </body>
9
9
  </html>
@@ -5,7 +5,7 @@
5
5
  "foo": "bar"
6
6
  }'
7
7
  >
8
- Variable from page: [[ page.env ]]
8
+ Variable from page: [[ page.env ]]
9
9
 
10
10
  <component
11
11
  src="test/stubs/components/component.html"
@@ -14,6 +14,6 @@
14
14
  "foo": "bar (nested)"
15
15
  }'
16
16
  >
17
- Variable from page (nested): [[ page.env ]]
17
+ Variable from page (nested): [[ page.env ]]
18
18
  </component>
19
19
  </component>
@@ -1,19 +1,19 @@
1
- const test = require('ava')
2
- const Config = require('../src/generators/config')
3
-
4
- test('returns the merged config', async t => {
5
- const config = await Config.getMerged('maizzle-ci')
6
- t.is(config.env, 'maizzle-ci')
7
- })
8
-
9
- test('throws if env name is not a string', async t => {
10
- await t.throwsAsync(async () => {
11
- await Config.getMerged(false)
12
- }, {instanceOf: TypeError, message: `env name must be a string, received boolean(false)`})
13
- })
14
-
15
- test('throws if a config could not be loaded for the specified environment', async t => {
16
- await t.throwsAsync(async () => {
17
- await Config.getMerged('fake')
18
- }, {instanceOf: Error, message: `could not load config.fake.js`})
19
- })
1
+ const test = require('ava')
2
+ const Config = require('../src/generators/config')
3
+
4
+ test('returns the merged config', async t => {
5
+ const config = await Config.getMerged('maizzle-ci')
6
+ t.is(config.env, 'maizzle-ci')
7
+ })
8
+
9
+ test('throws if env name is not a string', async t => {
10
+ await t.throwsAsync(async () => {
11
+ await Config.getMerged(false)
12
+ }, {instanceOf: TypeError, message: `env name must be a string, received boolean(false)`})
13
+ })
14
+
15
+ test('throws if a config could not be loaded for the specified environment', async t => {
16
+ await t.throwsAsync(async () => {
17
+ await Config.getMerged('fake')
18
+ }, {instanceOf: Error, message: `could not load config.fake.js`})
19
+ })
@@ -1,8 +1,8 @@
1
- const test = require('ava')
2
- const PostCSS = require('../src/generators/postcss')
3
-
4
- test('throws on processing error', async t => {
5
- await t.throwsAsync(async () => {
6
- await PostCSS.process(null, {})
7
- }, {instanceOf: Error, message: 'PostCSS processing failed'})
8
- })
1
+ const test = require('ava')
2
+ const PostCSS = require('../src/generators/postcss')
3
+
4
+ test('throws on processing error', async t => {
5
+ await t.throwsAsync(async () => {
6
+ await PostCSS.process(null, {})
7
+ }, {instanceOf: Error, message: 'PostCSS processing failed'})
8
+ })
@@ -1,66 +1,72 @@
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('layouts', async t => {
13
- const source = fixture('posthtml/layout')
14
-
15
- const html = await renderString(source, {maizzle: {env: 'maizzle-ci'}})
16
-
17
- t.is(html.trim(), expected('posthtml/layout').trim())
18
- })
19
-
20
- test('inheritance when extending a template', async t => {
21
- let html = await renderString(fixture('posthtml/extend-template'))
22
- html = html.replace(/[^\S\r\n]+$/gm, '').trim()
23
-
24
- t.is(html, expected('posthtml/extend-template').trim())
25
- })
26
-
27
- test('components', async t => {
28
- const source = fixture('posthtml/component')
29
- const options = {
30
- maizzle: {
31
- env: 'maizzle-ci',
32
- build: {
33
- components: {
34
- expressions: {
35
- delimiters: ['[[', ']]']
36
- }
37
- }
38
- }
39
- }
40
- }
41
-
42
- const html = await renderString(source, options)
43
-
44
- t.is(html.trim(), expected('posthtml/component').trim())
45
- })
46
-
47
- test('fetch component', async t => {
48
- const source = fixture('posthtml/fetch')
49
- const options = {
50
- maizzle: {
51
- env: 'maizzle-ci',
52
- build: {
53
- posthtml: {
54
- expressions: {
55
- delimiters: ['[[', ']]']
56
- }
57
- }
58
- }
59
- }
60
- }
61
-
62
- let html = await renderString(source, options)
63
- html = html.replace(/[^\S\r\n]+$/gm, '')
64
-
65
- t.is(html.trim(), expected('posthtml/fetch').trim())
66
- })
1
+ const test = require('ava')
2
+ const Maizzle = require('../src')
3
+
4
+ const path = require('path')
5
+ const fs = require('fs')
6
+
7
+ const readFile = (dir, filename) => fs.promises
8
+ .readFile(path.join(__dirname, dir, `${filename}.html`), 'utf8')
9
+ .then(html => html.trim())
10
+
11
+ const fixture = file => readFile('fixtures', file)
12
+ const expected = file => readFile('expected', file)
13
+
14
+ const renderString = (string, options = {}) => Maizzle.render(string, options).then(({html}) => html)
15
+
16
+ test('layouts', async t => {
17
+ const source = await fixture('posthtml/layout')
18
+
19
+ const html = await renderString(source, {maizzle: {env: 'maizzle-ci'}})
20
+
21
+ t.is(html.trim(), await expected('posthtml/layout'))
22
+ })
23
+
24
+ test('inheritance when extending a template', async t => {
25
+ const source = await fixture('posthtml/extend-template')
26
+ let html = await renderString(source)
27
+
28
+ html = html.replace(/[^\S\r\n]+$/gm, '').trim()
29
+
30
+ t.is(html, await expected('posthtml/extend-template'))
31
+ })
32
+
33
+ test('components', async t => {
34
+ const source = await fixture('posthtml/component')
35
+ const options = {
36
+ maizzle: {
37
+ env: 'maizzle-ci',
38
+ build: {
39
+ components: {
40
+ expressions: {
41
+ delimiters: ['[[', ']]']
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+
48
+ const html = await renderString(source, options)
49
+
50
+ t.is(html.trim(), await expected('posthtml/component'))
51
+ })
52
+
53
+ test('fetch component', async t => {
54
+ const source = await fixture('posthtml/fetch')
55
+ const options = {
56
+ maizzle: {
57
+ env: 'maizzle-ci',
58
+ build: {
59
+ posthtml: {
60
+ expressions: {
61
+ delimiters: ['[[', ']]']
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ let html = await renderString(source, options)
69
+ html = html.replace(/[^\S\r\n]+$/gm, '')
70
+
71
+ t.is(html.trim(), await expected('posthtml/fetch'))
72
+ })