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

Add support for multiple comment formats #10

Open
JacobDB opened this issue Feb 20, 2017 · 1 comment
Open

Add support for multiple comment formats #10

JacobDB opened this issue Feb 20, 2017 · 1 comment

Comments

@JacobDB
Copy link

JacobDB commented Feb 20, 2017

Took me a while to figure out why this wasn't working with my PHP files, but I realized it's because PHP wasn't being recognized as using "HTML-style" comments. I rectified it by using the commentStart and commentEnd parameters, but then I got thinking.

What if I needed to remove blocks of HTML code in one part of a PHP file, and PHP code in another part? I suppose I could wrap the HTML parts in <?php /*removeIf(condition)*/ ?> ... <?php /*endRemoveIf(condition)*/ ?>, but then I'd be stuck with an empty <?php ?>, which isn't ideal.

Additionally, what if I want to search multiple file types for the same condition? For example, remove all PHP, HTML, JS, and CSS for a module. I'd have to duplicate a lot of code in my task, saying "check this format, and then this format, and then this one," which again, isn't ideal.

I'd really like to see an option to set commentStart and commentEnd as arrays, something like the following:

gulp.task("init", function () {
    return gulp.src(src + "/**/*")
        // remove login HTML code if --remove --login is passed
        .pipe(gulpif(argv.remove && argv.login, removeCode({no_login: true, commentStart: ["<!--", "/*", "//"], commentEnd: ["-->", "*/", ""]})))
        // return to the source directory
        .pipe(gulp.dest(src));
});

That way you could parse multiple file types at once.

@JacobDB
Copy link
Author

JacobDB commented Jun 8, 2017

@crissdev any chance you could implement this? I've found a workaround, but I have to add multiple calls to the module with differing names, which seems very inefficient.

.pipe(plugins.remove_code({login_html: plugins.argv.remove && plugins.argv.remove.includes("login") ? true : false, commentStart: "<!--", commentEnd: "-->"}))
.pipe(plugins.remove_code({login_php: plugins.argv.remove && plugins.argv.remove.includes("login") ? true : false, commentStart: "/*", commentEnd: "*/"}))
.pipe(plugins.remove_code({login_css: plugins.argv.remove && plugins.argv.remove.includes("login") ? true : false, commentStart: "/*", commentEnd: "*/"}))

crissdev added a commit that referenced this issue Apr 27, 2018
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

1 participant