Skip to content

Commit

Permalink
Main functionality implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
sethyuan committed May 11, 2013
1 parent ade2cf8 commit 5b75243
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 26 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -10,7 +10,9 @@ $ npm install picemb -g

## Example

## API
```bash
picemb input output
```

## License

Expand Down
50 changes: 50 additions & 0 deletions bin/picemb._js
@@ -0,0 +1,50 @@
#!/usr/bin/env node

var nomnom = require("nomnom");
var img = require("../lib/imgbase64.js");
var fs = require("fs");

var PROGNAME = require("../package.json").name;

var args = nomnom
.script(PROGNAME)
.options({
htmlfile: {
position: 0,
required: true,
help: "HTML file with img tags."
},
output: {
position: 1,
required: true,
help: "Output file."
},
version: {
abbr: "V",
flag: true,
callback: function() {
return PROGNAME + " " + require("../package.json").version;
},
help: "Show version and quit."
}
})
.parse();

try {
var html = fs.readFile(args.htmlfile, "utf8", _);
var outStream = fs.createWriteStream(
args.output, {flags: "w+", encoding: "utf8"});
var imgCrit = /(<img [^\/]*src=)(?:(["'])([^"']+)(["']))/g;
var res, offset = 0;
while ((res = imgCrit.exec(html)) != null) {
outStream.write(html.substring(offset, res.index));
outStream.write(res[1]);
outStream.write(res[2]);
outStream.write(img.imgToDataProtocol(res[3], _));
outStream.write(res[4]);
offset = imgCrit.lastIndex;
}
outStream.end(html.substring(offset));
} catch (e) {
console.error(e.message);
}
71 changes: 47 additions & 24 deletions bin/picemb.js
@@ -1,26 +1,49 @@
#!/usr/bin/env node
/*** Generated by streamline 0.4.11 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb,__trap=__rt.__trap,__tryCatch=__rt.__tryCatch; (function main(_) { var nomnom, img, fs, PROGNAME, args, html, outStream, imgCrit, res, offset; var __frame = { name: "main", line: 1 }; return __func(_, this, arguments, main, 0, __frame, function __$main() {
nomnom = require("nomnom");
img = require("../lib/imgbase64.js");
fs = require("fs");

var nomnom = require("nomnom");
var img = require("../lib/imgbase64.js");
var fs = require("fs");

var args = nomnom
.script("picemb")
.options({
imgpath: {
position: 0,
required: true,
help: "Image to convert to data protocol."
},
version: {
abbr: "V",
flag: true,
callback: function() {return "picemb " + require("../package.json").version;},
help: "Show version"
}
}).parse();

img.imgToDataProtocol(args.imgpath, function(err, text) {
if (err) return console.error(err);
console.log(text);
});
PROGNAME = require("../package.json").name;























args = nomnom.script(PROGNAME).options({ htmlfile: { position: 0, required: true, help: "HTML file with img tags." }, output: { position: 1, required: true, help: "Output file." }, version: { abbr: "V", flag: true, callback: function() { return ((PROGNAME + " ") + require("../package.json").version); }, help: "Show version and quit." } }).parse(); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$main() {


return fs.readFile(args.htmlfile, "utf8", __cb(_, __frame, 32, 13, function ___(__0, __1) { html = __1;
outStream = fs.createWriteStream(args.output, {
flags: "w+", encoding: "utf8" });
imgCrit = /(<img [^\/]*src=)(?:(["'])([^"']+)(["']))/g;
offset = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$main() { __more = false;
var __4 = ((res = imgCrit.exec(html)) != null); if (__4) {
outStream.write(html.substring(offset, res.index));
outStream.write(res[1]);
outStream.write(res[2]);
return img.imgToDataProtocol(res[3], __cb(_, __frame, 41, 20, function ___(__0, __2) { outStream.write(__2);
outStream.write(res[4]);
offset = imgCrit.lastIndex; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$main() {

outStream.end(html.substring(offset)); __then(); }); }, true)); }); })(function ___(e, __result) { __tryCatch(_, function __$main() { if (e) {

console.error(e.message); __then(); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); });}).call(this, __trap);
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -27,6 +27,7 @@
"license": "MIT",
"readmeFilename": "README.md",
"dependencies": {
"nomnom": "latest"
"nomnom": "1.x",
"streamline": ">=0.4.9 <1.0"
}
}

0 comments on commit 5b75243

Please sign in to comment.