transform: Add missing test case in livereloadinject

* Test for both </body> and </BODY>
* This also cosmetically changes the behaviour, as the case of the end body tag is kept.
This commit is contained in:
Bjørn Erik Pedersen 2016-02-06 18:28:26 +01:00
parent 96e990456b
commit dd1db334ac
2 changed files with 16 additions and 5 deletions

View file

@ -15,15 +15,20 @@ package transform
import (
"bytes"
"fmt"
)
func LiveReloadInject(ct contentTransformer) {
match := []byte("</body>")
replace := []byte(`<script data-no-instant>document.write('<script src="/livereload.js?mindelay=10"></' + 'script>')</script></body>`)
endBodyTag := "</body>"
match := []byte(endBodyTag)
replaceTemplate := `<script data-no-instant>document.write('<script src="/livereload.js?mindelay=10"></' + 'script>')</script>%s`
replace := []byte(fmt.Sprintf(replaceTemplate, endBodyTag))
newcontent := bytes.Replace(ct.Content(), match, replace, -1)
if len(newcontent) == len(ct.Content()) {
match := []byte("</BODY>")
endBodyTag = "</BODY>"
replace := []byte(fmt.Sprintf(replaceTemplate, endBodyTag))
match := []byte(endBodyTag)
newcontent = bytes.Replace(ct.Content(), match, replace, -1)
}