Skip to content

Commit

Permalink
rejig of directory layout for simplier code, and fixed edge case caus…
Browse files Browse the repository at this point in the history
…ing empty output. Closes remy#5
  • Loading branch information
remy committed May 15, 2011
1 parent 4be8404 commit 85b9cbd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "lib/uglify-js"]
path = lib/uglify-js
url = https://github.com/mishoo/UglifyJS.git
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ Turns your web page to a single HTML file with everything inlined - perfect for

## Installation

Check out a working copy of the source code with [Git](http://git-scm.com), or install `servedir` via [npm](http://npmjs.org). The latter will also install `inliner` into the system's `bin` path.
Check out a working copy of the source code with [Git](http://git-scm.com), or install `inliner` via [npm](http://npmjs.org) (the recommended way). The latter will also install `inliner` into the system's `bin` path.

$ git clone git://github.com/rem/inliner.git
$ npm install inliner -g

Alternatively, `inliner` can be run directly from the repository using Node:

$ node bin/inliner
$ ./bin/inliner

`inliner` uses a `package.json` to describe the dependancies, and if you install via a github clone, ensure you run `npm install` from the `inliner` directory to install the dependancies (or manually install [jsdom](https://github.com/tmpvar/jsdom "tmpvar/jsdom - GitHub") and [uglify-js](https://github.com/mishoo/UglifyJS "mishoo/UglifyJS - GitHub")).

## Usage

Expand Down
25 changes: 21 additions & 4 deletions inliner.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var URL = require('url'),
Buffer = require('buffer').Buffer,
jsdom = require('jsdom'),
jsp = require('./uglify-js/lib/parse-js'),
pro = require('./uglify-js/lib/process');
jsp = require('uglify-js/lib/parse-js'),
pro = require('uglify-js/lib/process');

function get(url, callback) {
var oURL = URL.parse(url),
Expand Down Expand Up @@ -232,7 +232,13 @@ var inliner = module.exports = function (url, options, callback) {
}
});

// console.log($scripts[$scripts.length - 1].parentNode.lastChild == $scripts[$scripts.length - 1]);
// edge case - if there's no images, nor scripts, nor links - we call finished manually
if (assets.links.length == 0 &&
assets.styles.length == 0 &&
assets.images.length == 0 &&
assets.scripts.length == 0) {
finished();
}

/** Inliner jobs:
* 1. get all inline images and base64 encode
Expand All @@ -250,4 +256,15 @@ var inliner = module.exports = function (url, options, callback) {
});
};

inliner.vesion = '0.0.1';
inliner.version = JSON.parse(require('fs').readFileSync('package.json').toString()).version;

if (!module.parent) {
if (process.argv[2] === undefined) {
console.log('Usage: inliner http://yoursite.com\ninliner will output the inlined HTML, CSS, images and JavaScript');
process.exit();
}

inliner(process.argv[2], function (html) {
console.log(html);
});
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"name": "inliner",
"version": "0.0.3",
"version": "0.0.4",
"description": "Utility to inline images, CSS and JavaScript for a web page - useful for mobile sites",
"homepage": "http://github.com/remy/inliner",
"main": "./lib/inliner",
"main": "inliner",
"keywords": ["mobile", "inline", "production", "build", "minify"],
"author": {
"name": "Remy Sharp",
"web": "http://github.com/remy"
},
"dependencies": {
"jsdom": ">= 0.2.0"
"jsdom": ">= 0.2.0",
"uglify-js": "1.0.1"
},
"repository": {
"type": "git",
"url": "git://github.com/remy/inliner.git"
},
"bin": {
"inliner": "./bin/inliner"
"inliner": "inliner.js"
}
}

0 comments on commit 85b9cbd

Please sign in to comment.