Skip to content
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

Cache parsed html/xml #7

Closed
w0rm opened this issue Dec 23, 2014 · 7 comments
Closed

Cache parsed html/xml #7

w0rm opened this issue Dec 23, 2014 · 7 comments

Comments

@w0rm
Copy link
Contributor

w0rm commented Dec 23, 2014

It would be great if gulp-cheerio cached parsed html/xml in gulp file objects so it could be reused in other gulp plugins e.g. in my gulp-svgstore.

@knpwrs
Copy link
Owner

knpwrs commented Dec 24, 2014

Care to elaborate with an example? I'm not quite sure I understand.

@w0rm
Copy link
Contributor Author

w0rm commented Dec 24, 2014

@KenPowers sure,

lets say I would like to use gulp-cheerio to modify svg before it is passed to gulp-svgstore, I would write it something like this:

gulp.src(config.SRC_SVG_LIST)
        .pipe(cheerio({
            run: function ($) {
                $('svg').attr('fill', '#666666');
            }
        }))
        .pipe(svgstore())

This means that every file will go through cheerio parser when it is transformed by gulp-cheerio, and then it will have to be parsed with cheerio again in gulp-svgstore. My idea is to cache $ and put it into the vinyl file object, e.g. file.$ = $, then in my plugin I can simply check if its there and use it instead of cheerio.load.

@w0rm
Copy link
Contributor Author

w0rm commented Dec 24, 2014

Same goes in the other direction, lets say I would like to transform the result of gulp-svgstore with gulp-cheerio, e.g.

gulp.src(config.SRC_SVG_LIST)
        .pipe(svgstore())
        .pipe(cheerio({
            run: function ($) {
                $('svg').attr('style', 'display:none');
            }
        }))

I can also cache file.$ so it may be reused in gulp-cheerio.

@knpwrs
Copy link
Owner

knpwrs commented Dec 30, 2014

I like the idea but I think claiming file.$ is a little greedy since Cheerio, while popular, hasn't reached defacto standard status like jQuery has. How about file.cheerio?

@w0rm
Copy link
Contributor Author

w0rm commented Jan 2, 2015

Sure, file.cheerio is fine. Will implement this in gulp-svgstore on this weekend.

@knpwrs
Copy link
Owner

knpwrs commented Jan 2, 2015

Published version 0.4.0 to npm. This version also defines cheerio 0.* as a peer dependency, I suggest you do the same in gulp-svgstore

@knpwrs knpwrs closed this as completed Jan 2, 2015
@w0rm
Copy link
Contributor Author

w0rm commented Jan 3, 2015

@KenPowers good, I just published gulp-svgstore 4.0.0 with examples of using with gulp-cheerio instead of hacky transformSvg callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants