Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change way of registering dependencies, for better handle with mjmlconfig #35

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions components/MjBasicComponent.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { registerDependencies } from 'mjml-validator'
import { BodyComponent } from 'mjml-core'

registerDependencies({
// Tell the validator which tags are allowed as our component's parent
'mj-hero': ['mj-basic-component'],
'mj-column': ['mj-basic-component'],
// Tell the validator which tags are allowed as our component's children
'mj-basic-component': []
})

/*
Our component is a (useless) simple text tag, that adds colored stars around the text.
It can take 3 attributes, to specify size and colors.
*/
export default class MjBasicComponent extends BodyComponent {
// Tell the parser that our component won't contain other mjml tags
static endingTag = true

static dependencies = {
// Tell the validator which tags are allowed as our component's parent
'mj-hero': ['mj-basic-component'],
'mj-column': ['mj-basic-component'],
// Tell the validator which tags are allowed as our component's children
'mj-basic-component': []
}

// Tells the validator which attributes are allowed for mj-layout
static allowedAttributes = {
Expand Down
12 changes: 6 additions & 6 deletions components/MjImageText.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import reverse from 'lodash/reverse'

import { registerDependencies } from 'mjml-validator'
import { BodyComponent } from 'mjml-core'
registerDependencies({
'mj-image-text': [],
'mj-body': ['mj-image-text'],
'mj-wrapper': ['mj-image-text'],
})

export default class MjImageText extends BodyComponent {
static endingTag = true

static dependencies = {
'mj-image-text': [],
'mj-body': ['mj-image-text'],
'mj-wrapper': ['mj-image-text'],
}

/*
We could obviously handle all the attributes accepted for Mj Section,
Column, Image and Text, but let's keep it simple for this example.
Expand Down
43 changes: 21 additions & 22 deletions components/MjLayout.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
import { registerDependencies } from 'mjml-validator'
import { BodyComponent } from 'mjml-core'

registerDependencies({
// Tell the validator which tags are allowed as our component's children
'mj-layout': [
'mj-accordion',
'mj-button',
'mj-carousel',
'mj-divider',
'mj-html',
'mj-image',
'mj-raw',
'mj-social',
'mj-spacer',
'mj-table',
'mj-text',
'mj-navbar'
],
// Now tell the validator which tags are allowed as our component's parent
'mj-wrapper': ['mj-layout'],
'mj-body': ['mj-layout'],
})

/*
This component is an example of layout, which uses existing mjml components
and can take some as children.
Expand All @@ -32,6 +10,27 @@ export default class MjLayout extends BodyComponent {
super(initialDatas)
this.cssId = Math.floor(Math.random() * 9) + 1
}

static dependencies = {
// Tell the validator which tags are allowed as our component's children
'mj-layout': [
'mj-accordion',
'mj-button',
'mj-carousel',
'mj-divider',
'mj-html',
'mj-image',
'mj-raw',
'mj-social',
'mj-spacer',
'mj-table',
'mj-text',
'mj-navbar'
],
// Now tell the validator which tags are allowed as our component's parent
'mj-wrapper': ['mj-layout'],
'mj-body': ['mj-layout'],
}

// Tells the validator which attributes are allowed for mj-layout
static allowedAttributes = {
Expand Down