Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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.