From 070fc331e70179e12883d17deceb8fc57c693eef Mon Sep 17 00:00:00 2001 From: Alexandre Gigliotti Date: Wed, 5 Aug 2015 15:36:27 -0700 Subject: [PATCH] Added README and .travis files. --- .travis.yml | 3 ++ README.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 .travis.yml create mode 100644 README.md diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2197832 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "node" diff --git a/README.md b/README.md new file mode 100644 index 0000000..e042c47 --- /dev/null +++ b/README.md @@ -0,0 +1,88 @@ +# inline-html + +Embed local assets into an HTML document. + +[![npm](https://img.shields.io/npm/v/inline-html.svg)]() +[![Travis](https://img.shields.io/travis/panosoft/inline-html.svg)]() +[![David](https://img.shields.io/david/panosoft/inline-html.svg)]() +[![npm](https://img.shields.io/npm/dm/inline-html.svg)]() + +## Installation + + npm install inline-html + +## Usage + +This: + + var inlineHtml = require('inline-html'); + + inlineHtml('path/to/file.html').then(function (html) { + ... + }); + +Turns this: + + + +
+ + +Into this: + + + +
+ + +Where: + +`main.less` + + @import (inline) 'main.css'; + div { background-image: url('path/to/file'); } + +`main.css` + + @font-face { src: url('path/to/file'); } + +## API + +### inlineHtml( filename [, options] ) + +Reads an HTML file and inlines all of the following that reference local assets: + +- LESS stylesheets - The LESS is compiled and the result is inlined within a ` + +- CSS url data types - The reference path is replaced with a datauri. These can be used in linked stylesheets, style elements, and element style attributes. + + url('file.ext') -> url('data:...') + +- Images - The source path is replaced with a datauri. + + -> + +Returns a `Promise` that is fulfilled with an `html` string or a `results` object depending on the value of `options.verbose`. + +#### Arguments + +- `filename` - The filename of the HTML file to be inlined. Relative file paths are resolved relative to the filename directory. +- `options` + - `less` - An object containing LESS options to pass to the less compiler. Defaults to `{}`. + - `verbose` - A boolean that determines the promises fulfillment value. Defaults to `false`. + - `true`: promise is resolved with an instance of `Results` + - `false`: promise is resolved with `html` + +#### Results object + +- `html` - The inlined html +- `files` - An array of filenames of the inlined local assets.