Closed spacewindow closed 9 years ago
Hi @spacewindow,
There's a test for this so it should be working.
When you say "DOESN'T WORK", what output are you getting? Perhaps you could post your gruntfile configuration for the includereplace task. I've just run a test to check and the html comment should work with a gruntfile like:
module.exports = function (grunt) {
grunt.initConfig({
includereplace: {
prefixsuffix: {
options: {
prefix: '<!-- @@',
suffix: ' -->'
},
src: 'test.html',
dest: 'dist/',
expand: true,
cwd: __dirname
}
}
});
grunt.loadNpmTasks('grunt-include-replace');
grunt.registerTask('default', 'includereplace');
};
For the css comment style prefix/suffix you'll need to escape the string like so:
module.exports = function (grunt) {
grunt.initConfig({
includereplace: {
prefixsuffix: {
options: {
prefix: '\\/\\* ',
suffix: ' \\*\\/'
},
src: 'test.html',
dest: 'dist/',
expand: true,
cwd: __dirname
}
}
});
grunt.loadNpmTasks('grunt-include-replace');
grunt.registerTask('default', 'includereplace');
};
Since the prefix and suffix are added to the regex string like this:
new RegExp(options.prefix + 'include\\(\\s*["\'](.*?)["\'](,\\s*({[\\s\\S]*?})){0,1}\\s*\\)' + options.suffix);
Thanks so much alan - double escape on those stars and slashes. When I say 'doesn't work' I get no error (because the string is simply bit found) and the 'include' string is not replaced. That's all.
With this fix it totally works. Thanks for the quick response and the very useful tool.
R
Sent from my iPhone
On 5 Feb 2015, at 7:21 pm, Alan Shaw notifications@github.com wrote:
Hi @spacewindow,
There's a test for this so it should be working.
When you say "DOESN'T WORK", what output are you getting? Perhaps you could post your gruntfile configuration for the includereplace task. I've just run a test to check and the html comment should work with a gruntfile like:
module.exports = function (grunt) { grunt.initConfig({ includereplace: { prefixsuffix: { options: { prefix: '' }, src: 'test.html', dest: 'dist/', expand: true, cwd: __dirname } } }); grunt.loadNpmTasks('grunt-include-replace'); grunt.registerTask('default', 'includereplace'); }; For the css comment style prefix/suffix you'll need to escape the string like so:
module.exports = function (grunt) { grunt.initConfig({ includereplace: { prefixsuffix: { options: { prefix: '\/\ ', suffix: ' \\/' }, src: 'test.html', dest: 'dist/', expand: true, cwd: __dirname } } }); grunt.loadNpmTasks('grunt-include-replace'); grunt.registerTask('default', 'includereplace'); }; Since the prefix and suffix are added to the regex string like this:
new RegExp(options.prefix + 'include(\s["\'](.?)"\'{0,1}\s*)' + options.suffix); — Reply to this email directly or view it on GitHub.
Wanted this feature to work with CSS comment before include.
Tried your example option: WORKS
[HTML]
[GRUNTFILE]
then tried this: DOESN'T WORK
[HTML]
[GRUNTFILE]
then this, with Regex escapes: DOESN'T WORK
Any tips appreciated, thanks.