Skip to content

Commit 649831c

Browse files
authored
Merge pull request #194 from donejs/keep-comment
Leave in comments starting with autorender-keep
2 parents eeea1bc + 3ed5b84 commit 649831c

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: node_js
2-
node_js: node
2+
node_js: 10.7
33
script: npm test
44
addons:
55
firefox: "51.0"

src/template.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/template.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ define(<%= imports %>, function(<%= args %>){
105105
"BASE": true
106106
};
107107

108+
function hasDataKeepAttr(node) {
109+
return node.dataset && node.dataset.keep === "";
110+
}
111+
112+
function isKeepComment(node) {
113+
return node.nodeType === 8 && node.nodeValue.indexOf("autorender-keep") === 0;
114+
}
115+
116+
function isKeepNode(node) {
117+
return hasDataKeepAttr(node) || isKeepComment(node);
118+
}
119+
108120
/**
109121
* Call a callback for each child Node within a parent, skipping
110122
* elements that should not be touched because of their side-effects.
@@ -117,7 +129,7 @@ define(<%= imports %>, function(<%= args %>){
117129
for(; i < len; i++) {
118130
node = nodes[i];
119131
ignoreTag = tagsToIgnore[node.nodeName];
120-
if(!ignoreTag && !(node.dataset && node.dataset.keep === "")) {
132+
if(!ignoreTag && !isKeepNode(node)) {
121133
// Returning false breaks the loop
122134
if(callback(node) === false) {
123135
break;

test/autorender_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ QUnit.test("basics works", function(){
3636

3737
QUnit.test("elements marked with data-keep are left in the DOM", function(){
3838
F("[name='custom-meta']").exists("meta tag left in");
39+
F(function() {
40+
var hasComment = false;
41+
var head = F.win.document.head;
42+
var child = head.firstChild;
43+
while(child) {
44+
if(child.nodeType === 8) {
45+
if(child.nodeValue === "autorender-keep some comment") {
46+
hasComment = true;
47+
break;
48+
}
49+
}
50+
child = child.nextSibling;
51+
}
52+
QUnit.equal(hasComment, true, "Comments with autorender-keep are left in.");
53+
})
3954
});
4055

4156
QUnit.module("tags to ignore from head", {

test/basics/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html>
22
<head>
33
<meta name="custom-meta" content="some value" data-keep>
4+
<!--autorender-keep some comment-->
45
</head>
56
<body>
67
<script src="../../node_modules/steal/steal.js" main="test/basics/index.stache!done-autorender"></script>

0 commit comments

Comments
 (0)