add simple demo page

This commit is contained in:
Dolan Miu
2017-03-12 21:34:49 +00:00
parent bf22866a8d
commit f17360d45a
4 changed files with 19 additions and 3 deletions

15
demo/demo.js Normal file
View File

@ -0,0 +1,15 @@
const docx = require('../build');
var doc = new docx.Document();
var paragraph = new docx.Paragraph("Hello World");
var institutionText = new docx.TextRun("University College London").bold();
var dateText = new docx.TextRun("5th Dec 2015").tab().bold();
paragraph.addText(institutionText);
paragraph.addText(dateText);
doc.addParagraph(paragraph);
var exporter = new docx.LocalPacker(doc);
exporter.pack('My Document');
console.log('Document created succesfully at project root!');

View File

@ -8,7 +8,8 @@
"test": "mocha ./build-tests --recursive",
"prepublishOnly": "npm run build",
"lint": "tslint --project ./ts",
"build": "rimraf ./build && tsc -p ts"
"build": "rimraf ./build && tsc -p ts",
"demo": "npm run build && node ./demo/demo.js"
},
"files": [
"ts",

View File

@ -18,7 +18,7 @@ export class ExpressPacker extends Packer {
}
public pack(name: string): void {
this.res.attachment(name + ".docx");
this.res.attachment(`${name}.docx`);
super.pack(this.res);
}
}

View File

@ -13,7 +13,7 @@ export class LocalPacker extends Packer {
}
public pack(path: string): void {
this.stream = fs.createWriteStream(path);
this.stream = fs.createWriteStream(`${path}.docx`);
super.pack(this.stream);
}
}