Git Product home page Git Product logo

oy's Introduction

Oy npm version Build Status

Emails, oy vey!

Render HTML emails on the server with React. Oy provides functionality to:

  • Validate props against email best-practices with Oy components.
  • Render templates server-side with Oy.renderTemplate.

Blog Post

Feedback request: Try the next branch, which is slated for a 1.0.0-rc1 release. It aims to improve the library's usability. Open an issue with your feedback. Thanks!

Installation

npm install --save oy-vey

Example usage

Replace table markup with validating Oy components

import React from 'react';
import Oy from 'oy-vey';

const {Table, TBody, TR, TD} = Oy;

export default (props) => {
  return (
    <Table width={props.maxWidth}>
      <TBody>
        <TR>
          <TD align="center">
            {props.children}
          </TD>
        </TR>
      </TBody>
    </Table>
  );
};

Compose higher level components like usual

import React from 'react';

import MyLayout from './layout/MyLayout.jsx';
import BodyText from './modules/BodyText.jsx';

export default (props) => {
  return (
    <MyLayout>
      <BodyText>Welcome to Oy!</BodyText>
    </MyLayout>
  );
};

Inject rendered code into HTML skeleton with Oy.renderTemplate

For example, if using Express.js:

import express from 'express';
import React from 'react';
import Oy from 'oy-vey';

import GettingStartedEmail from './templates/GettingStartedEmail.jsx';

const server = express();
server.set('port', (process.env.PORT || 8887));

server.get('/email/oy', (req, res) => {
  const template = Oy.renderTemplate(<GettingStartedEmail />, {
    title: 'Getting Started with Foo',
    headCSS: '@media ...',
    previewText: 'Here is your guide...'
  });
  res.send(template);
});

server.listen(server.get('port'), () => {
  console.log('Node server is running on port', server.get('port'));
});

Default components

The Oy namespace exposes the following components validated against email best practices:

Table TBody TR TD Img A

If you want to circumvent this validation, you can use Oy.Element and pass the tagName prop to implement your own validated element. If you additionally don’t mind React stripping the attributes below, you can use React DOM Element objects (i.e. use <table> instead of <Table>).

HTML attributes

In addition to the attributes supported by React, these HTML attributes are supported on Oy components:

align background bgColor border vAlign

Oy.renderTemplate API

Oy.renderTemplate(<Template />, templateOptions)

The templateOptions parameter is an object with the following fields:

title (string, required) - Used by clients if email is opened in a web page.
previewText (string, required) - Short description that appears in email clients
headCSS (string, optional) - CSS that belongs in `<head>`
lang (string, optional) - ISO language code
dir (string, optional) - Either 'ltr' or 'rtl'. 'ltr' is the default

Note about <= v0.5.0: bodyContent in options is no longer supported to avoid the insertion of arbitrary HTML into the email body.

Contributing

# Test
npm test

# Compile from ES6 in src/ to ES5 in lib/
npm run compile

We welcome contributions. If there's some information missing or ideas for how to make Oy better, please send a pull request, file an issue, or email [email protected].

The best place to start would be in contributing new rules. A running wishlist of email validation rules are in the Issues section.

oy's People

Contributors

cspickert avatar decoy31 avatar gerhardsletten avatar malte-wessel avatar meyer avatar revivek avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

l3r

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.