{"id":13451913,"url":"https://github.com/revivek/oy","last_synced_at":"2025-03-23T19:33:11.689Z","repository":{"id":33949851,"uuid":"37676432","full_name":"revivek/oy","owner":"revivek","description":"Render HTML emails on the server with React.","archived":false,"fork":false,"pushed_at":"2023-03-01T09:16:02.000Z","size":854,"stargazers_count":832,"open_issues_count":18,"forks_count":46,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-03-18T23:46:49.609Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/revivek.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-18T18:13:04.000Z","updated_at":"2025-02-11T15:48:09.000Z","dependencies_parsed_at":"2024-06-18T13:58:55.383Z","dependency_job_id":null,"html_url":"https://github.com/revivek/oy","commit_stats":null,"previous_names":["oysterbooks/oy"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/revivek%2Foy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/revivek%2Foy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/revivek%2Foy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/revivek%2Foy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/revivek","download_url":"https://codeload.github.com/revivek/oy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244991166,"owners_count":20543627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:01:06.762Z","updated_at":"2025-03-23T19:33:11.357Z","avatar_url":"https://github.com/revivek.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Email"],"sub_categories":[],"readme":"# Oy [![npm version](https://badge.fury.io/js/oy-vey.svg)](http://badge.fury.io/js/oy-vey) [![Build Status](https://travis-ci.org/revivek/oy.svg?branch=master)](https://travis-ci.org/revivek/oy)\n\n*Emails, oy vey!*\n\nRender HTML emails on the server with React. Oy provides functionality to:\n\n- Validate props against [email best-practices](https://github.com/revivek/oy/tree/master/src/rules) with `Oy` components.\n- Render templates server-side with `Oy.renderTemplate`.\n\n[Blog Post](http://oyster.engineering/post/124868558323/emails-oy-vey-render-emails-with-react) - [ReactConf 2016 talk](https://www.youtube.com/watch?v=KNGj8Y0J01Q)\n\nNOTE: 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](https://github.com/revivek/oy/issues/84). If TypeScript is a requirement, [see a workaround](https://github.com/revivek/oy/issues/84#issuecomment-374994906) that disables a subset of type-checks.\n\n## Installation\n\n```\nnpm install --save oy-vey\n```\n\n## Example usage\n\n### Replace table markup with validating Oy components\n\n```js\nimport React from 'react';\nimport Oy from 'oy-vey';\n\nconst {Table, TBody, TR, TD} = Oy;\n\nexport default (props) =\u003e {\n  return (\n    \u003cTable width={props.maxWidth}\u003e\n      \u003cTBody\u003e\n        \u003cTR\u003e\n          \u003cTD align=\"center\"\u003e\n            {props.children}\n          \u003c/TD\u003e\n        \u003c/TR\u003e\n      \u003c/TBody\u003e\n    \u003c/Table\u003e\n  );\n};\n```\n\n### Compose higher level components like usual\n\n```js\nimport React from 'react';\n\nimport MyLayout from './layout/MyLayout.jsx';\nimport BodyText from './modules/BodyText.jsx';\n\nexport default (props) =\u003e {\n  return (\n    \u003cMyLayout\u003e\n      \u003cBodyText\u003eWelcome to Oy!\u003c/BodyText\u003e\n    \u003c/MyLayout\u003e\n  );\n};\n```\n\n\n### Inject rendered code into HTML skeleton with Oy.renderTemplate\n\nFor example, if using Express.js:\n\n```js\nimport express from 'express';\nimport React from 'react';\nimport Oy from 'oy-vey';\n\nimport GettingStartedEmail from './templates/GettingStartedEmail.jsx';\n\nconst server = express();\nserver.set('port', (process.env.PORT || 8887));\n\nserver.get('/email/oy', (req, res) =\u003e {\n  const template = Oy.renderTemplate(\u003cGettingStartedEmail /\u003e, {\n    title: 'Getting Started with Foo',\n    headCSS: '@media ...',\n    previewText: 'Here is your guide...'\n  });\n  res.send(template);\n});\n\nserver.listen(server.get('port'), () =\u003e {\n  console.log('Node server is running on port', server.get('port'));\n});\n```\n\n## Default components\n\nThe `Oy` namespace exposes the following components validated against email best practices:\n\n```\nTable TBody TR TD Img A\n```\n\n## HTML attributes\n\nAs of React 16, React will not strip non-standard HTML attributes. That means you can use all the attributes typically required for email templates:\n\n```\nalign background bgcolor border valign\n```\n\nFor those migrating from previous Oy versions, note that `bgColor` is now `bgcolor` and `vAlign` is `valign`.\n\n## Oy.renderTemplate API\n\n`Oy.renderTemplate(\u003cTemplate /\u003e, templateOptions[, generateCustomTemplate])`\n\nThe `templateOptions` parameter is an object with the following fields:\n\n```\ntitle (string, required) - Used by clients if email is opened in a web page.\npreviewText (string, required) - Short description that appears in email clients\nheadCSS (string, optional) - CSS that belongs in `\u003chead\u003e`. Note, email clients may strip this out.\nbgColor (string, optional) - The background color for the email. '#FFFFFF' is the default\nlang (string, optional) - ISO language code\ndir (string, optional) - Either 'ltr' or 'rtl'. 'ltr' is the default\n```\n\n### Using a Custom Template\n\nIf Oy's [default template](https://github.com/revivek/oy/blob/master/src/utils/HTML4.js) 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.\n\n```js\nconst generateCustomTemplate = (templateOptions) =\u003e {\n  return `\n    \u003c!doctype html\u003e\n    \u003chtml\u003e\n      \u003chead\u003e\n        \u003ctitle\u003e${templateOptions.title}\u003c/title\u003e\n      \u003c/head\u003e\n      \u003cbody\u003e\n        ${templateOptions.bodyContent}\n      \u003c/body\u003e\n    \u003c/html\u003e\n  `\n};\n\nconst template = Oy.renderTemplate(\u003cGettingStartedEmail /\u003e, {\n  title: 'Getting Started with Foo'\n}, (templateOptions) =\u003e generateCustomTemplate(templateOptions));\n```\n\n\n## Contributing\n\n```\n# Test\nnpm test\n\n# Compile from ES6 in src/ to ES5 in lib/\nnpm run compile\n```\n\nWe welcome contributions. If there's some information missing or ideas for how to make Oy better, please\nsend a pull request, file an issue, or email [1.vivekpatel@gmail.com](mailto:1.vivekpatel@gmail.com).\n\nThe best place to start would be in contributing new rules. [A running wishlist of email validation rules are in the Issues section](https://github.com/oysterbooks/oy/issues?q=is%3Aopen+is%3Aissue+label%3A%22rule+wishlist%22).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevivek%2Foy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frevivek%2Foy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevivek%2Foy/lists"}