-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
305407f
commit 40594b0
Showing
4 changed files
with
11 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# receipt-image-browser | ||
|
||
docs incoming |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# receipt-image-node | ||
|
||
docs incoming |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# receipt-layout | ||
|
||
NOT READY YET |
89 changes: 2 additions & 87 deletions
89
packages/plugins/renderers/receipt-html-renderer/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,3 @@ | ||
# receipt-components | ||
# receipt-html-renderer | ||
|
||
This package is for building complex and evolving receipts using a simple XML style language and component engine. The XML is converted to a simple JS representation that is then converted to either HTML or an ESC/POS byte array at runtime with supplied data. | ||
|
||
## Getting started | ||
|
||
First, install the package with yarn or npm: | ||
|
||
`npm install @resaleai/receipt-components` | ||
|
||
After that, import the `ReceiptComponent` class and create a new component with a template: | ||
|
||
```javascript | ||
import { ReceiptComponent } from '@resaleai/receipt-components'; | ||
|
||
let Receipt = new ReceiptComponent({ | ||
template: `<receipt> | ||
<text bold>Hello world!</text> | ||
</receipt>`, | ||
}); | ||
``` | ||
|
||
## Dependancies | ||
|
||
This project tries not to use any deps, but the image processing does require access to a `Canvas` API. This is always available in the browser, and can be simulated using another package, such as... | ||
|
||
After building the template, you can render the component into either HTML or the ESC/POS bytes using | ||
|
||
```javascript | ||
let htmlStr = Receipt.renderHTML(); // build the HTML | ||
let epBytes = Receipt.renderPrinterBytes(); // build the byte array | ||
``` | ||
|
||
This will output | ||
|
||
**printer bytes and html** | ||
|
||
## Templated | ||
|
||
On top of this, there is a simple templating engine built in for putting dynamic data in the receipts. | ||
|
||
**example** | ||
|
||
## Components | ||
|
||
The component system is simple, but surprisingly powerful. Take, for instance, some sort of legalise that needs to be put on the bottom of every receipt: | ||
|
||
```javascript | ||
let ReceiptLegalise = new ReceiptComponent({ | ||
template: `<receipt> | ||
<align mode="center"> | ||
<text scale="7:0">-------</text> | ||
<break lines="3" /> | ||
<text font="2" multiLine>{{ tnLegal }}</text> | ||
<break lines="3" /> | ||
<text scale="7:0">-------</text> | ||
</align> | ||
</receipt>`, | ||
}); | ||
``` | ||
|
||
This component, as well as any other components we need, can be used in the template of any other receipt component by registering it in the `components` constructor param. | ||
|
||
```javascript | ||
let Receipt = new ReceiptComponent({ | ||
template: | ||
`<receipt> | ||
... | ||
<ReceiptLegalise /> | ||
</receipt>` | ||
components: { | ||
ReceiptLegalise | ||
} | ||
}) | ||
|
||
let output = Receipt.renderPrinterBytes({ | ||
tnLegal: "This is the legal statement, you are legally obligated to have a good time :)" | ||
}) | ||
``` | ||
|
||
Note that the data is global. You must define any data you need in the render function. | ||
|
||
### TODO | ||
|
||
[ ] allow passing options to a different renderer | ||
[ ] build html renderer | ||
[ ] move images in to a separate package | ||
[ ] write docs | ||
docs incoming |