diff --git a/docs/README.md b/docs/README.md index dae964d87a..28781012fe 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,13 +1,3 @@ -
-
-
- Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100: -
- ---- - # Welcome ## Installation @@ -66,12 +56,6 @@ Packer.toBuffer(doc).then((buffer) => { // Done! A file called 'My First Document.docx' will be in your file system. ``` -## Honoured Mentions - -[@felipeochoa](https://github.com/felipeochoa) - -[@h4buli](https://github.com/h4buli) -
+
+> Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100:
+
+- Simple, declarative API
+- 50+ usage examples
+- Battle tested, mature, 95%+ coverage
+
+[GitHub](https://github.com/dolanmiu/docx)
+[Get Started](#Welcome)
diff --git a/docs/_sidebar.md b/docs/_sidebar.md
index 9e329b6448..a63970dff9 100644
--- a/docs/_sidebar.md
+++ b/docs/_sidebar.md
@@ -1,6 +1,6 @@
* [Getting Started](/)
-* [Examples](examples.md)
+* [Examples](https://github.com/dolanmiu/docx/tree/master/demo)
* API
diff --git a/docs/contribution-guidelines.md b/docs/contribution-guidelines.md
index 1305c4c4bd..f9963bd644 100644
--- a/docs/contribution-guidelines.md
+++ b/docs/contribution-guidelines.md
@@ -1,25 +1,23 @@
# Contribution Guidelines
-* Include documentation reference(s) at the top of each file:
+- Include documentation reference(s) at the top of each file:
```ts
// http://officeopenxml.com/WPdocument.php
```
-* Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
+- Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
-* Follow the `TSLint` rules
+- Follow the `TSLint` rules
## Always think about the user
-The number one pillar for contribution to `docx` is to **ALWAYS** think about how the user will use `docx`.
-
Put yourself in their position, and imagine how they would feel about your feature you wrote.
1. Is it easy to use?
2. Has it been documented well?
3. Is it intuitive?
-4. Is it consistent with the rest of the API?
+4. Is it declarative?
5. Is it fun to use?
## Good Commit Names
@@ -27,6 +25,7 @@ Put yourself in their position, and imagine how they would feel about your featu
Please write good commit messages when making a commit: https://chris.beams.io/posts/git-commit/
**Do not:**
+
```
c // What?
rtl // Adding acryonyms without explaining anything else is not helpful
@@ -35,34 +34,6 @@ demo updated // Getting better, but capitalize the first letter
Unesesary coment removed // Make sure to use correct spelling
```
-## No leaky components in API interface
-
-> This mainly applies to the API the end user will consume.
-
-Try to make method parameters of the outside API accept primitives, or `json` objects, so that child components are created **inside** the component, rather than being **injected** in.
-
-This is so that:
-
-1. Imports are much cleaner for the end user, no need for:
- ```ts
- import { ChildComponent } from "./my-feature/sub-component/deeper/.../my-deep.component";
- ```
-
-2. This is what I consider "leakage". The code is aware of the underlying implementation of the component.
-3. It means the end user does not need to import and create the child component to be injected.
-
-**Do not**
-
-`TableFloatProperties` is a class. The outside world would have to `new` up the object, and inject it in like so:
-
-```ts
- public float(tableFloatProperties: TableFloatProperties): Table
-```
-
-```ts
- table.float(new TableFloatProperties(...));
-```
-
**Do**
`ITableFloatOptions` is an interface for a JSON of primitives. The end user would need to pass in a json object and not need to worry about the internals:
@@ -71,31 +42,29 @@ This is so that:
public float(tableFloatOptions: ITableFloatOptions): Table
```
+## Delcariative API
+
+Make sure the API is declarative, so no _method calling_ or _mutation_. This is a design decision, consistent with the rest of the project. There are benefits to delcariative code over other styles of code, explained here: https://dzone.com/articles/why-declarative-coding-makes-you-a-better-programm
+
+**Do not:**
+
```ts
- table.float({...});
+const paragraph = doc.createParagraph();
+const text = paragraph.createText();
+text.contents = "Hello World";
```
-## Add vs Create
+**Do**
-This is just a guideline, and the rules can sometimes be broken.
-
-* Use `create` if the method `new`'s up an element inside:
-
- ```ts
- public createParagraph() {
- const paragraph = new Paragraph();
- this.root.push(paragraph);
- }
- ```
-
-* Use `add` if you add the element into the method as a parameter.
- *Note:* This may look like its breaking the previous guideline, but it has semantically different meanings. The previous one is using data to construct an object, whereas this one is simply adding elements into the document:
-
- ```ts
- public add(paragraph: Paragraph) {
- this.root.push(paragraph);
- }
- ```
+```ts
+doc.addSection({
+ children: [
+ new Paragraph({
+ children: [new TextRun("Hello World")],
+ }),
+ ],
+});
+```
## Getters and Setters
@@ -107,7 +76,7 @@ public get Level() {
}
```
-There is no performance advantage by doing this. It means we don't need to prefix all private variables with the ugly `_`:
+This is the convention of this project. There is no performance advantage by doing this. It means we don't need to prefix all private variables with `_`:
**Do not:**
@@ -121,30 +90,6 @@ private get _level: string;
private get level: string;
```
-## Temporal Methods
-
-Some methods are `non-temporal`, which means regardless of when you call the method, it will have the same affect on the document. For example, setting the width of a table at the end of the document will have the same effect as setting the width at the start:
-
-```ts
-table.setWidth(1000); // now removed as of version 5.0.0
-```
-
-Whereas some methods are `temporal`, which means depending on the time-frame they are called, it would produce a difference result. For example, moving `createParagraph()` around your code will physically alter the document.
-
-```ts
-doc.createParagraph("hello");
-```
-
-If a method is `non-temporal`, put it in the objects `constructor`. For example:
-
-```ts
-const table = new Table(width: number);
-```
-
-`Non-temporal` methods are usually methods which can only be used one time and one time only. For example, `.float()`. It does not make sense to call `.float()` again if its already floating.
-
-I am not sure what the real term is, but this will do.
-
## Interfaces over type alias
Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a class cannot implement it.
@@ -152,14 +97,14 @@ Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a
> "In general, use what you want ( type alias / interface ) just be consistent"
> "always use interface for public API's definition when authoring a library or 3rd party ambient type definitions"
>
-> * https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c
+> - https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c
`Interface` is generally preferred over `type`: https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types
**Do not:**
```ts
-type RelationshipFileInfo = { id: number, target: string };
+type RelationshipFileInfo = { id: number; target: string };
```
**Do:**
@@ -193,26 +138,26 @@ enum WeaponType = {
## Spell correctly, in full and in American English
-I am not sure where these habits in software development come from, but I do not believe it is beneficial:
-
**Do not:**
+
```ts
-readdy // misspelling
-perm // abbreviation
-conf // abbreviation
-cnty // abbreviation
-relationFile // abbreviation
-colour // U.K. English
+readdy; // misspelling
+perm; // abbreviation
+conf; // abbreviation
+cnty; // abbreviation
+relationFile; // abbreviation
+colour; // U.K. English
```
**Do:**
+
```ts
-ready
-permission
-config
-country
-relationshipFile
-color
+ready;
+permission;
+config;
+country;
+relationshipFile;
+color;
```
## Keep files small (within reason)
diff --git a/docs/examples.md b/docs/examples.md
deleted file mode 100644
index f638e1aa25..0000000000
--- a/docs/examples.md
+++ /dev/null
@@ -1,219 +0,0 @@
-# Examples
-
-> All examples can run independently and can be found in the `/demo` folder of the project
-
-All the examples below can be ran locally, to do so, run the following command:
-
-```sh
-npm run demo
-```
-
-This command will run the `demo selector app` in the `/demo` folder. It will prompt you to select a demo number, which will run a demo from that folder.
-
-## Simple
-
-A simple hello world of the `docx` library:
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo1.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo1.ts_
-
-## Styles
-
-### Styling with JS
-
-This example shows how to customise the look and feel of a document using JS configuration
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo2.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo2.ts_
-
-### Styling with XML
-
-This example shows how to customise the look and feel of a document using XML configuration
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo13.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo13.ts_
-
-## Numbering
-
-This example shows many levels of numbering
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo3.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo3.ts_
-
-## Table
-
-Example of simple table
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo4.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo4.ts_
-
-### Styling table borders
-
-Styling the borders of a table
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo20.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo20.ts_
-
-## Images
-
-### Add image to the document
-
-Importing Images from file system path
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo5.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo5.ts_
-
-### Add images to header and footer
-
-Example showing how to add image to headers and footers
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo9.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo9.ts_
-
-### Scaling images
-
-Example showing how to scale images
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo12.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo12.ts_
-
-### Add Image to media before adding to document
-
-This is the best way to add an image to a document because you can add the same image in two locations without increasing document size by re-using the same image
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo23.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo23.ts_
-
-### Add image to table
-
-As before, to add an image to a table, you would need to add it to the `Media` object first
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo24.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo24.ts_
-
-### Images using Base64 URI
-
-If you want to use a Base64 image instead
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo18.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.ts_
-
-## Margins
-
-Example showing how to set custom margins
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo6.ts_
-
-## Orientation
-
-Example showing how to set the document to `landscape` or `portrait`
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo7.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo7.ts_
-
-## Headers & Footers
-
-Example showing how to add headers and footers
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo8.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo8.ts_
-
-## Multiple headers and footers
-
-Check out `Sections` for this feature
-
-## Page Breaks
-
-### Normal page breaks
-
-Example showing how to page break
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo14.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo14.ts_
-
-### Page break before
-
-Example showing how to page break before like in Word
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo15.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo15.ts_
-
-## Sections
-
-Example of how sections work. Sections allow multiple headers and footers, and `landscape`/`portrait` inside the same document.
-Also you can have different page number formats and starts for different sections.
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo16.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo16.ts_
-
-## Footnotes
-
-Example of how to add footnotes. Good for references
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo17.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo17.ts_
-
-## Packers
-
-## Buffer output
-
-Example showing how to use the Buffer packer and then write that buffer to the file system
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo19.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo19.ts_
-
-
-## Bookmarks
-
-Example showing how to make bookmarks to make internal hyperlinks within the document
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo21.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo21.ts_
-
-## Bidirectional text
-
-Example showing how to use bidirectional text for certain languages such as Hebrew
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo22.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo22.ts_
-
-## Showcase
-
-### My CV
-
-Example showing how to add headers and footers
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo10.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo10.ts_
-
-### Style and Images
-
-This example shows how to customise the look and feel of a document and add images
-
-[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo11.ts ':include')
-
-_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo11.ts_
diff --git a/docs/index.html b/docs/index.html
index 29ab70ff59..13c52ae6da 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1,40 +1,36 @@
+
+
+