diff --git a/tasks/injector.js b/tasks/injector.js index da7831b..cc264e0 100644 --- a/tasks/injector.js +++ b/tasks/injector.js @@ -84,6 +84,18 @@ module.exports = function(grunt) { } }); + // Clear existing content between injectors + var templateContent = options.templateString || grunt.file.read(template), + templateOriginal = templateContent; + + var re = getInjectorTagsRegExp(options.starttag, options.endtag); + templateContent = templateContent.replace(re, function (match, indent, starttag, content, endtag) { + return indent + starttag + '\n' + indent + endtag; + }); + + if (templateContent !== templateOriginal || !grunt.file.exists(destination)) { + grunt.file.write(destination, templateContent); + } }); /**