added style components

This commit is contained in:
Dolan Miu
2016-04-09 04:27:49 +01:00
parent bf928393b5
commit aed59754cc
7 changed files with 68 additions and 5 deletions

View File

@ -0,0 +1,16 @@
import {XmlComponent} from "./";
export abstract class BaseAttributes implements XmlComponent {
private _attr: Object;
xmlKeys = {};
constructor(xmlKeys: Object, properties?: any) {
this._attr = properties
if (!properties) {
this._attr = {};
}
this._attr["xmlKeys"] = this.xmlKeys;
}
}

View File

@ -3,7 +3,7 @@ import * as fs from "fs";
import * as xml from "xml"; import * as xml from "xml";
import {Formatter} from "../formatter"; import {Formatter} from "../formatter";
import {Document} from "../../docx"; import {Document} from "../../docx";
import {Style} from "../../style"; import {Styles} from "../../styles";
import {Properties} from "../../properties"; import {Properties} from "../../properties";
var appRoot = require('app-root-path'); var appRoot = require('app-root-path');
@ -11,7 +11,7 @@ export abstract class Packer {
protected archive: any; protected archive: any;
private formatter: Formatter; private formatter: Formatter;
protected document: Document; protected document: Document;
private style: Style; private style: Styles;
private properties: Properties; private properties: Properties;
constructor(document: Document, style: any, properties: Properties) { constructor(document: Document, style: any, properties: Properties) {

View File

@ -5,7 +5,7 @@ import {LatentStyles} from "./latent-styles";
import {LatentStyleException} from "./latent-styles/exceptions"; import {LatentStyleException} from "./latent-styles/exceptions";
import {LatentStyleExceptionAttributes} from "./latent-styles/exceptions/attributes"; import {LatentStyleExceptionAttributes} from "./latent-styles/exceptions/attributes";
export class Style implements XmlComponent { export class Styles implements XmlComponent {
private styles: Array<XmlComponent>; private styles: Array<XmlComponent>;
xmlKeys = { xmlKeys = {

View File

@ -0,0 +1,28 @@
import {XmlComponent} from "../../docx/xml-components";
interface StyleAttributesProperties {
type?: string;
styleId?: string;
default?: string;
customStyle?: string;
}
export class StyleAttributes implements XmlComponent {
private _attr: Object;
xmlKeys = {
type: "w:type",
styleId: "w:styleId",
default: "w:default",
customStyle: "w:customStyle"
};
constructor(properties?: StyleAttributesProperties) {
this._attr = properties
if (!properties) {
this._attr = {};
}
this._attr["xmlKeys"] = this.xmlKeys;
}
}

View File

19
ts/styles/style/index.ts Normal file
View File

@ -0,0 +1,19 @@
import {XmlComponent} from "../../docx/xml-components";
import {StyleAttributes} from "./attributes";
export class Style implements XmlComponent {
private style: Array<XmlComponent>;
xmlKeys = {
style: "w:style"
}
constructor(attributes: StyleAttributes) {
this.style = new Array<XmlComponent>();
this.style.push(attributes);
}
push(styleSegment: XmlComponent): void {
this.style.push(styleSegment);
}
}

View File

@ -7,10 +7,10 @@ import {LocalPacker} from "../export/packer/local";
import {assert} from "chai"; import {assert} from "chai";
import {Document} from "../docx/document" import {Document} from "../docx/document"
import {Properties} from "../properties" import {Properties} from "../properties"
import {DefaultStyle} from "../style/default" import {DefaultStyle} from "../styles/sample"
import {Paragraph} from "../docx/paragraph" import {Paragraph} from "../docx/paragraph"
describe.only("Packer", () => { describe("Packer", () => {
var packer: LocalPacker; var packer: LocalPacker;
beforeEach(() => { beforeEach(() => {