I am currently developing an administrative suite using Ruby on Rails 3.2.
One of the tasks it needs to perform is the generation of contracts and invoices.
Because the application needs to accomodate multiple clients, I want each client to be able to upload some kind of template which dictates their personal style and layout. (i.e.: logo, company name, addr, etc).
I am thinking of letting clients create their own .docx contract templates using variables and placeholders which my application should replace whener a specific contract / invoice is generated. Note that the people creating the templates will not be tech savvy.
How should I be able to accomplish this? Note that there will placeholders which can be replaced directly as well as repeating elements which should be contained in tables. The number of these elements can vary from contract to contract.
After having considered many solutions, gems and examples available I am unable to find one which works for my situation. This is what I have tried so far:
I get the feeling I am missing something obvious. I cannot imagine that such a mundane task as document generation is so complicated when using Ruby on Rails.
I have created a library exactly for this purpose:
It's called Docxgen and can be found on github: https://github.com/edi9999/docxgenjs
Here's a usage example of how to use it:
Used content: Hello {first_name} {last_name}
var doc= new DocxGen(docData); //Create a new DocxGen document
doc.setTemplateVars(
{"first_name":"Hipp",
"last_name":"Edgar",
}
) //set the templateVariables
doc.applyTemplateVars() //apply them (replace all occurences of {first_name} by Hipp, ...)
doc.output() //Output the document using Data-URI
Here's the example live on my site: http://javascript-ninja.fr/docxgenjs/examples/demo.html
it runs on node when you install it globally, as a command line:
docxgen <inputFileDocx> <inputFileJson>
More about the installation on the github repo: https://github.com/edi9999/docxgenjs#node-installation-and-usage
Hope this helps
Have a look at ruby-docx-templater
I use it for exactly the same purpose
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With