Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matfluor/docxtemplate
a Simple Docx-Templating Class for Pharo.
https://github.com/matfluor/docxtemplate
pharo smalltalk
Last synced: 7 days ago
JSON representation
a Simple Docx-Templating Class for Pharo.
- Host: GitHub
- URL: https://github.com/matfluor/docxtemplate
- Owner: MatFluor
- Created: 2023-06-14T05:01:28.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-29T06:22:42.000Z (over 1 year ago)
- Last Synced: 2024-12-18T20:14:55.188Z (7 days ago)
- Topics: pharo, smalltalk
- Language: Smalltalk
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DocxTemplate
DocxTemplate is a simple Pharo class that allows you to perform templating with DOCX files. It makes use of [Mustache](https://github.com/noha/mustache) for variable replacement.
## Installation
To install DocxTemplate in Pharo, execute the following code:
```Smalltalk
Metacello new
baseline: 'DocxTemplater';
repository: 'github.com//MatFluor/DocxTemplate:main';
load
```## Usage
With DocxTemplate, you can work directly on the `document.xml` file inside a DOCX archive by using mustache variables, such as `{{name}}`, in your template. Thanks to Noha's Mustache implementation, the usage is straightforward.
Here are some examples:
```smalltalk
"Fill a template based on JSON data"
DocxTemplate new
zip: ''
json: '{ "name" : "mustache" }'
out: ''.
"Fill a template based on an Array"
DocxTemplate new
zip: ''
array: { 'name' -> 'mustache' }
out: ''.
```Apart from these two convenient methods, you can directly access each part individually (see the "private" protocol) for more advanced usage.
## Caveats
Please note that DocxTemplate has not been tested with partial templates and larger or more formatted documents. Keep this in mind as DOCX/Word may sometimes split content in unexpected ways.