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

Allow replacement function to access the relativePath #4

Open
alexeagle opened this issue Apr 8, 2015 · 5 comments
Open

Allow replacement function to access the relativePath #4

alexeagle opened this issue Apr 8, 2015 · 5 comments

Comments

@alexeagle
Copy link

This plugin is just what I need - except part of what I need to replace in my file is the relative path to the file being processed (for a <script> tag insertion based on the current directory).
Could you provide some config to make this possible?

Note, the processString method

ReplaceFilter.prototype.processString = function (string) {

takes the relativePath as a second parameter, so this doesn't seem too hard to wire up in that location (no change to applause)

@outaTiME
Copy link
Owner

outaTiME commented Apr 8, 2015

Hi pal,

Mmmm, i make some similar for grunt-replace ... i create special replacement tags it might be work ?? (but only available for grunt, but may can i port that)

https://github.com/outaTiME/grunt-replace#built-in-replacements

checkout ...

@alexeagle
Copy link
Author

FYI here is what I've patched:

ReplaceFilter.prototype.processString = function (string, relativePath) {
  var result = this.applause.replace(string);
  if (result === false) {
    // no replacements
    return string;
  }
  console.log(this.options.replaceWithPath);
  if (this.options.replaceWithPath) {
    result = this.options.replaceWithPath(relativePath, result);
  }
  return result;
};

@alexeagle
Copy link
Author

oops, didn't mean to close.

Would you like a PR?

@alexeagle alexeagle reopened this Apr 8, 2015
@outaTiME
Copy link
Owner

outaTiME commented Apr 8, 2015

mmm, for example what replaceWithPath function do in your code ??

@alexeagle
Copy link
Author

replaceWithPath: function(relativePath, result) {
    return result.replace('@@FILENAME_NO_EXT', relativePath.replace(/\.\w+$/, ''));
  }

So either the original file contained @@FILENAME_NO_EXT, or (in my case) it was written there by one of the other replace's.

alexeagle added a commit to alexeagle/broccoli-replace that referenced this issue Apr 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants