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

Autoremove #1

Open
prayerslayer opened this issue Sep 25, 2015 · 0 comments
Open

Autoremove #1

prayerslayer opened this issue Sep 25, 2015 · 0 comments
Labels

Comments

@prayerslayer
Copy link
Member

So detecting mismatches between classes in styles and templates works. The next nice feature to have would probably be an optional autoremoval.

This needs probably separate plugins as it would work roughly like this:

function symdiffHtmlAutoremove(fileContent, classesToRemove) {
  var ast = htmlParser.parse(fileContent);
  walkAst(function(node) {
    if (node.type === CLASS_ATTR) {
      node.content = node.content.replace(classesToRemove, '');
    });
  });
  return htmlParser.stringify(ast); // also unclear if that exists already for various parsers
});

Now the question is what to do with the cleaned up CSS string. Obviously we would save it somewhere. For file handling we have the task runner plugins. So it seems to be the simplest solution to add a new configuration to them:

// gulp-symdiff, that is
symdiff({
  templates: [symdiffHtml],
  css: [symdiffCss],
  autoremove: [symdiffHtmlAutoremove (..optional other autoremovers)]
})

We can just feed all file contents to all autoremovers! One will work and the output we save to the destination folder. If none works, we just copy the file there. If more than one works, we make a lot of noise.

Details to be clarified:

  • Should the autoremover throw if it can't parse the file or return null/empty string? Not sure yet of the benefits.
  • People organize their project folders sometimes in crazy ways, so the file destination definition has to be very flexible. Look at how others do it. Do we have to care about this actually? In Gulp we would just emit the clean string and be done.
  • Check which parsers out there implement ast->string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant