Giter Club home page Giter Club logo

notifme-template's Introduction

Notif.me

Template plugin for Notif.me SDK.

npm-status js-standard-style flow-typed license

Features

  • All your notifications in one place — Define all your email, sms, push, and webpush templates in one folder 👍

  • Choose your template enginefacebook/react, mozilla/nunjucks, handlebars.js, mustache.js, lodash, underscore, marko, doT, swig, linkedin/dustjs, twig.js, ejs... and many more. Literally the one you want 💃

  • Complete control — No magic: you define all the behaviours you need (layouts, CSS preprocessor...) 🚀

  • No dependencies — Lightning fast installation ⚡

  • Localization — Easily implement i18n/l10n for all your notifications 🌐

  • CSS inlining — Add Juice to your dependencies and the CSS in your emails will automatically be inlined 🎀

  • MIT license — Use it like you want.

Getting Started

$ yarn add notifme-template
// Example with nunjucks template engine ($ yarn add nunjucks)
const nunjucks = require('nunjucks')
const getRenderer = require('notifme-template')

const render = getRenderer(nunjucks.renderString, './templates')

const data = {user: {firstname: 'John', email: '[email protected]', ...}}
render('welcome', data, 'en-US').then((notification) => {
  // Send the notification on its channels
})
// ./templates/welcome.js
module.exports = () => ({
  name: 'welcome',
  title: 'Welcome {{user.firstname}}',
  version: 1,
  channels: {
    sms: {
      from: '{{smsFrom}}',
      to: '{{user.phone}}',
      text: "Hi {{user.firstname}}, we're very happy to welcome you on board!"
    },
    email: {
      from: '{{emailFrom}}',
      to: '{{user.email}}',
      subject: 'Welcome {{user.firstname}}',
      html: `{% extends "templates/_layouts/email-transactional.html" %}
        {% block content %}
          Hi {{user.firstname}},<br><br>
          We're very happy to welcome you on board.<br><br>
          See you soon!
        {% endblock %}`
    },
    push: {
      registrationToken: '{{user.pushToken}}',
      title: 'Welcome {{user.firstname}}',
      body: "Hi {{user.firstname}}, we're very happy to welcome you on board"
    }
  },
  sampleData: {
    smsFrom: 'Notifme',
    emailFrom: '"David, Notif.me team" <[email protected]>',
    user: {
      firstname: 'John',
      email: '[email protected]',
      phone: '+15000000001',
      pushToken: 'xxxxx'
    }
  }
})

See a complete working example for more details.

How to use

Constructor options

const getRenderer = require('notifme-template')

const render = getRenderer(/* renderer, folder, options */)
Argument name Type Required Description
renderer Function true Template engine function to use. It must implement (templateName: string, data: Object) => string
folder string true The path to the folder containing all your templates.
options Object false See options definition.

This returns the render function documented below.

Template declaration

project/
│
└───templates/    <= you can place this folder where you want and choose its name
    │   template1.js
    │
    └───template2/
        │   index.js

With the structure above, you will have two templates template1 and template2. notifme-template makes a dynamic require require(`${path.resolve(folder, templateName)}`) the first time you call them.

Each template must export a function implementing: (lang: string) => TemplateType | Promise<TemplateType>. See TemplateType definition and examples for more details.

render method

render(/* templateName, data, lang */).then((notification) => {
  // Send the notification on its channels
})
Argument name Type Required Description
templateName string true The template name to use.
data Object true Data to use when rendering the notification.
lang string false User language.

This returns a Promise resolving with the rendered template.

Contributing

js-standard-style flow-typed

Contributions are very welcome!

To get started: fork this repository to your own GitHub account and then clone it to your local device.

$ git clone [email protected]:[YOUR_USERNAME]/notifme-template.git && cd notifme-template
$ yarn install

Need Help? Found a bug?

Submit an issue to the project Github if you need any help. And, of course, feel free to submit pull requests with bug fixes or changes.

notifme-template's People

Contributors

bdav24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

notifme-template's Issues

not really usable with pug

This isn't really usable with pug since the render function tries to render every property of the template, including for example name, title, etc.
However, a simple string 'title' rendered with pug.render leads to <title></title>.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

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.