Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move processToken

  • Loading branch information...
commit a1aa34df6bec310ff0283aad46eec89c4b4f3894 1 parent 2ac8387
@wycats wycats authored
View
3  Rakefile
@@ -10,6 +10,7 @@ end
directory "browser/htmlbars"
directory "browser/htmlbars/compiler"
+directory "browser/htmlbars/html-parser"
directory "browser/vendor"
def amd_module(filename)
@@ -17,7 +18,7 @@ def amd_module(filename)
output = "browser/#{out_name}"
input = "lib/#{filename}"
- file output => ["browser/htmlbars/compiler", "browser/vendor", input] do
+ file output => ["browser/htmlbars/compiler", "browser/htmlbars/html-parser", "browser/vendor", input] do
library = File.read(input)
open output, "w" do |file|
View
86 browser/htmlbars.js
@@ -786,8 +786,54 @@ define("htmlbars/helpers",
__exports__.helpers = helpers;
});
+define("htmlbars/html-parser/process-token",
+ ["htmlbars/ast","simple-html-tokenizer","exports"],
+ function(__dependency1__, __dependency2__, __exports__) {
+ "use strict";
+ var HTMLElement = __dependency1__.HTMLElement;
+ var BlockElement = __dependency1__.BlockElement;
+ var Chars = __dependency2__.Chars;
+ var StartTag = __dependency2__.StartTag;
+ var EndTag = __dependency2__.EndTag;
+
+ function processToken(processor, elementStack, token) {
+ var currentElement = elementStack[elementStack.length - 1];
+ if (token instanceof Chars) {
+ currentElement.children.push(token.chars);
+ } else if (token instanceof EndTag) {
+ if (currentElement.tag === token.tagName) {
+ var value = config.processHTMLMacros(currentElement)
+ elementStack.pop();
+
+ if (value === undefined) {
+ elementStack[elementStack.length - 1].children.push(currentElement);
+ } else if (value instanceof HTMLElement) {
+ elementStack[elementStack.length - 1].children.push(value);
+ }
+ } else {
+ throw new Error("Closing tag " + token.tagName + " did not match last open tag " + currentElement.tag);
+ }
+ } else if (token instanceof StartTag) {
+ var element = new HTMLElement(token.tagName, token.attributes);
+ element.helpers = processor.pendingTagHelpers.slice();
+ processor.pendingTagHelpers = [];
+ elementStack.push(element);
+ } else if (token instanceof Handlebars.AST.BlockNode) {
+ elementStack.push(new BlockElement(token.mustache));
+ }
+ }
+
+
+ var config = {
+ processHTMLMacros: function() {}
+ };
+
+ __exports__.processToken = processToken;
+ __exports__.config = config;
+ });
+
define("htmlbars/macros",
- ["htmlbars/parser","htmlbars/ast","exports"],
+ ["htmlbars/html-parser/process-token","htmlbars/ast","exports"],
function(__dependency1__, __dependency2__, __exports__) {
"use strict";
var config = __dependency1__.config;
@@ -833,8 +879,8 @@ define("htmlbars/macros",
});
define("htmlbars/parser",
- ["simple-html-tokenizer","htmlbars/ast","exports"],
- function(__dependency1__, __dependency2__, __exports__) {
+ ["simple-html-tokenizer","htmlbars/ast","htmlbars/html-parser/process-token","exports"],
+ function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
"use strict";
var Tokenizer = __dependency1__.Tokenizer;
var Chars = __dependency1__.Chars;
@@ -842,6 +888,7 @@ define("htmlbars/parser",
var EndTag = __dependency1__.EndTag;
var HTMLElement = __dependency2__.HTMLElement;
var BlockElement = __dependency2__.BlockElement;
+ var processToken = __dependency3__.processToken;
function preprocess(html) {
var ast = Handlebars.parse(html);
@@ -942,40 +989,7 @@ define("htmlbars/parser",
value.push(char);
}
};
-
- function processToken(processor, elementStack, token) {
- var currentElement = elementStack[elementStack.length - 1];
- if (token instanceof Chars) {
- currentElement.children.push(token.chars);
- } else if (token instanceof EndTag) {
- if (currentElement.tag === token.tagName) {
- var value = config.processHTMLMacros(currentElement)
- elementStack.pop();
-
- if (value === undefined) {
- elementStack[elementStack.length - 1].children.push(currentElement);
- } else if (value instanceof HTMLElement) {
- elementStack[elementStack.length - 1].children.push(value);
- }
- } else {
- throw new Error("Closing tag " + token.tagName + " did not match last open tag " + currentElement.tag);
- }
- } else if (token instanceof StartTag) {
- var element = new HTMLElement(token.tagName, token.attributes);
- element.helpers = processor.pendingTagHelpers.slice();
- processor.pendingTagHelpers = [];
- elementStack.push(element);
- } else if (token instanceof Handlebars.AST.BlockNode) {
- elementStack.push(new BlockElement(token.mustache));
- }
- }
-
- var config = {
- processHTMLMacros: function() {}
- };
-
__exports__.preprocess = preprocess;
- __exports__.config = config;
});
define("htmlbars/runtime",
View
45 browser/htmlbars/html-parser/process-token.amd.js
@@ -0,0 +1,45 @@
+define(
+ ["htmlbars/ast","simple-html-tokenizer","exports"],
+ function(__dependency1__, __dependency2__, __exports__) {
+ "use strict";
+ var HTMLElement = __dependency1__.HTMLElement;
+ var BlockElement = __dependency1__.BlockElement;
+ var Chars = __dependency2__.Chars;
+ var StartTag = __dependency2__.StartTag;
+ var EndTag = __dependency2__.EndTag;
+
+ function processToken(processor, elementStack, token) {
+ var currentElement = elementStack[elementStack.length - 1];
+ if (token instanceof Chars) {
+ currentElement.children.push(token.chars);
+ } else if (token instanceof EndTag) {
+ if (currentElement.tag === token.tagName) {
+ var value = config.processHTMLMacros(currentElement)
+ elementStack.pop();
+
+ if (value === undefined) {
+ elementStack[elementStack.length - 1].children.push(currentElement);
+ } else if (value instanceof HTMLElement) {
+ elementStack[elementStack.length - 1].children.push(value);
+ }
+ } else {
+ throw new Error("Closing tag " + token.tagName + " did not match last open tag " + currentElement.tag);
+ }
+ } else if (token instanceof StartTag) {
+ var element = new HTMLElement(token.tagName, token.attributes);
+ element.helpers = processor.pendingTagHelpers.slice();
+ processor.pendingTagHelpers = [];
+ elementStack.push(element);
+ } else if (token instanceof Handlebars.AST.BlockNode) {
+ elementStack.push(new BlockElement(token.mustache));
+ }
+ }
+
+
+ var config = {
+ processHTMLMacros: function() {}
+ };
+
+ __exports__.processToken = processToken;
+ __exports__.config = config;
+ });
View
2  browser/htmlbars/macros.amd.js
@@ -1,5 +1,5 @@
define(
- ["htmlbars/parser","htmlbars/ast","exports"],
+ ["htmlbars/html-parser/process-token","htmlbars/ast","exports"],
function(__dependency1__, __dependency2__, __exports__) {
"use strict";
var config = __dependency1__.config;
View
38 browser/htmlbars/parser.amd.js
@@ -1,6 +1,6 @@
define(
- ["simple-html-tokenizer","htmlbars/ast","exports"],
- function(__dependency1__, __dependency2__, __exports__) {
+ ["simple-html-tokenizer","htmlbars/ast","htmlbars/html-parser/process-token","exports"],
+ function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
"use strict";
var Tokenizer = __dependency1__.Tokenizer;
var Chars = __dependency1__.Chars;
@@ -8,6 +8,7 @@ define(
var EndTag = __dependency1__.EndTag;
var HTMLElement = __dependency2__.HTMLElement;
var BlockElement = __dependency2__.BlockElement;
+ var processToken = __dependency3__.processToken;
function preprocess(html) {
var ast = Handlebars.parse(html);
@@ -108,38 +109,5 @@ define(
value.push(char);
}
};
-
- function processToken(processor, elementStack, token) {
- var currentElement = elementStack[elementStack.length - 1];
- if (token instanceof Chars) {
- currentElement.children.push(token.chars);
- } else if (token instanceof EndTag) {
- if (currentElement.tag === token.tagName) {
- var value = config.processHTMLMacros(currentElement)
- elementStack.pop();
-
- if (value === undefined) {
- elementStack[elementStack.length - 1].children.push(currentElement);
- } else if (value instanceof HTMLElement) {
- elementStack[elementStack.length - 1].children.push(value);
- }
- } else {
- throw new Error("Closing tag " + token.tagName + " did not match last open tag " + currentElement.tag);
- }
- } else if (token instanceof StartTag) {
- var element = new HTMLElement(token.tagName, token.attributes);
- element.helpers = processor.pendingTagHelpers.slice();
- processor.pendingTagHelpers = [];
- elementStack.push(element);
- } else if (token instanceof Handlebars.AST.BlockNode) {
- elementStack.push(new BlockElement(token.mustache));
- }
- }
-
- var config = {
- processHTMLMacros: function() {}
- };
-
__exports__.preprocess = preprocess;
- __exports__.config = config;
});
View
37 lib/htmlbars/html-parser/process-token.js
@@ -0,0 +1,37 @@
+import { HTMLElement, BlockElement } from "htmlbars/ast";
+import { Chars, StartTag, EndTag } from "simple-html-tokenizer";
+
+function processToken(processor, elementStack, token) {
+ var currentElement = elementStack[elementStack.length - 1];
+ if (token instanceof Chars) {
+ currentElement.children.push(token.chars);
+ } else if (token instanceof EndTag) {
+ if (currentElement.tag === token.tagName) {
+ var value = config.processHTMLMacros(currentElement)
+ elementStack.pop();
+
+ if (value === undefined) {
+ elementStack[elementStack.length - 1].children.push(currentElement);
+ } else if (value instanceof HTMLElement) {
+ elementStack[elementStack.length - 1].children.push(value);
+ }
+ } else {
+ throw new Error("Closing tag " + token.tagName + " did not match last open tag " + currentElement.tag);
+ }
+ } else if (token instanceof StartTag) {
+ var element = new HTMLElement(token.tagName, token.attributes);
+ element.helpers = processor.pendingTagHelpers.slice();
+ processor.pendingTagHelpers = [];
+ elementStack.push(element);
+ } else if (token instanceof Handlebars.AST.BlockNode) {
+ elementStack.push(new BlockElement(token.mustache));
+ }
+}
+
+export { processToken };
+
+var config = {
+ processHTMLMacros: function() {}
+};
+
+export { config };
View
2  lib/htmlbars/macros.js
@@ -1,4 +1,4 @@
-import { config } from "htmlbars/parser";
+import { config } from "htmlbars/html-parser/process-token";
import { HTMLElement } from "htmlbars/ast";
var htmlMacros = {};
View
36 lib/htmlbars/parser.js
@@ -1,5 +1,6 @@
import { Tokenizer, Chars, StartTag, EndTag } from "simple-html-tokenizer";
import { HTMLElement, BlockElement } from "htmlbars/ast";
+import { processToken } from "htmlbars/html-parser/process-token";
function preprocess(html) {
var ast = Handlebars.parse(html);
@@ -100,37 +101,4 @@ StartTag.prototype.addToAttributeValue = function(char) {
} else {
value.push(char);
}
-};
-
-function processToken(processor, elementStack, token) {
- var currentElement = elementStack[elementStack.length - 1];
- if (token instanceof Chars) {
- currentElement.children.push(token.chars);
- } else if (token instanceof EndTag) {
- if (currentElement.tag === token.tagName) {
- var value = config.processHTMLMacros(currentElement)
- elementStack.pop();
-
- if (value === undefined) {
- elementStack[elementStack.length - 1].children.push(currentElement);
- } else if (value instanceof HTMLElement) {
- elementStack[elementStack.length - 1].children.push(value);
- }
- } else {
- throw new Error("Closing tag " + token.tagName + " did not match last open tag " + currentElement.tag);
- }
- } else if (token instanceof StartTag) {
- var element = new HTMLElement(token.tagName, token.attributes);
- element.helpers = processor.pendingTagHelpers.slice();
- processor.pendingTagHelpers = [];
- elementStack.push(element);
- } else if (token instanceof Handlebars.AST.BlockNode) {
- elementStack.push(new BlockElement(token.mustache));
- }
-}
-
-var config = {
- processHTMLMacros: function() {}
-};
-
-export { config };
+};
Please sign in to comment.
Something went wrong with that request. Please try again.