0.1.6 • Published 10 months ago

@melvynx/maily-render v0.1.6

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

Install

Install @melvynx/maily-render from your command line.

pnpm add @melvynx/maily-render

Getting started

Convert React components into a HTML string.

import { render } from '@melvynx/maily-render';

const html = await render({
  type: 'doc',
  content: [
    {
      type: 'paragraph',
      content: [
        {
          type: 'text',
          text: 'Hello World!',
        },
      ],
    },
  ],
});

Variables

You can replace variables in the content.

import { Maily } from '@melvynx/maily-render';

const maily = new Maily({
  type: 'doc',
  content: [
    {
      type: 'paragraph',
      attrs: { textAlign: 'left' },
      content: [
        {
          type: 'variable',
          attrs: {
            id: 'currentDate',
            fallback: 'now',
            showIfKey: null,
          },
        },
      ],
    },
  ],
});

maily.setVariableValue('currentDate', new Date().toISOString());
const html = await maily.render();

Payloads

Payload values are used for the Repeat and Show If blocks.

// (Omitted repeated imports)

const maily = new Maily({
  type: 'doc',
  content: [
    {
      type: 'repeat',
      attrs: { each: 'items', showIfKey: null },
      content: [
        {
          type: 'paragraph',
          attrs: { textAlign: 'left' },
          content: [{ type: 'text', text: 'Hello' }],
        },
      ],
    },
  ],
});

maily.setPayloadValue('items', ['Alice', 'Bob', 'Charlie']);
const html = await maily.render();

Contributions

Feel free to submit pull requests, create issues, or spread the word.

License

Non-Commercial Use Only. See LICENSE for more information.

0.1.6

10 months ago

0.1.5

10 months ago

0.1.4

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.2.0

10 months ago

0.1.0

10 months ago