made attributes able to be replaced

This commit is contained in:
Dolan Miu
2016-04-25 03:28:02 +01:00
parent 52fcbc56d9
commit 3f8d23662e

View File

@ -1,3 +1,5 @@
import * as _ from "lodash";
export abstract class BaseXmlComponent {
protected rootKey: string;
@ -44,6 +46,28 @@ export abstract class XmlUnitComponent extends BaseXmlComponent {
}
}
export abstract class XmlAttributeComponent extends BaseXmlComponent {
protected root: Object;
private xmlKeys: Object;
constructor(xmlKeys: Object) {
super("_attr");
this.xmlKeys = xmlKeys;
}
replaceKey(): void {
if (this.root !== undefined) {
_.forOwn(this.root, (value, key) => {
var newKey = this.xmlKeys[key];
this.root[newKey] = value;
delete this.root[key];
});
this[this.rootKey] = this.root;
delete this.root;
}
}
}
interface AttributesProperties {
val?: any;
color?: string;
@ -65,39 +89,34 @@ interface AttributesProperties {
linePitch?: string;
}
export class Attributes extends XmlComponent {
private _attr: Object;
xmlKeys = {
val: "w:val",
color: "w:color",
space: "w:space",
sz: "w:sz",
type: "w:type",
rsidR: "w:rsidR",
rsidRPr: "w:rsidRPr",
rsidSect: "w:rsidSect",
w: "w:w",
h: "w:h",
top: "w:top",
right: "w:right",
bottom: "w:bottom",
left: "w:left",
header: "w:header",
footer: "w:footer",
gutter: "w:gutter",
linePitch: "w:linePitch"
};
export class Attributes extends XmlAttributeComponent {
constructor(properties?: AttributesProperties) {
super("_attr");
this._attr = properties
super({
val: "w:val",
color: "w:color",
space: "w:space",
sz: "w:sz",
type: "w:type",
rsidR: "w:rsidR",
rsidRPr: "w:rsidRPr",
rsidSect: "w:rsidSect",
w: "w:w",
h: "w:h",
top: "w:top",
right: "w:right",
bottom: "w:bottom",
left: "w:left",
header: "w:header",
footer: "w:footer",
gutter: "w:gutter",
linePitch: "w:linePitch"
});
this.root = properties
if (!properties) {
this._attr = {};
this.root = {};
}
this._attr["xmlKeys"] = this.xmlKeys;
}
}