0.1.2 • Published 7 years ago

styliner-get v0.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

styliner-get

styliner-get is a binary that you can execute from a shell or any programming language to inline your external and <style /> CSS into your HTML document. It is just a simple wrapper around the styliner npm module, all of the CSS inlining is done by that package, styliner-get makes it possible to use its functionality in environments other than Node.

Why

Because you need to inline your CSS when sending HTML emails.

Primitive

As of right now styliner-get is primitive and does not provide all the options that the styliner module does, only the very basic functionality is there, which will be sufficient for most use cases. It still needs to be thoroughly tested so use it thoughtfully, developers are welcome to contribute. Because this package is being developed to provide all the features of styliner, be sure to only update to minor and patch releases as you may need update your code that calls styliner-get when a new major version is released.

Install

You'll install styliner-get globally using npm so that you can execute it from anywhere. You may need to install it using sudo.

npm install --global styliner-get
sudo install --global styliner-get

Usage

To use styliner-get once you've installed it you have to make a call to the styliner-get binary on your system. How you do this depends on the environment that you are calling it from. In any case you have to pass 2 arguments to the binary when you call it.

The arguments:
  1. The HTML source that has CSS to be inlined.
  2. A directory path on your system that will be used as the base directory that relative hyperlinks in your HTML source will resolve to.
Let's say your HTML source looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Styliner</title>
  <link rel="stylesheet" href="css/style.css">
  <link rel="stylesheet" href="css/morestyles.css">
</head>
<body>
  <p>I'm a p tag. After I've been run through styliner-get my styles from the external css files will be inlined on my style attribute and those link tags above will not be present in the returned HTML.</p>
</body>
</html>

You would store that HTML string in a variable, html. You pass the html variable as your first argument to styliner-get.

And you pass the filesystem directory path that the css directory resides in as the second argument to styliner-get so that the styliner module can resolve those relative hrefs in the link tags.

/home/yourusername/myproject

Examples

Node
var html = htmlSourceThatIGotFromSomewhere;

var spawn = require('child_process').spawn;
var stylinerGet = spawn('styliner-get', [html, "/home/yourusername/myproject"]);

stylinerGet.stdout.on('data', (data) => {
  //data contains the HTML with the inlined CSS. Send that email.
});
Python
from subprocess import call

html = htmlSourceThatIGotFromSomewhere

data = call(["styliner-get", html, "/home/yourusername/myproject"])

#data contains the HTML with the inlined CSS. Send that email.
PHP
$html = $htmlSourceThatIGotFromSomewhere;

$data = shell_exec("styliner-get '{$html}' '/home/yourusername/myproject'");

//$data contains the HTML with the inlined CSS. Send that email.
0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago