Skip to content

MatFluor/DocxTemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DocxTemplate

DocxTemplate is a simple Pharo class that allows you to perform templating with DOCX files. It makes use of Mustache for variable replacement.

Installation

To install DocxTemplate in Pharo, execute the following code:

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:

"Fill a template based on JSON data"
DocxTemplate new 
	zip: '<Location of my .docx>'
	json: '{ "name" : "mustache" }'
	out: '<Location of the new, filled .docx>'.
	
"Fill a template based on an Array"
DocxTemplate new 
	zip: '<Location of my .docx>'
	array: { 'name' -> 'mustache' }
	out: '<Location of the new, filled .docx>'.

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.

About

a Simple Docx-Templating Class for Pharo.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published