npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oy-vey

v0.12.1

Published

React utilities for building server-side email templates.

Downloads

52,303

Readme

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 - ReactConf 2016 talk

NOTE: If using TypeScript, the current typings result in quickly growing compilation times. I would suggest not using TypeScript with Oy until the bug is addressed. If TypeScript is a requirement, see a workaround that disables a subset of type-checks.

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

HTML attributes

As of React 16, React will not strip non-standard HTML attributes. That means you can use all the attributes typically required for email templates:

align background bgcolor border valign

For those migrating from previous Oy versions, note that bgColor is now bgcolor and vAlign is valign.

Oy.renderTemplate API

Oy.renderTemplate(<Template />, templateOptions[, generateCustomTemplate])

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>`. Note, email clients may strip this out.
bgColor (string, optional) - The background color for the email. '#FFFFFF' is the default
lang (string, optional) - ISO language code
dir (string, optional) - Either 'ltr' or 'rtl'. 'ltr' is the default

Using a Custom Template

If Oy's default template doesn't work for you, you can make your own. generateCustomTemplate takes in templateOptions with an additional property bodyContent, which is the rendered body HTML to be inserted into your template. It then returns a string that should be the final email HTML sent to users.

const generateCustomTemplate = (templateOptions) => {
  return `
    <!doctype html>
    <html>
      <head>
        <title>${templateOptions.title}</title>
      </head>
      <body>
        ${templateOptions.bodyContent}
      </body>
    </html>
  `
};

const template = Oy.renderTemplate(<GettingStartedEmail />, {
  title: 'Getting Started with Foo'
}, (templateOptions) => generateCustomTemplate(templateOptions));

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.