Skip to content

Commit 57f11cb

Browse files
committed
Use HTMLTools namespace for all of html-tools
1 parent 5e85c32 commit 57f11cb

16 files changed

+70
-91
lines changed

packages/html-tools/charref.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,7 @@ var isLegalCodepoint = function (cp) {
23602360
// either `"`, `'`, or `>` and is supplied when parsing attribute values. NOTE: In the current spec, the
23612361
// value of `allowedChar` doesn't actually seem to end up mattering, but there is still some debate about
23622362
// the right approach to ampersands.
2363-
getCharacterReference = function (scanner, inAttribute, allowedChar) {
2363+
getCharacterReference = HTMLTools.Parse.getCharacterReference = function (scanner, inAttribute, allowedChar) {
23642364
if (scanner.peek() !== '&')
23652365
// no ampersand
23662366
return null;

packages/html-tools/charref_tests.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var Scanner = HTML._$.Scanner;
2-
var getCharacterReference = HTML._$.getCharacterReference;
1+
var Scanner = HTMLTools.Scanner;
2+
var getCharacterReference = HTMLTools.Parse.getCharacterReference;
33

44
Tinytest.add("html-tools - entities", function (test) {
55
var succeed = function (input, match, codepoints) {

packages/html-tools/exports.js

-20
This file was deleted.

packages/html-tools/package.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@ Package.describe({
44
});
55

66
Package.on_use(function (api) {
7-
// we attach stuff to the global symbol `HTML`, exported
8-
// by `htmljs`, so we both use and effectively imply it.
97
api.use('htmljs');
10-
api.imply('htmljs');
118

129
api.export('HTMLTools');
1310

1411
api.add_files(['utils.js',
1512
'scanner.js',
1613
'charref.js',
1714
'tokenize.js',
18-
'parse.js',
19-
'exports.js']);
15+
'parse.js']);
2016
});
2117

2218
Package.on_test(function (api) {

packages/html-tools/parse.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11

2-
HTML.Special = function (value) {
3-
if (! (this instanceof HTML.Special))
2+
HTMLTools.Special = function (value) {
3+
if (! (this instanceof HTMLTools.Special))
44
// called without `new`
5-
return new HTML.Special(value);
5+
return new HTMLTools.Special(value);
66

77
this.value = value;
88
};
9-
HTML.Special.prototype.toJS = function (options) {
9+
HTMLTools.Special.prototype.toJS = function (options) {
1010
// XXX this is weird because toJS is defined in spacebars-compiler.
11-
// Think about where HTML.Special and toJS should go.
12-
return HTML.Tag.prototype.toJS.call({tagName: 'Special',
11+
// Think about where HTMLTools.Special and toJS should go.
12+
return HTML.Tag.prototype.toJS.call({tagName: 'HTMLTools.Special',
1313
attrs: this.value,
1414
children: []},
1515
options);
1616
};
1717

18-
parseFragment = function (input, options) {
18+
HTMLTools.parseFragment = function (input, options) {
1919
var scanner;
2020
if (typeof input === 'string')
2121
scanner = new Scanner(input);
@@ -28,7 +28,7 @@ parseFragment = function (input, options) {
2828

2929
// ```
3030
// { getSpecialTag: function (scanner, templateTagPosition) {
31-
// if (templateTagPosition === HTML.TEMPLATE_TAG_POSITION.ELEMENT) {
31+
// if (templateTagPosition === HTMLTools.TEMPLATE_TAG_POSITION.ELEMENT) {
3232
// ...
3333
// ```
3434
if (options && options.getSpecialTag)
@@ -72,7 +72,7 @@ parseFragment = function (input, options) {
7272
//
7373
// Adapted from
7474
// http://stackoverflow.com/questions/7126384/expressing-utf-16-unicode-characters-in-javascript/7126661.
75-
codePointToString = function(cp) {
75+
codePointToString = HTMLTools.codePointToString = function(cp) {
7676
if (cp >= 0 && cp <= 0xD7FF || cp >= 0xE000 && cp <= 0xFFFF) {
7777
return String.fromCharCode(cp);
7878
} else if (cp >= 0x10000 && cp <= 0x10FFFF) {
@@ -95,7 +95,7 @@ codePointToString = function(cp) {
9595
}
9696
};
9797

98-
getContent = function (scanner, shouldStopFunc) {
98+
getContent = HTMLTools.Parse.getContent = function (scanner, shouldStopFunc) {
9999
var items = [];
100100

101101
while (! scanner.isEOF()) {
@@ -123,7 +123,7 @@ getContent = function (scanner, shouldStopFunc) {
123123
items.push(HTML.Comment(token.v));
124124
} else if (token.t === 'Special') {
125125
// token.v is an object `{ ... }`
126-
items.push(HTML.Special(token.v));
126+
items.push(HTMLTools.Special(token.v));
127127
} else if (token.t === 'Tag') {
128128
if (token.isEnd)
129129
// we've already screened for `</` so this shouldn't be
@@ -208,7 +208,7 @@ var pushOrAppendString = function (items, string) {
208208
};
209209

210210
// get RCDATA to go in the lowercase (or camel case) tagName (e.g. "textarea")
211-
getRCData = function (scanner, tagName, shouldStopFunc) {
211+
getRCData = HTMLTools.Parse.getRCData = function (scanner, tagName, shouldStopFunc) {
212212
var items = [];
213213

214214
while (! scanner.isEOF()) {
@@ -231,7 +231,7 @@ getRCData = function (scanner, tagName, shouldStopFunc) {
231231
items.push(convertCharRef(token));
232232
} else if (token.t === 'Special') {
233233
// token.v is an object `{ ... }`
234-
items.push(HTML.Special(token.v));
234+
items.push(HTMLTools.Special(token.v));
235235
} else {
236236
// (can't happen)
237237
scanner.fatal("Unknown or unexpected token type: " + token.t);
@@ -267,7 +267,7 @@ var getRawText = function (scanner, tagName, shouldStopFunc) {
267267
pushOrAppendString(items, token.v);
268268
} else if (token.t === 'Special') {
269269
// token.v is an object `{ ... }`
270-
items.push(HTML.Special(token.v));
270+
items.push(HTMLTools.Special(token.v));
271271
} else {
272272
// (can't happen)
273273
scanner.fatal("Unknown or unexpected token type: " + token.t);
@@ -319,7 +319,7 @@ var parseAttrs = function (attrs) {
319319
if (token.t === 'CharRef') {
320320
outParts.push(convertCharRef(token));
321321
} else if (token.t === 'Special') {
322-
outParts.push(HTML.Special(token.v));
322+
outParts.push(HTMLTools.Special(token.v));
323323
} else if (token.t === 'Chars') {
324324
pushOrAppendString(outParts, token.v);
325325
}

packages/html-tools/parse_tests.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var Scanner = HTML._$.Scanner;
2-
var getContent = HTML._$.getContent;
1+
var Scanner = HTMLTools.Scanner;
2+
var getContent = HTMLTools.Parse.getContent;
33

44
var CharRef = HTML.CharRef;
55
var Comment = HTML.Comment;
6-
var Special = HTML.Special;
6+
var Special = HTMLTools.Special;
77

88
var BR = HTML.BR;
99
var HR = HTML.HR;
@@ -149,23 +149,23 @@ Tinytest.add("html-tools - parser getContent", function (test) {
149149
});
150150

151151
Tinytest.add("html-tools - parseFragment", function (test) {
152-
test.equal(HTML.toJS(HTML.parseFragment("<div><p id=foo>Hello</p></div>")),
152+
test.equal(HTML.toJS(HTMLTools.parseFragment("<div><p id=foo>Hello</p></div>")),
153153
HTML.toJS(DIV(P({id:'foo'}, 'Hello'))));
154154

155155
test.throws(function() {
156-
HTML.parseFragment('asdf</a>');
156+
HTMLTools.parseFragment('asdf</a>');
157157
});
158158

159159
(function () {
160-
var p = HTML.parseFragment('<p></p>');
160+
var p = HTMLTools.parseFragment('<p></p>');
161161
test.equal(p.tagName, 'p');
162162
test.equal(p.attrs, null);
163163
test.isTrue(p instanceof HTML.Tag);
164164
test.equal(p.children.length, 0);
165165
})();
166166

167167
(function () {
168-
var p = HTML.parseFragment('<p>x</p>');
168+
var p = HTMLTools.parseFragment('<p>x</p>');
169169
test.equal(p.tagName, 'p');
170170
test.equal(p.attrs, null);
171171
test.isTrue(p instanceof HTML.Tag);
@@ -174,7 +174,7 @@ Tinytest.add("html-tools - parseFragment", function (test) {
174174
})();
175175

176176
(function () {
177-
var p = HTML.parseFragment('<p>x&#65;</p>');
177+
var p = HTMLTools.parseFragment('<p>x&#65;</p>');
178178
test.equal(p.tagName, 'p');
179179
test.equal(p.attrs, null);
180180
test.isTrue(p instanceof HTML.Tag);
@@ -187,7 +187,7 @@ Tinytest.add("html-tools - parseFragment", function (test) {
187187
})();
188188

189189
(function () {
190-
var pp = HTML.parseFragment('<p>x</p><p>y</p>');
190+
var pp = HTMLTools.parseFragment('<p>x</p><p>y</p>');
191191
test.isTrue(pp instanceof Array);
192192
test.equal(pp.length, 2);
193193

@@ -206,12 +206,12 @@ Tinytest.add("html-tools - parseFragment", function (test) {
206206

207207
var scanner = new Scanner('asdf');
208208
scanner.pos = 1;
209-
test.equal(HTML.parseFragment(scanner), 'sdf');
209+
test.equal(HTMLTools.parseFragment(scanner), 'sdf');
210210

211211
test.throws(function () {
212212
var scanner = new Scanner('asdf</p>');
213213
scanner.pos = 1;
214-
HTML.parseFragment(scanner);
214+
HTMLTools.parseFragment(scanner);
215215
});
216216
});
217217

packages/html-tools/scanner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// * `scanner.isEOF()` - true if `pos` is at or beyond the end of `input`
1010
// * `scanner.fatal(msg)` - throw an error indicating a problem at `pos`
1111

12-
Scanner = function (input) {
12+
Scanner = HTMLTools.Scanner = function (input) {
1313
this.input = input; // public, read-only
1414
this.pos = 0; // public, read-write
1515
};

packages/html-tools/tokenize.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var convertCRLF = function (str) {
5353
return str.replace(/\r\n?/g, '\n');
5454
};
5555

56-
getComment = function (scanner) {
56+
getComment = HTMLTools.Parse.getComment = function (scanner) {
5757
if (scanner.rest().slice(0, 4) !== '<!--')
5858
return null;
5959
scanner.pos += 4;
@@ -121,7 +121,7 @@ var getDoctypeQuotedString = function (scanner) {
121121
// See http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#the-doctype.
122122
//
123123
// If `getDocType` sees "<!DOCTYPE" (case-insensitive), it will match or fail fatally.
124-
getDoctype = function (scanner) {
124+
getDoctype = HTMLTools.Parse.getDoctype = function (scanner) {
125125
if (HTMLTools.asciiLowerCase(scanner.rest().slice(0, 9)) !== '<!doctype')
126126
return null;
127127
var start = scanner.pos;
@@ -205,7 +205,7 @@ var getChars = makeRegexMatcher(/^[^&<\u0000][^&<\u0000{]*/);
205205
// consumes characters and emits nothing (e.g. in the case of template
206206
// comments), we may go from not-at-EOF to at-EOF and return `null`,
207207
// while otherwise we always find some token to return.
208-
getHTMLToken = function (scanner, dataMode) {
208+
getHTMLToken = HTMLTools.Parse.getHTMLToken = function (scanner, dataMode) {
209209
var result = null;
210210
if (scanner.getSpecialTag) {
211211
var lastPos = -1;
@@ -377,7 +377,7 @@ var getUnquotedAttributeValue = function (scanner) {
377377
}
378378
};
379379

380-
getTagToken = function (scanner) {
380+
getTagToken = HTMLTools.Parse.getTagToken = function (scanner) {
381381
if (! (scanner.peek() === '<' && scanner.rest().charAt(1) !== '!'))
382382
return null;
383383
scanner.pos++;
@@ -506,7 +506,7 @@ getTagToken = function (scanner) {
506506
}
507507
};
508508

509-
TEMPLATE_TAG_POSITION = {
509+
TEMPLATE_TAG_POSITION = HTMLTools.TEMPLATE_TAG_POSITION = {
510510
ELEMENT: 1,
511511
IN_START_TAG: 2,
512512
IN_ATTRIBUTE: 3,

packages/html-tools/tokenize_tests.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var Scanner = HTML._$.Scanner;
2-
var getComment = HTML._$.getComment;
3-
var getDoctype = HTML._$.getDoctype;
4-
var getHTMLToken = HTML._$.getHTMLToken;
1+
var Scanner = HTMLTools.Scanner;
2+
var getComment = HTMLTools.Parse.getComment;
3+
var getDoctype = HTMLTools.Parse.getDoctype;
4+
var getHTMLToken = HTMLTools.Parse.getHTMLToken;
55

66
// "tokenize" is not really a great operation for real use, because
77
// it ignores the special content rules for tags like "style" and

packages/html-tools/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
HTMLTools = {};
3+
HTMLTools.Parse = {};
34

45
var asciiLowerCase = HTMLTools.asciiLowerCase = function (str) {
56
return str.replace(/[A-Z]/g, function (c) {

packages/spacebars-compiler/spacebars-compiler.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
Spacebars.parse = function (input) {
55

6-
var tree = HTML.parseFragment(
6+
var tree = HTMLTools.parseFragment(
77
input,
88
{ getSpecialTag: TemplateTag.parseCompleteTag });
99

@@ -65,7 +65,7 @@ var optimize = function (tree) {
6565
};
6666

6767
var doesAttributeValueHaveSpecials = function (v) {
68-
if (v instanceof HTML.Special)
68+
if (v instanceof HTMLTools.Special)
6969
return true;
7070
if (typeof v === 'function')
7171
return true;
@@ -161,7 +161,7 @@ Spacebars.isReservedName = function (name) {
161161
};
162162

163163
var codeGenTemplateTag = function (tag) {
164-
if (tag.position === HTML.TEMPLATE_TAG_POSITION.IN_START_TAG) {
164+
if (tag.position === HTMLTools.TEMPLATE_TAG_POSITION.IN_START_TAG) {
165165
// only `tag.type === 'DOUBLE'` allowed (by earlier validation)
166166
return HTML.EmitCode('function () { return ' +
167167
codeGenMustache(tag.path, tag.args, 'attrMustache')
@@ -446,7 +446,7 @@ var replaceSpecials = function (node) {
446446
return newTag;
447447
} else if (node instanceof Array) {
448448
return _.map(node, replaceSpecials);
449-
} else if (node instanceof HTML.Special) {
449+
} else if (node instanceof HTMLTools.Special) {
450450
return codeGenTemplateTag(node.value);
451451
} else {
452452
return node;

packages/spacebars-compiler/spacebars_tests.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,19 @@ Tinytest.add("spacebars - Spacebars.dot", function (test) {
188188

189189
Tinytest.add("spacebars - parse", function (test) {
190190
test.equal(HTML.toJS(Spacebars.parse('{{foo}}')),
191-
'HTML.Special({type: "DOUBLE", path: ["foo"]})');
191+
'HTMLTools.Special({type: "DOUBLE", path: ["foo"]})');
192192

193193
test.equal(HTML.toJS(Spacebars.parse('{{!foo}}')), 'null');
194194
test.equal(HTML.toJS(Spacebars.parse('x{{!foo}}y')), '"xy"');
195195

196196
test.equal(HTML.toJS(Spacebars.parse('{{#foo}}x{{/foo}}')),
197-
'HTML.Special({type: "BLOCKOPEN", path: ["foo"], content: "x"})');
197+
'HTMLTools.Special({type: "BLOCKOPEN", path: ["foo"], content: "x"})');
198198

199199
test.equal(HTML.toJS(Spacebars.parse('{{#foo}}{{#bar}}{{/bar}}{{/foo}}')),
200-
'HTML.Special({type: "BLOCKOPEN", path: ["foo"], content: HTML.Special({type: "BLOCKOPEN", path: ["bar"]})})');
200+
'HTMLTools.Special({type: "BLOCKOPEN", path: ["foo"], content: HTMLTools.Special({type: "BLOCKOPEN", path: ["bar"]})})');
201201

202202
test.equal(HTML.toJS(Spacebars.parse('<div>hello</div> {{#foo}}<div>{{#bar}}world{{/bar}}</div>{{/foo}}')),
203-
'[HTML.DIV("hello"), " ", HTML.Special({type: "BLOCKOPEN", path: ["foo"], content: HTML.DIV(HTML.Special({type: "BLOCKOPEN", path: ["bar"], content: "world"}))})]');
203+
'[HTML.DIV("hello"), " ", HTMLTools.Special({type: "BLOCKOPEN", path: ["foo"], content: HTML.DIV(HTMLTools.Special({type: "BLOCKOPEN", path: ["bar"], content: "world"}))})]');
204204

205205

206206
test.throws(function () {

0 commit comments

Comments
 (0)