How to use mjml-validator - 6 common examples

To help you get started, we’ve selected a few mjml-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mjmlio / mjml / packages / mjml-core / src / helpers / mjmlconfig.js View on Github external
packages.forEach(compPath => {
    let resolvedPath = compPath
    try {
      resolvedPath = resolveComponentPath(compPath, componentRootPath)
      if (resolvedPath) {
        const requiredComp = require(resolvedPath) // eslint-disable-line global-require, import/no-dynamic-require
        registerCustomComponent(requiredComp.default || requiredComp, registerCompFn)
        registerDependencies((requiredComp.default || requiredComp).dependencies)
        result.success.push(compPath)
      }
    } catch (e) {
      result.failures.push({ error: e, compPath })
      if (e.code === 'ENOENT' || e.code === 'MODULE_NOT_FOUND') {
        console.error('Missing or unreadable custom component : ', resolvedPath) // eslint-disable-line no-console
      } else {
        console.error('Error when registering custom component : ', resolvedPath, e) // eslint-disable-line no-console
      }
    }
  })
github mjmlio / mjml / packages / mjml-cli / src / client.js View on Github external
inputs.forEach(i => {
    try {
      let compiled
      switch (inputOpt) {
        case 'm': // eslint-disable-line no-case-declarations
          compiled = { html: migrate(i.mjml, { beautify: true }) }
          break
        case 'v': // eslint-disable-line no-case-declarations
          const mjmlJson = MJMLParser(i.mjml, { components })
          compiled = {
            errors: validate(mjmlJson, { components, initializeType }),
          }
          break
        default:
          compiled = mjml2html(i.mjml, { ...config, filePath: filePath || i.file })
      }

      convertedStream.push({ ...i, compiled })
    } catch (e) {
      EXIT_CODE = 2
      failedStream.push({ file: i.file, error: e })
    }
  })
github mjmlio / mjml / packages / mjml-core / src / MJMLRenderer.js View on Github external
validate () {
    if (this.options.level == "skip") {
      return;
    }

    this.errors = MJMLValidator(this.content)

    if (this.options.level == "strict" && this.errors.length > 0) {
      throw new MJMLValidationError(this.errors)
    }
  }
github mjmlio / mjml / packages / mjml-core / src / index.js View on Github external
title: '',
    forceOWADesktop: get(mjml, 'attributes.owa', 'mobile') === 'desktop',
    lang: get(mjml, 'attributes.lang'),
  }

  const validatorOptions = {
    components,
    initializeType,
  }

  switch (validationLevel) {
    case 'skip':
      break

    case 'strict':
      errors = MJMLValidator(mjml, validatorOptions)

      if (errors.length > 0) {
        throw new ValidationError(
          `ValidationError: \n ${errors
            .map(e => e.formattedMessage)
            .join('\n')}`,
          errors,
        )
      }
      break

    case 'soft':
    default:
      errors = MJMLValidator(mjml, validatorOptions)
      break
  }
github mjmlio / mjml / packages / mjml-core / src / index.js View on Github external
case 'strict':
      errors = MJMLValidator(mjml, validatorOptions)

      if (errors.length > 0) {
        throw new ValidationError(
          `ValidationError: \n ${errors
            .map(e => e.formattedMessage)
            .join('\n')}`,
          errors,
        )
      }
      break

    case 'soft':
    default:
      errors = MJMLValidator(mjml, validatorOptions)
      break
  }

  const mjBody = find(mjml.children, { tagName: 'mj-body' })
  const mjHead = find(mjml.children, { tagName: 'mj-head' })

  const processing = (node, context, parseMJML = identity) => {
    if (!node) {
      return
    }

    const component = initComponent({
      name: node.tagName,
      initialDatas: {
        ...parseMJML(node),
        context,
github mjmlio / mjml / packages / mjml-core / src / parsers / config.js View on Github external
validators.forEach(file => {
    if (!file) {
      return
    }

    try {
      const filename = path.join(process.cwd(), file)
      const rule = isRelativePath(file) ? require(filename) : require.main.require(file)

      registerMJRule(rule)
    } catch (e) {
      warning(false, `.mjmlconfig file ${file} opened from ${cwd} has an error : ${e}`)
    }
  })
}

mjml-validator

mjml-validator

MIT
Latest version published 11 months ago

Package Health Score

91 / 100
Full package analysis

Similar packages