styles: support for external styles. parsing external styles.
This commit is contained in:
71
src/file/xml-components/imported-xml-component.ts
Normal file
71
src/file/xml-components/imported-xml-component.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import { XmlComponent, IXmlableObject } from ".";
|
||||
|
||||
/**
|
||||
* Represents imported xml component from xml file.
|
||||
*/
|
||||
export class ImportedXmlComponent extends XmlComponent {
|
||||
private _attr: any;
|
||||
|
||||
constructor(rootKey: string, _attr?: any) {
|
||||
super(rootKey);
|
||||
if (_attr) {
|
||||
this._attr = _attr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the object so it can be converted to xml. Example:
|
||||
* <w:someKey someAttr="1" otherAttr="11">
|
||||
* <w:child childAttr="2">
|
||||
* </w:child>
|
||||
* </w:someKey>
|
||||
* {
|
||||
* 'w:someKey': [
|
||||
* {
|
||||
* _attr: {
|
||||
* someAttr: "1",
|
||||
* otherAttr: "11"
|
||||
* }
|
||||
* },
|
||||
* {
|
||||
* 'w:child': [
|
||||
* {
|
||||
* _attr: {
|
||||
* childAttr: "2"
|
||||
* }
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
prepForXml(): IXmlableObject {
|
||||
const result = super.prepForXml();
|
||||
if (!!this._attr) {
|
||||
if (!Array.isArray(result[this.rootKey])) {
|
||||
result[this.rootKey] = [result[this.rootKey]];
|
||||
}
|
||||
result[this.rootKey].unshift({ _attr: this._attr });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
push(xmlComponent: XmlComponent) {
|
||||
this.root.push(xmlComponent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for the attributes of root element that is being imported.
|
||||
*/
|
||||
export class ImportedRootElementAttributes extends XmlComponent {
|
||||
constructor(private _attr: any) {
|
||||
super("");
|
||||
}
|
||||
|
||||
public prepForXml(): IXmlableObject {
|
||||
return {
|
||||
_attr: this._attr,
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user