Comparing version 0.1.9 to 0.1.10
@@ -363,2 +363,6 @@ define("htmlbars-runtime", | ||
prototype.createComment = function(text){ | ||
return this.document.createComment(text); | ||
}; | ||
prototype.repairClonedNode = function(element, blankChildTextNodes, isChecked){ | ||
@@ -365,0 +369,0 @@ if (deletesBlankTextNodes && blankChildTextNodes.length > 0) { |
@@ -186,2 +186,6 @@ define("morph", | ||
prototype.createComment = function(text){ | ||
return this.document.createComment(text); | ||
}; | ||
prototype.repairClonedNode = function(element, blankChildTextNodes, isChecked){ | ||
@@ -188,0 +192,0 @@ if (deletesBlankTextNodes && blankChildTextNodes.length > 0) { |
@@ -198,2 +198,18 @@ "use strict"; | ||
test("The compiler can handle HTML comments", function() { | ||
compilesTo('<div><!-- Just passing through --></div>'); | ||
}); | ||
test("The compiler can handle HTML comments with mustaches in them", function() { | ||
compilesTo('<div><!-- {{foo}} --></div>', '<div><!-- {{foo}} --></div>', { foo: 'bar' }); | ||
}); | ||
test("The compiler can handle HTML comments with complex mustaches in them", function() { | ||
compilesTo('<div><!-- {{foo bar baz}} --></div>', '<div><!-- {{foo bar baz}} --></div>', { foo: 'bar' }); | ||
}); | ||
test("The compiler can handle HTML comments with multi-line mustaches in them", function() { | ||
compilesTo('<div><!-- {{#each foo as |bar|}}\n{{bar}}\n\n{{/each}} --></div>'); | ||
}); | ||
// TODO: Revisit partial syntax. | ||
@@ -200,0 +216,0 @@ // test("The compiler can handle partials in handlebars partial syntax", function() { |
@@ -152,2 +152,11 @@ "use strict"; | ||
]); | ||
}); | ||
test("comment", function() { | ||
var input = "<!-- some comment -->"; | ||
actionsEqual(input, [ | ||
['startProgram', [0, []]], | ||
['comment', [0, 1, true]], | ||
['endProgram', [0]] | ||
]); | ||
}); |
@@ -28,2 +28,7 @@ "use strict"; | ||
FragmentOpcodeCompiler.prototype.comment = function(comment) { | ||
this.opcode('createComment', [comment.chars]); | ||
this.opcode('appendChild'); | ||
}; | ||
FragmentOpcodeCompiler.prototype.openElement = function(element) { | ||
@@ -30,0 +35,0 @@ this.opcode('createElement', [element.tag]); |
@@ -37,2 +37,7 @@ "use strict"; | ||
FragmentCompiler.prototype.createComment = function(str) { | ||
var el = 'el'+(++this.depth); | ||
this.source.push(this.indent+' var '+el+' = dom.createComment('+string(str)+');\n'); | ||
}; | ||
FragmentCompiler.prototype.returnNode = function() { | ||
@@ -39,0 +44,0 @@ var el = 'el'+this.depth; |
@@ -58,2 +58,6 @@ "use strict"; | ||
HydrationOpcodeCompiler.prototype.comment = function(/* string, pos, len */) { | ||
++this.currentDOMChildIndex; | ||
}; | ||
HydrationOpcodeCompiler.prototype.openElement = function(element, pos, len, isSingleRoot, mustacheCount, blankChildTextNodes) { | ||
@@ -60,0 +64,0 @@ distributeMorphs(this.morphs, this.opcodes); |
@@ -203,2 +203,8 @@ "use strict"; | ||
TemplateVisitor.prototype.comment = function(text) { | ||
var frame = this.getCurrentFrame(); | ||
frame.actions.push(['comment', [text, frame.childIndex, frame.childCount, true]]); | ||
}; | ||
TemplateVisitor.prototype.mustache = function(mustache) { | ||
@@ -205,0 +211,0 @@ var frame = this.getCurrentFrame(); |
@@ -135,2 +135,7 @@ "use strict"; | ||
TemplateCompiler.prototype.comment = function(string, i, l, r) { | ||
this.fragmentOpcodeCompiler.comment(string, i, l, r); | ||
this.hydrationOpcodeCompiler.comment(string, i, l, r); | ||
}; | ||
TemplateCompiler.prototype.mustache = function (mustache, i, l) { | ||
@@ -137,0 +142,0 @@ this.fragmentOpcodeCompiler.mustache(mustache, i, l); |
@@ -39,2 +39,7 @@ "use strict"; | ||
block: function(block) { | ||
if (this.tokenizer.state === 'comment') { | ||
this.tokenizer.token.addChar('{{' + this.sourceForMustache(block) + '}}'); | ||
return; | ||
} | ||
switchToHandlebars(this); | ||
@@ -65,2 +70,7 @@ this.acceptToken(block); | ||
mustache: function(mustache) { | ||
if (this.tokenizer.state === 'comment') { | ||
this.tokenizer.token.addChar('{{' + this.sourceForMustache(mustache) + '}}'); | ||
return; | ||
} | ||
switchToHandlebars(this); | ||
@@ -67,0 +77,0 @@ this.acceptToken(mustache); |
@@ -72,3 +72,5 @@ "use strict"; | ||
block: function(/*block*/) { | ||
if (this.tokenizer.state !== 'data') { | ||
if (this.tokenizer.state === 'comment') { | ||
return; | ||
} else if (this.tokenizer.state !== 'data') { | ||
throw new Error("A block may only be used inside an HTML element or another block."); | ||
@@ -75,0 +77,0 @@ } |
@@ -9,7 +9,8 @@ "use strict"; | ||
var ast = parse(html); | ||
var combined = new HTMLProcessor(options).acceptNode(ast); | ||
var combined = new HTMLProcessor(html, options).acceptNode(ast); | ||
return combined; | ||
} | ||
exports.preprocess = preprocess;function HTMLProcessor(options) { | ||
exports.preprocess = preprocess;function HTMLProcessor(source, options) { | ||
this.options = options || {}; | ||
@@ -20,2 +21,3 @@ this.elementStack = []; | ||
this.tokenHandlers = tokenHandlers; | ||
this.source = source.split(/(?:\r\n?|\n)/g); | ||
} | ||
@@ -35,2 +37,31 @@ | ||
return this.elementStack[this.elementStack.length - 1]; | ||
}; | ||
HTMLProcessor.prototype.sourceForMustache = function(mustache) { | ||
var firstLine = mustache.firstLine - 1; | ||
var lastLine = mustache.lastLine - 1; | ||
var currentLine = firstLine - 1; | ||
var firstColumn = mustache.firstColumn + 2; | ||
var lastColumn = mustache.lastColumn - 2; | ||
var string = []; | ||
var line; | ||
while (currentLine < lastLine) { | ||
currentLine++; | ||
line = this.source[currentLine]; | ||
if (currentLine === firstLine) { | ||
if (firstLine === lastLine) { | ||
string.push(line.slice(firstColumn, lastColumn)); | ||
} else { | ||
string.push(line.slice(firstColumn)); | ||
} | ||
} else if (currentLine === lastLine) { | ||
string.push(line.slice(0, lastColumn)); | ||
} else { | ||
string.push(line); | ||
} | ||
} | ||
return string.join('\n'); | ||
}; |
@@ -7,3 +7,3 @@ "use strict"; | ||
* See https://raw.githubusercontent.com/tildeio/htmlbars/master/LICENSE | ||
* @version 0.1.9 | ||
* @version 0.1.10 | ||
*/ | ||
@@ -10,0 +10,0 @@ |
@@ -173,2 +173,6 @@ "use strict"; | ||
prototype.createComment = function(text){ | ||
return this.document.createComment(text); | ||
}; | ||
prototype.repairClonedNode = function(element, blankChildTextNodes, isChecked){ | ||
@@ -175,0 +179,0 @@ if (deletesBlankTextNodes && blankChildTextNodes.length > 0) { |
@@ -27,2 +27,7 @@ import TemplateVisitor from "./template_visitor"; | ||
FragmentOpcodeCompiler.prototype.comment = function(comment) { | ||
this.opcode('createComment', [comment.chars]); | ||
this.opcode('appendChild'); | ||
}; | ||
FragmentOpcodeCompiler.prototype.openElement = function(element) { | ||
@@ -29,0 +34,0 @@ this.opcode('createElement', [element.tag]); |
@@ -36,2 +36,7 @@ import { processOpcodes } from "./utils"; | ||
FragmentCompiler.prototype.createComment = function(str) { | ||
var el = 'el'+(++this.depth); | ||
this.source.push(this.indent+' var '+el+' = dom.createComment('+string(str)+');\n'); | ||
}; | ||
FragmentCompiler.prototype.returnNode = function() { | ||
@@ -38,0 +43,0 @@ var el = 'el'+this.depth; |
@@ -57,2 +57,6 @@ import TemplateVisitor from "./template_visitor"; | ||
HydrationOpcodeCompiler.prototype.comment = function(/* string, pos, len */) { | ||
++this.currentDOMChildIndex; | ||
}; | ||
HydrationOpcodeCompiler.prototype.openElement = function(element, pos, len, isSingleRoot, mustacheCount, blankChildTextNodes) { | ||
@@ -59,0 +63,0 @@ distributeMorphs(this.morphs, this.opcodes); |
@@ -202,2 +202,8 @@ var push = Array.prototype.push; | ||
TemplateVisitor.prototype.comment = function(text) { | ||
var frame = this.getCurrentFrame(); | ||
frame.actions.push(['comment', [text, frame.childIndex, frame.childCount, true]]); | ||
}; | ||
TemplateVisitor.prototype.mustache = function(mustache) { | ||
@@ -204,0 +210,0 @@ var frame = this.getCurrentFrame(); |
@@ -133,2 +133,7 @@ import { FragmentOpcodeCompiler } from './fragment_opcode'; | ||
TemplateCompiler.prototype.comment = function(string, i, l, r) { | ||
this.fragmentOpcodeCompiler.comment(string, i, l, r); | ||
this.hydrationOpcodeCompiler.comment(string, i, l, r); | ||
}; | ||
TemplateCompiler.prototype.mustache = function (mustache, i, l) { | ||
@@ -135,0 +140,0 @@ this.fragmentOpcodeCompiler.mustache(mustache, i, l); |
@@ -35,2 +35,7 @@ import { BlockNode, ProgramNode, PartialNode, appendChild } from "../ast"; | ||
block: function(block) { | ||
if (this.tokenizer.state === 'comment') { | ||
this.tokenizer.token.addChar('{{' + this.sourceForMustache(block) + '}}'); | ||
return; | ||
} | ||
switchToHandlebars(this); | ||
@@ -61,2 +66,7 @@ this.acceptToken(block); | ||
mustache: function(mustache) { | ||
if (this.tokenizer.state === 'comment') { | ||
this.tokenizer.token.addChar('{{' + this.sourceForMustache(mustache) + '}}'); | ||
return; | ||
} | ||
switchToHandlebars(this); | ||
@@ -63,0 +73,0 @@ this.acceptToken(mustache); |
@@ -73,3 +73,5 @@ import { | ||
block: function(/*block*/) { | ||
if (this.tokenizer.state !== 'data') { | ||
if (this.tokenizer.state === 'comment') { | ||
return; | ||
} else if (this.tokenizer.state !== 'data') { | ||
throw new Error("A block may only be used inside an HTML element or another block."); | ||
@@ -76,0 +78,0 @@ } |
@@ -8,7 +8,8 @@ import { parse } from "./handlebars/compiler/base"; | ||
var ast = parse(html); | ||
var combined = new HTMLProcessor(options).acceptNode(ast); | ||
var combined = new HTMLProcessor(html, options).acceptNode(ast); | ||
return combined; | ||
} | ||
function HTMLProcessor(options) { | ||
function HTMLProcessor(source, options) { | ||
this.options = options || {}; | ||
@@ -19,2 +20,3 @@ this.elementStack = []; | ||
this.tokenHandlers = tokenHandlers; | ||
this.source = source.split(/(?:\r\n?|\n)/g); | ||
} | ||
@@ -35,1 +37,30 @@ | ||
}; | ||
HTMLProcessor.prototype.sourceForMustache = function(mustache) { | ||
var firstLine = mustache.firstLine - 1; | ||
var lastLine = mustache.lastLine - 1; | ||
var currentLine = firstLine - 1; | ||
var firstColumn = mustache.firstColumn + 2; | ||
var lastColumn = mustache.lastColumn - 2; | ||
var string = []; | ||
var line; | ||
while (currentLine < lastLine) { | ||
currentLine++; | ||
line = this.source[currentLine]; | ||
if (currentLine === firstLine) { | ||
if (firstLine === lastLine) { | ||
string.push(line.slice(firstColumn, lastColumn)); | ||
} else { | ||
string.push(line.slice(firstColumn)); | ||
} | ||
} else if (currentLine === lastLine) { | ||
string.push(line.slice(0, lastColumn)); | ||
} else { | ||
string.push(line); | ||
} | ||
} | ||
return string.join('\n'); | ||
}; |
@@ -6,3 +6,3 @@ /* | ||
* See https://raw.githubusercontent.com/tildeio/htmlbars/master/LICENSE | ||
* @version 0.1.9 | ||
* @version 0.1.10 | ||
*/ | ||
@@ -9,0 +9,0 @@ |
@@ -174,2 +174,6 @@ /* global window:false */ | ||
prototype.createComment = function(text){ | ||
return this.document.createComment(text); | ||
}; | ||
prototype.repairClonedNode = function(element, blankChildTextNodes, isChecked){ | ||
@@ -176,0 +180,0 @@ if (deletesBlankTextNodes && blankChildTextNodes.length > 0) { |
var packagesConfig = { | ||
"version": "0.1.9", | ||
"revision": "448c8bd45abef809aaad51793531edd19b4813e2", | ||
"version": "0.1.10", | ||
"revision": "d32e5b566b2f38532bbfdd11889a3b9f3136fa8c", | ||
"vendored": {}, | ||
@@ -5,0 +5,0 @@ "dependencies": { |
{ | ||
"name": "htmlbars", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "HTMLBars compiles Handlebars templates into document fragments rather than string buffers", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/htmlbars.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1168835
34608