Skip to content

Instantly share code, notes, and snippets.

@tivac
Created September 30, 2013 22:09
Show Gist options
  • Save tivac/6771048 to your computer and use it in GitHub Desktop.
Save tivac/6771048 to your computer and use it in GitHub Desktop.
Experimenting with substack's node-trumpet project
/*jshint node:true */
"use strict";
var fs = require("fs"),
path = require("path"),
trumpet = require("trumpet"),
Uri = require("jsuri"),
tr = trumpet();
tr.pipe(process.stdout);
tr.selectAll("script", function(script) {
script.getAttribute("src", function(src) {
var url = new Uri(src),
host = url.host(),
file = path.join(__dirname, "test", "specimens", url.path());
// we only want relative uris
if(host || !fs.existsSync(file) || fs.statSync(file).size > 1024) {
return;
}
script.removeAttribute("src");
script
.createWriteStream()
.end(fs.readFileSync(file, { encoding : "utf8" }));
});
});
fs.createReadStream(__dirname + "/test/specimens/test.ejs").pipe(tr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment