Permalink
Browse files

Merge pull request #279 from SteveSanderson/279-newlines-in-virtual-e…

…lements

Containerless control comments with line-breaks are not recognized.
  • Loading branch information...
SteveSanderson committed Aug 21, 2012
2 parents 59cea3b + a6377f1 commit 48c911be2a25b2e00dcda1d272816e76adde09bb
Showing with 29 additions and 2 deletions.
  1. +15 −1 spec/bindingAttributeBehaviors.js
  2. +13 −0 spec/templatingBehaviors.js
  3. +1 −1 src/virtualElements.js
@@ -271,13 +271,27 @@ describe('Binding attribute syntax', {
ko.bindingHandlers.test = { init: function () { initCalls++ } };
ko.virtualElements.allowedBindings['test'] = true;
- testNode.innerHTML = "Hello <!-- ko test: false -->Some text<!-- /ko --> Goodbye"
+ testNode.innerHTML = "Hello <!-- ko test: false -->Some text<!-- /ko --> Goodbye";
ko.applyBindings(null, testNode);
value_of(initCalls).should_be(1);
value_of(testNode).should_contain_text("Hello Some text Goodbye");
},
+ 'Should be allowed to express containerless bindings with arbitrary internal whitespace and newlines': function() {
+ testNode.innerHTML = "Hello <!-- ko\n" +
+ " with\n" +
+ " : \n "+
+ " { \n" +
+ " \tpersonName: 'Bert'\n" +
+ " }\n" +
+ " \t --><span data-bind='text: personName'></span><!-- \n" +
+ " /ko \n" +
+ "-->, Goodbye";
+ ko.applyBindings(null, testNode);
+ value_of(testNode).should_contain_text('Hello Bert, Goodbye');
+ },
+
'Should be able to access virtual children in custom containerless binding': function() {
var countNodes = 0;
ko.bindingHandlers.test = {
@@ -751,6 +751,19 @@ describe('Templating', {
});
},
+ 'Data binding syntax should permit nested templates using virtual containers (with arbitrary internal whitespace and newlines)': function() {
+ ko.setTemplateEngine(new dummyTemplateEngine({
+ outerTemplate: "Outer <!-- ko template: \n" +
+ "{ name: \"innerTemplate\" } \n" +
+ "--><!-- /ko -->",
+ innerTemplate: "Inner via inline binding: <span data-bind='text: \"someText\"'></span>"
+ }));
+ var model = { };
+ testNode.innerHTML = "<div data-bind='template: { name: \"outerTemplate\" }'></div>";
+ ko.applyBindings(model, testNode);
+ value_of(testNode.childNodes[0]).should_contain_html("outer <!-- ko -->inner via inline binding: <span>sometext</span><!-- /ko -->");
+ },
+
'Should be able to render anonymous templates using virtual containers': function() {
ko.setTemplateEngine(new dummyTemplateEngine());
testNode.innerHTML = "Start <!-- ko template: { data: someData } -->Childprop: [js: childProp]<!-- /ko --> End";
View
@@ -12,7 +12,7 @@
// So, use node.text where available, and node.nodeValue elsewhere
var commentNodesHaveTextProperty = document.createComment("test").text === "<!--test-->";
- var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko\s+(.*\:.*)\s*-->$/ : /^\s*ko\s+(.*\:.*)\s*$/;
+ var startCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*ko(?:\s+(.+\s*\:[\s\S]*))?\s*-->$/ : /^\s*ko(?:\s+(.+\s*\:[\s\S]*))?\s*$/;
var endCommentRegex = commentNodesHaveTextProperty ? /^<!--\s*\/ko\s*-->$/ : /^\s*\/ko\s*$/;
var htmlTagsWithOptionallyClosingChildren = { 'ul': true, 'ol': true };

0 comments on commit 48c911b

Please sign in to comment.