Giter Club home page Giter Club logo

inker's Introduction

Inker - transaction & marketing email development workflow

Basics

Big tables mess no more. Inker provides all the mechanics for creating sane email templates and keeping a clean workflow.

Documentation http://posabsolute.github.io/inker/

Inker is :

Coding

  • Built on top of Zurb Ink
  • Sane CSS components structure with sass
  • Sane HTML components structure with nunjucks
  • Localization
  • Auto generate template to HTML documents with inlined CSS
  • Auto deployment on litmus for testing
  • Auto deployment to any email address for testing

REST API Email Delivery service

  • Asyncronous for a warp speed response (you can use it in sync mode too)
  • Generate emails with custom data on the fly
  • Integrate all major email delivery providers, just put you account infos
  • Failover, when one goes down we redirect the request to another provider
  • Logs! hipchat, slack, logtenries, winston, push notifications with push bullet, are all in but you can easily add your own too

Getting started

Inker requires npm & grunt to be already installed.

git clone https://github.com/posabsolute/inker.git
gem install premailer
cd inker && npm install

You have now everything you need to use inker. Your first stop would be the example in src/templates to help you get started.

Available grunt commands

  • grunt watch - Watch source folder for changes & generate dist files
  • grunt css - Build CSS
  • grunt html - Build HTML templates
  • grunt build - Build css & html
  • grunt connect *- test emails in your browser from the root folder (http://0.0.0.0:8555/)
  • grunt email - Send a test email to any email inbox
  • grunt litmus - Send a test email to litmus

CSS with Inker

Inker use Zurb Ink responsive css framework, everything in Ink is available in inker, please refer to their documentation. Inker also uses the meta framework ITCSS for the files and folders' structure. Better explained by this image. The css can be found in src/css

base.scss is your base CSS file importing all needed files for inker, if you add a css component you must import it in base.scss.

It is important to note that since we inline style to html nodes it makes no sense to pick and choose components you want to use as it will make no differences on the file size in the end

Responsive

Responsive rules are in the folder 8_trumps, please note that these rules are added to the document's head instead of inlined using data-ignore="ignore" in the html templates.

Ignore css inlining

<!-- external styles -->
<link rel="stylesheet" data-ignore="ignore"  href="../css/style.css" />

<!-- embedded styles -->
<style data-ignore="ignore">
 /* styles here will not be inlined */
</style>

Adding new themes

Open 7_themes, you will see there is already a folder called sidebarhero used for the sidebar hero template. Add a new folder in 7_themes for your template, your main css file will be automatically generated in dist/css/[your folder].

Then in your html, use:

  {% block theme_css %}<link href="../../css/sidebarhero/sidebarhero.css" media="all" rel="stylesheet" type="text/css" />{% endblock %}

HTML with inker

Inker uses Mozilla Nunjucks to build html templates, please see nunjucks' documentation for more information on how you can take inker even further.

Inker as an html component stucture that uses nunjucks macros. Example of component:

{% macro button(label='default', link='#', class='', align='left') %}
  <table class="button {{class}}" align="{{align}}">
    <tr>
      <td>
        <a href="{{link}}">{{label}}</a>
      </td>
    </tr>
  </table>
{% endmacro %}
// Import the component in the base.html file in html-components folder.
{% from "/html-components/component.button.html" import button %}

Usage in html template :

{{ button('Go to google', 'http://www.google.com', 'button-green', 'left'); }}

When creating new components, remember to add them to the base.html file situated in src/html-components

Creating new html templates

Open the template's folder, you should see a folder sidebar_hero, add your own folder here. Please refer to sidebar_hero for a complete example.

Example of base template

{% extends "/html-components/base.html" %}
  {% block main_css %}
    <link href="../../css/main.css" media="all" rel="stylesheet" type="text/css" />
  {% endblock %}
  {% block theme_css %}
    <link href="../../css/sidebarhero/sidebarhero.css" media="all" rel="stylesheet" type="text/css" />
  {% endblock %}

  {% block responsive_css %}
    <link href="../../css/responsive.css" media="all" data-ignore="ignore" rel="stylesheet" type="text/css" />
  {% endblock %}

  {% block meta_title %}
    Email title in document head
  {% endblock %}

{% block mainContent %}
  {% block header %}
    {% include "/templates/sidebar_hero/header.html" %}
  {% endblock %}
  {% block content %}
    {% include "/templates/sidebar_hero/content.html" %}
  {% endblock %}
{% endblock %}

Inker with your back-end templating engine & application

There is a bit of a duality with Inker, it uses a templating engine to generate templates but must not use it to render personalized data on first pass so that it can be generated by another templating engine or by the server.

Passing data and custom template logic by string

If you have a conflict with nunjucks' template syntax, you can pass your variables and custom logics as strings likewise :

  <h4>{{ '{{ name }}' }} last step and you're done!</h4>

  <p>
    {{ '{% for item in loop %}' }}
    {{ '{{ item }}' }} &nbsp;
    {{ '{% endfor %}' }}
  </p>

In the final email template, this will look like :

  <h4>{{ name }} last step and you're done!</h4>

  <p>
    {% for item in loop %}
      {{ item }}
    {% endfor %}
  </p>

Using a custom syntax

Inker enables you to use a custom syntax to not interfere with your templating engine of choice. If you do use a custom syntax, you will have to replace the current implementation with the new syntax.

nunjucks: {
  options: {
    tags : {
      blockStart: '<%',
      blockEnd: '%>',
      variableStart: '<$',
      variableEnd: '$>',
      commentStart: '<#',
      commentEnd: '#>'
    }
  }
}

Inker with dynamic custom data

Inker can use json files as a source of dynamic data. Please note that you can also use the provided rest api to test custom data.

This is a built-in feature of grunt-nunjucks-2-html.

nunjucks: {
  options: {
    data: grunt.file.readJSON('data.json')
  }
}

Included components

Current list of implemented components. (I am always looking to add more components to inker.)

Buttons

Options :

  • Label
  • Link
  • Class to add
  • Alignment

Usage :

button('Go to google', 'http://www.google.com', 'button-green', 'left');

Render :

  <table class="button button-green" align="left">
    <tr>
      <td>
        <a href="http://www.google.com">Go to google</a>
      </td>
    </tr>
  </table>

Progress Bar

Options:

  • width of bars
  • progress
  • label
  • Class to add

Usage :

progressbar('100%', 70, 'Your progress so far', 'progressbar-green');

Render :

  <table class='progressbar progressbar-green' cellpadding="0" cellspacing="0" width="100%">
      <tr>
          <td class='foreground' style='' width="70%">
              Your progress so far
          </td>
          <td class="background" width="30%">
              &nbsp;
          </td>
      </tr>
  </table>

Video

Please refer to campaign monitor chart to see which email client supports video, fallback to an image.

Options :

  • width
  • height
  • video_src
  • video_link
  • video_image_placeholder
  • class

Usage :

video(320, 176, 'http://www.google.com', 'http://www.google.com', 'http://www.google.com', 'video-big');

Render :

  <div class="video_holder video-big">
      <video width="320" height="176" controls>
          <source src="{{video_src}}.mp4" type="video/mp4">
          <source src="{{video_src}}.ogg" type="video/ogg">
            <a href="{{video_link}}" ><img height="176"
              src="{{video_image_placeholder}}" width="320" /></a>
      </video>
  </div>

Image Caption

Options :

  • Label
  • Width
  • Class
  • Align

Usage :

caption('This is a cat', '320px', 'caption-red', 'left');

Render :

  <table class="caption caption-red" cellpadding="0" cellspacing="0" width="320px" border="0", align='left'>
      <tr>
          <td align="center">
              <img src="http://placekitten.com/g/300/300" alt="" />
              <div>This is a cat</div>
          </td>
      </tr>
  </table>

Panel

Options :

  • Label
  • size (default: twelve)
  • Class

Usage :

panel('This is a panel', 'twelve', 'panel-red');

Render :

  <table class="twelve panel-red columns">
    <tr>
      <td class="panel">

        This is a panel

      </td>
      <td class="expander"></td>
    </tr>
  </table>

Localization

Inker can generate for the same template multiple language. Strings are defined in the folder locales in the Yaml format. Don't forget that inker pre-generate templates, it's not generated on the fly.

You can set default rendering languages in the gruntfile.js in the nunjucks section.

nunjucks: {
  options:{
    langs : ["en_US"],

Follow the same conventions while creating your localization files, in this case, locales/en_US.yml.

Sending a test email to your inbox

Inker uses grunt-nodemailer to send tests. By default, it sends a test for all files that are in the output folders, you can easily change that in gruntfile.js.

However a better way to use it would be to change the path directly from the grunt command. This makes it possible to send tests really fast with different templates.

// Override default src provided in gruntfile
grunt email --fileSrc=dist/output/example.html

Config example :

nodemailer: {
    options: {
      transport: {
        type: 'SMTP',
        options: {
          service: 'Gmail',
          auth: {
            user: '[email protected]',
            pass: 'BLAH'
          }
        }
      },
      recipients: [
        {
          email: '[email protected]',
          name: 'Jane Doe'
        }
      ]
    },
    src: ['dist/output/*.html']
},

Using litmus

Grunt litmus documentation.

Overriding default files sent to litmus

grunt litmus:dist/output/sidebar_hero/index.html

Default config

The most used email clients are already set in the config file.

litmus: {
  test: {
    src: ['email.html'],
    options: {
      username: 'username',
      password: 'password',
      url: 'https://yourcompany.litmus.com',
      clients: [
        //gmail
        'gmailnew', 'ffgmailnew', 'chromegmailnew',
        // outlook
        'ol2002', 'ol2003', 'ol2007', 'ol2010', 'ol2011', 'ol2013',
        // hotmail
        'outlookcom', 'ffoutlookcom', 'chromeoutlookcom',
        //Yahoo
        'chromeyahoo',
        //applemail
        'appmail6',
        //mobile
        'iphone6plus', 'iphone6', 'iphone5s', 'androidgmailapp', 'android4', 'ipad',
        // spam check
        'messagelabs'
      ]
    }
  }
},

Email REST API

Inker comes with a nodejs rest api that can handle rendering templates with custom variables and send emails throught SMTP to any email provider.

There is a public Postman collection for your convenience for testing the api locally. https://www.getpostman.com/collections/f37b94b5cf18a574e32a

Starting the server

Install all dependencies

npm install
cp src/server/configs/_serviceAuth.js src/server/configs/serviceAuth.js
cp src/server/configs/_configs.js src/server/configs/configs.js

Start the server

node src/server/server.js

Authentication

The server has a basic auth system. It expects a token for each request. This token is set in /src/server/config.js

Default :

X-Authorization-Token : asd98a7s9898asdaSDA(asd987asda*(&*&%))

Configs

API Templates rendering

The API also uses nunjucks to render custom variables. Remember that since we use the same rendering engine (nunjucks) for both front-end & server side, you must use strings in your template to add variables and custom template logics.

Example:

  <h4>{{ '{{ name }}' }} last step and you're done!</h4>

  <p>
    {{ '{% for item in loop %}' }}
    {{ '{{ item }}' }} &nbsp;
    {{ '{% endfor %}' }}
  </p>

You can configure the template syntax in /src/server/config.js.

"GET /templates/folder/template"

Base path is dist/output

Example:

"GET /collections/:folders/templates/:filename?name=Cedric&loop[]=1&loop[]=2&loop[]=3"
// with localization
// Example with french
"GET /collections/:folders/templates/:filename/locale/fr_CA?name=Cedric&loop[]=1&loop[]=2&loop[]=3"

API Email sending

The api can send emails to a variety of SMTP services, MailGun, Mandrill, SendGrig, Gmail, etc. You can see the full list in /src/server/serviceAuth.js

Example :

"POST /email"
// Post data
{
  "data" : {
    "collection": "data_example", // required, folder(s) in output
    "template": "index", // required, template filename
    "locale" : "en_US", // optional, default to en_US
    "variables": {
      "name":"Cedric",
      "loop": ["1","2","3"]      
    }
  },
  "options" : {
    "from": "sender@address",
    "to": "[email protected]",
    "subject": "hello",
    "text": "hello world!"
  },
  // optional, default to 'service' set in config.js
  "service" : {
    "name":"MailGun"
  }
}

Email delivery service Authentication

You must add your credentials in /src/server/configs.providers.auth.js

Failover Email Delivery Provider

You can set a default failover service provider in /src/server/configs.js

// main mailing service used to send email
"service" : "MailGun",
// failover service when main service is down
"failOver" : "SendGrid",

Logs

By default Inker can log errors hapenning on the service & alert you when one your main email sending provider is down, when an application request an unexistent template or when there is an error in a template.

Default Services used is defined in /src/server/configs.js

// active logs
"sendLogs" : ['hipchat','logentries'],
// logs configs
"logs" : {
  "hipchat":{
    "room" : "HIPCHAT_ROOM_ID",
    "token" : "MY_TOKEN"
  },
  "logentries" : {
    "token" : "MY_TOKEN"
  }
}

Adding a log provider

You can add a log prodider in /src/server/configs.logs.js. Implementation example:

"hipchat": {
    "level":2,
    // Module required for the log provider 
    "module":"node-hipchat",
    // Executed after the module is loaded in
    // Generally used to instanciate the provider
    "afterRequire": function(loggers){
      loggers.hipchatLog = new loggers.hipchat(configs.logs.hipchat.token);
    },
    // Actual log function
    // loggers is passed bavk & contains all the logs providers.
    log : function(loggers, type, messageText, messageJson){
      var params = {
          room: configs.logs.hipchat.room,
          from: 'Email Server',
          message: messageText,
          color: 'yellow'
        };

      loggers.hipchatLog.postMessage(params, function(data) { });
    }
},

Special thanks

Thanks to Litmus for providing free email client testing for this project.

Contributions

I'm always happy to accept contributions, I'm currently looking for more components and examples, but please follow ITCSS guidelines, and please test your new components in the most used email clients.

Licence

The MIT License (MIT)

Copyright (c) 2014 Cedric Dugas http://www.position-absolute.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

inker's People

Contributors

dustinhorton avatar mikechaos avatar posabsolute avatar

Watchers

 avatar

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.