Skip to content

Instantly share code, notes, and snippets.

@danfinlay
Created August 18, 2013 03:35
Show Gist options
  • Select an option

  • Save danfinlay/6259778 to your computer and use it in GitHub Desktop.

Select an option

Save danfinlay/6259778 to your computer and use it in GitHub Desktop.
How does one use trumpet to inject a series of individual files into a page? I feel like the asynchronous nature of streams means these extensions may be loaded unreliably, is there a more correct way?
fs.createServer(function(req, res){
var extensionTrumpet = trumpet();
extensionTrumpet.selectAll('#frameInitScript', function(elem){
var writeOutStream = elem.createWriteStream();
for(var i = 0; i < extensions.length; i++){
fs.createReadStream(__dirname + '/../site/blocks/'+extensions[i]+'.js').pipe(writeOutStream);
}
});
fs.createReadStream(__dirname+'/../site/frame.html')
.pipe(extensionTrumpet).pipe(res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment