forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-builder.ts
More file actions
45 lines (34 loc) · 1.38 KB
/
template-builder.ts
File metadata and controls
45 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import definition = require("ui/builder/template-builder");
var KNOWNTEMPLATES = "knownTemplates";
export class TemplateBuilder {
private _items: Array<string>;
private _templateProperty: definition.TemplateProperty;
constructor(templateProperty: definition.TemplateProperty) {
this._items = new Array<string>();
this._templateProperty = templateProperty;
}
public get elementName(): string {
return this._templateProperty.elementName;
}
public addStartElement(elementName: string, attributes: Object) {
this._items.push("<" + elementName + (attributes ? " " + getAttributesAsString(attributes) + ">" : ">"));
}
public addEndElement(elementName: string) {
this._items.push("</" + elementName + ">");
}
public build() {
if (this._templateProperty.name in this._templateProperty.parent.component) {
this._templateProperty.parent.component[this._templateProperty.name] = this._items.join("");
}
}
}
export function isKnownTemplate(name: string, exports: any): boolean {
return KNOWNTEMPLATES in exports && exports[KNOWNTEMPLATES] && name in exports[KNOWNTEMPLATES];
}
function getAttributesAsString(attributes: Object): string {
var result = [];
for (var item in attributes) {
result.push(item + '="' + attributes[item] + '"');
}
return result.join(" ");
}