From f3cd1a7fa7b64dcb1756edeec4ce4b59df46e9ff Mon Sep 17 00:00:00 2001 From: Tyler Henkel Date: Mon, 28 Apr 2014 02:48:34 -0400 Subject: [PATCH] Clear existing content between start/end tags before injection --- tasks/injector.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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); + } }); /**