added default style

This commit is contained in:
Dolan Miu
2016-04-05 06:03:04 +01:00
parent d4c2b10285
commit a4b6ea562f
4 changed files with 162 additions and 8 deletions

View File

@ -7,7 +7,7 @@ export class LocalPacker extends Packer {
private stream: fs.WriteStream private stream: fs.WriteStream
constructor(document: Document, style: any, properties: Properties, path: string) { constructor(document: Document, style: any, properties: Properties, path: string) {
super(document, null, properties); super(document, style, properties);
this.stream = fs.createWriteStream(path); this.stream = fs.createWriteStream(path);
} }

View File

@ -5,6 +5,7 @@ import {Formatter} from "../formatter";
import {Document} from "../../docx"; import {Document} from "../../docx";
import {Style} from "../../style"; import {Style} from "../../style";
import {Properties} from "../../properties"; import {Properties} from "../../properties";
var appRoot = require('app-root-path');
export abstract class Packer { export abstract class Packer {
protected archive: any; protected archive: any;
@ -27,28 +28,30 @@ export abstract class Packer {
pack(output: any): void { pack(output: any): void {
this.archive.pipe(output); this.archive.pipe(output);
console.log(appRoot.path);
this.archive.bulk([ this.archive.bulk([
{ {
expand: true, expand: true,
cwd: __dirname + '/template', cwd: appRoot.path + '/template',
src: ['**', '**/.rels'] src: ['**', '**/.rels']
} }
]); ]);
//this.archive.directory(__dirname + "/template", "/"); //this.archive.directory(__dirname + "/template", "/");
var xmlDocument = xml(this.formatter.format(this.document)); var xmlDocument = xml(this.formatter.format(this.document));
//var xmlStyle = xml(this.style); var xmlStyle = xml(this.style);
var xmlProperties = xml(this.formatter.format(this.properties)); var xmlProperties = xml(this.formatter.format(this.properties));
console.log(JSON.stringify(this.formatter.format(this.document), null, " ")); console.log(JSON.stringify(this.formatter.format(this.document), null, " "));
console.log(xmlDocument); console.log(xmlDocument);
this.archive.append(xmlDocument, { this.archive.append(xmlDocument, {
name: 'word/document.xml' name: 'word/document.xml'
}); });
//this.archive.append(xmlStyle, { this.archive.append(xmlStyle, {
// name: 'word/newStyle.xml' name: 'word/newStyle.xml'
//}); });
this.archive.append(xmlProperties, { this.archive.append(xmlProperties, {
name: 'docProps/core.xml' name: 'docProps/core.xml'

150
ts/style/default.ts Normal file
View File

@ -0,0 +1,150 @@
function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) {
'use strict';
return [{
_attr: {
'w:name': name,
'w:uiPriority': uiPriority,
'w:qFormat': qFormat,
'w:semiHidden': semiHidden,
'w:unhideWhenUsed': unhideWhenUsed
}
}];
}
export function DefaultStyle() {
var style = {
'w:styles': [{
_attr: {
'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
'xmlns:w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
'xmlns:w14': 'http://schemas.microsoft.com/office/word/2010/wordml',
'xmlns:w15': 'http://schemas.microsoft.com/office/word/2012/wordml',
'mc:Ignorable': 'w14 w15'
}
}, {
'w:docDefaults': [{
'w:rPrDefault': [{
'w:rPr': [{
'w:rFonts': [{
_attr: {
'w:asciiTheme': "minorHAnsi",
'w:eastAsiaTheme': "minorHAnsi",
'w:hAnsiTheme': "minorHAnsi",
'w:cstheme': "minorBidi"
}
}]
}, {
'w:sz': [{
_attr: {
'w:val': "22"
}
}]
}, {
'w:szCs': [{
_attr: {
'w:val': "22"
}
}]
}, {
'w:lang': [{
_attr: {
'w:val': "en-GB",
'w:eastAsia': "en-US",
'w:bidi': "ar-SA"
}
}]
}]
}]
}, {
'w:pPrDefault': [{
'w:pPr': [{
'w:spacing': [{
_attr: {
'w:after': "160",
'w:line': "259",
'w:lineRule': "auto"
}
}]
}]
}]
}]
}, {
'w:latentStyles': [{
_attr: {
'w:defLockedState': "0",
'w:defUIPriority': "99",
'w:defSemiHidden': "0",
'w:defUnhideWhenUsed': "0",
'w:defQFormat': "0",
'w:count': "371"
}
}, {
'w:lsdException': createLsdException('Normal', 0, 1)
}, {
'w:lsdException': createLsdException("heading 1", 9, 1)
}, {
'w:lsdException': createLsdException("heading 1", 9, 1, 1, 1)
}, {
'w:lsdException': createLsdException("heading 2", 9, 1, 1, 1)
}, {
'w:lsdException': createLsdException("heading 3", 9, 1, 1, 1)
}, {
'w:lsdException': createLsdException("heading 4", 9, 1, 1, 1)
}, {
'w:lsdException': createLsdException("heading 5", 9, 1, 1, 1)
}, {
'w:lsdException': createLsdException("heading 6", 9, 1, 1, 1)
}, {
'w:lsdException': createLsdException("heading 7", 9, 1, 1, 1)
}, {
'w:lsdException': createLsdException("heading 8", 9, 1, 1, 1)
}, {
'w:lsdException': createLsdException("heading 9", 9, 1, 1, 1)
}, {
'w:lsdException': createLsdException("index 1", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("index 2", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("index 3", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("index 4", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("index 5", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("index 6", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("index 7", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("index 8", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("index 9", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("toc 1", 39, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("toc 2", 39, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("toc 3", 39, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("toc 4", 39, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("toc 5", 39, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("toc 6", 39, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("toc 7", 39, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("toc 8", 39, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("toc 9", 39, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("Normal Indent", undefined, undefined, 1, 1)
}, {
'w:lsdException': createLsdException("footnote text", undefined, undefined, 1, 1)
}]
}]
};
return style;
};

View File

@ -7,6 +7,7 @@ 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"
describe.only("Packer", () => { describe.only("Packer", () => {
var packer: LocalPacker; var packer: LocalPacker;
@ -16,7 +17,7 @@ describe.only("Packer", () => {
var properties = new Properties({ var properties = new Properties({
title: "test document" title: "test document"
}); });
packer = new LocalPacker(document, undefined, properties, "build/tests/test.zip"); packer = new LocalPacker(document, DefaultStyle(), properties, "build/tests/test.zip");
}); });
describe('#pack()', () => { describe('#pack()', () => {