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,10 +89,10 @@ interface AttributesProperties {
|
|||||||
linePitch?: string;
|
linePitch?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Attributes extends XmlComponent {
|
export class Attributes extends XmlAttributeComponent {
|
||||||
private _attr: Object;
|
|
||||||
|
|
||||||
xmlKeys = {
|
constructor(properties?: AttributesProperties) {
|
||||||
|
super({
|
||||||
val: "w:val",
|
val: "w:val",
|
||||||
color: "w:color",
|
color: "w:color",
|
||||||
space: "w:space",
|
space: "w:space",
|
||||||
@ -87,17 +111,12 @@ export class Attributes extends XmlComponent {
|
|||||||
footer: "w:footer",
|
footer: "w:footer",
|
||||||
gutter: "w:gutter",
|
gutter: "w:gutter",
|
||||||
linePitch: "w:linePitch"
|
linePitch: "w:linePitch"
|
||||||
};
|
});
|
||||||
|
this.root = properties
|
||||||
constructor(properties?: AttributesProperties) {
|
|
||||||
super("_attr");
|
|
||||||
this._attr = properties
|
|
||||||
|
|
||||||
if (!properties) {
|
if (!properties) {
|
||||||
this._attr = {};
|
this.root = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
this._attr["xmlKeys"] = this.xmlKeys;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user