-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
html_stream wording suggests multiple .loud elements #105
Comments
I absolutely agree. Was going to make the same suggestion. The example solution only uppercases the first matching element, and the input html only has a single loud class to test with. |
Yes I also noticed this and agree! Being adventurous, I wrote to try and handle for multiple elements. But, when I add another .loud element to the HTML input it fails with Error: write after end when it tries to transform the second element. var trumpet = require('trumpet');
var through = require('through2');
var upperCase = function(buffer, enc, next){
this.push(buffer.toString().toUpperCase());
next();
}
var upperStream = through(upperCase); //create a transform stream for upperCase
var tr = trumpet(); //create new trumpet stream
process.stdin.pipe(tr); //pipe the input into trumpet
//find elements and transform them
tr.selectAll('.loud', function (elem){
var rs = elem.createReadStream();
var ws = elem.createWriteStream();
rs.pipe(upperStream).pipe(ws); //transform the stream
});
tr.pipe(process.stdout); //pipe trumpet back to output @max, if can you please help me by pointing out how I can fix to handle all the elements? |
@max - all good I figured it out - I need to move the deceleration of upperStream and upperCase function into the selectAll event handler. Corrected code: var trumpet = require('trumpet');
var through = require('through2');
var tr = trumpet(); //create new trumpet stree
process.stdin.pipe(tr); //pipe the input into trumpet
//find elements and transform them
tr.selectAll('.loud', function (elem){
var upperCase = function(buffer, enc, next){
this.push(buffer.toString().toUpperCase());
next();
}
var upperStream = through(upperCase); //create a transform stream for upperCase
var rs = elem.createReadStream();
var ws = elem.createWriteStream();
rs.pipe(upperStream).pipe(ws); //transform the stream
});
tr.pipe(process.stdout); //pipe trumpet back to output |
This discussion could be complemented by 3 pull requests doing basically the same as suggested:
Although #69 should be picked as a primary change request being first, #146 looks most thorough, readable and it's the only pull request with no conflicts at the moment. |
I'm closing since this it's stale from some time ago. We are planning to update |
I was trying to come up with a solution that would uppercase multiple
.loud
elements in any given HTML input. That proved to be quite a bit more difficult than simply transforming a single element. Perhaps the problem statement can be reworded here.The text was updated successfully, but these errors were encountered: