Skip to content

Commit

Permalink
refactor: split API and serialization logic (#62)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `addHeading`, `addList` and `addParagraph` are no longer available on `TextDocument` but are added to the `TextBody` which can be retrieved from the document (`getBody`).

The code was largely restructured: The domain model classes (except for the style stuff) were moved to `/api` and the DOM generation is placed in `/xml`. The styles will get some extra love as soon as common styles will be implemented and thus are excluded for now.

All tests are placed next to their corresponding classes.

Except for the styles, the public API now is fluent and its documentation follows the same pattern and includes examples.

Fixes: #60
  • Loading branch information
connium authored Feb 17, 2019
1 parent 2a5312c commit 3af8831
Show file tree
Hide file tree
Showing 71 changed files with 3,218 additions and 2,304 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ coverage/
examples/
lib/
node_modules/
test/example
example.spec.ts

TODO.md
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- **meta:** Use `Date` instead of `number` when dealing with dates
- **chore:** Update dev dependencies, place test code next to production code, mention contributors in package.json
- **refactor:** Split API and serialization logic, closes [#60](https://github.com/connium/simple-odf/issues/60)

## [0.6.0] (2018-10-12)
### Added
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ Create your first document.
const simpleOdf = require("simple-odf");

const document = new simpleOdf.TextDocument();
const body = document.getBody();

const image = document.addParagraph().addImage("/home/homer/myself.png");
const image = body.addParagraph().addImage("/home/homer/myself.png");
image.getStyle().setAnchorType(simpleOdf.AnchorType.AsChar);
image.getStyle().setSize(29.4, 36.5);

document.addHeading("Welcome to simple-odf");
body.addHeading("Welcome to simple-odf");

const p1 = document.addParagraph("The quick, brown fox jumps over a lazy dog.");
const p1 = body.addParagraph("The quick, brown fox jumps over a lazy dog.");
p1.addText("\nThe five boxing wizards jump quickly.\n\n");
p1.addHyperlink("Visit me", "http://example.org/");
const style1 = new simpleOdf.ParagraphStyle();
Expand All @@ -45,15 +46,15 @@ style1.setKeepTogether();
p1.setStyle(style1);
// font usage
document.declareFont("Open Sans", "Open Sans", simpleOdf.FontPitch.Variable);
const p2 = document.addParagraph("It always seems impossible until it's done.");
const p2 = body.addParagraph("It always seems impossible until it's done.");
const style2 = new simpleOdf.ParagraphStyle();
style1.setFontName("Open Sans");

document.addHeading("Credits", 2);
body.addHeading("Credits", 2);

document.addParagraph("This was quite easy. Do you want to know why?");
body.addParagraph("This was quite easy. Do you want to know why?");

const list = document.addList();
const list = body.addList();
list.addItem("one-liner setup");
list.addItem("just write like you would do in a full-blown editor");

Expand Down
Loading

0 comments on commit 3af8831

Please sign in to comment.