Skip to content

Commit

Permalink
ref #2396 #2355 move body tag from skeleton to mj-body, add lang on w…
Browse files Browse the repository at this point in the history
…rapping div
  • Loading branch information
Cédric Cavrois committed Jan 13, 2022
1 parent 0f4c641 commit 1245156
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 31 deletions.
26 changes: 17 additions & 9 deletions packages/mjml-body/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BodyComponent } from 'mjml-core'
import buildPreview from './helpers/preview'

export default class MjBody extends BodyComponent {
static componentName = 'mj-body'
Expand All @@ -21,25 +22,32 @@ export default class MjBody extends BodyComponent {

getStyles() {
return {
body: {
'word-spacing': 'normal',
'background-color': this.getAttribute('background-color'),
},
div: {
'background-color': this.getAttribute('background-color'),
},
}
}

render() {
const { setBackgroundColor } = this.context
setBackgroundColor(this.getAttribute('background-color'))
const { preview, lang } = this.context.getGlobalDatas()

return `
<div
${this.htmlAttributes({
class: this.getAttribute('css-class'),
<body ${this.htmlAttributes({
class: this.getAttribute('css-class'),
style: 'body',
})}>
${buildPreview(preview)}
<div ${this.htmlAttributes({
lang,
style: 'div',
})}
>
${this.renderChildren()}
</div>
})}>
${this.renderChildren()}
</div>
</body>
`
}
}
1 change: 1 addition & 0 deletions packages/mjml-core/src/createComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Component {
context = {},
props = {},
globalAttributes = {},
globalDatas = {},
} = initialDatas

this.props = {
Expand Down
11 changes: 0 additions & 11 deletions packages/mjml-core/src/helpers/preview.js

This file was deleted.

8 changes: 1 addition & 7 deletions packages/mjml-core/src/helpers/skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import buildMediaQueriesTags from './mediaQueries'

export default function skeleton(options) {
const {
backgroundColor = '',
breakpoint = '480px',
content = '',
fonts = {},
Expand Down Expand Up @@ -76,12 +75,7 @@ export default function skeleton(options) {
</style>
${headRaw.filter(negate(isNil)).join('\n')}
</head>
<body style="word-spacing:normal;${
backgroundColor ? `background-color:${backgroundColor};` : ''
}">
${buildPreview(preview)}
${content}
</body>
${content}
</html>
`
}
5 changes: 1 addition & 4 deletions packages/mjml-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export default function mjml2html(mjml, options = {}) {
mjml = handleMjml3(mjml, { noMigrateWarn })

const globalDatas = {
backgroundColor: '',
breakpoint: '480px',
classes: {},
classesDefault: {},
Expand Down Expand Up @@ -278,9 +277,7 @@ export default function mjml2html(mjml, options = {}) {
addComponentHeadSyle(headStyle) {
globalDatas.componentsHeadStyle.push(headStyle)
},
setBackgroundColor: (color) => {
globalDatas.backgroundColor = color
},
getGlobalDatas: () => globalDatas,
processing: (node, context) => processing(node, context, applyAttributes),
}

Expand Down

0 comments on commit 1245156

Please sign in to comment.