made attributes able to be replaced
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
import * as _ from "lodash";
|
||||||
|
|
||||||
export abstract class BaseXmlComponent {
|
export abstract class BaseXmlComponent {
|
||||||
protected rootKey: string;
|
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 {
|
interface AttributesProperties {
|
||||||
val?: any;
|
val?: any;
|
||||||
color?: string;
|
color?: string;
|
||||||
@ -65,39 +89,34 @@ interface AttributesProperties {
|
|||||||
linePitch?: string;
|
linePitch?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Attributes extends XmlComponent {
|
export class Attributes extends XmlAttributeComponent {
|
||||||
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"
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(properties?: AttributesProperties) {
|
constructor(properties?: AttributesProperties) {
|
||||||
super("_attr");
|
super({
|
||||||
this._attr = properties
|
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) {
|
if (!properties) {
|
||||||
this._attr = {};
|
this.root = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
this._attr["xmlKeys"] = this.xmlKeys;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user