Creating Templates Using Ruby on Rails

I am currently developing an administrative package using Ruby on Rails 3.2.

One of the tasks that must be completed is the creation of contracts and invoices .

Since the application must host multiple clients, I want each client to be able to download some kind of template that dictates their personal style and layout. (i.e. logo, company name, addr, etc.).

I mean letting clients create their own .docx contract templates using variables and placeholders that my application should replace when a specific contract / invoice is created. Please note: people who create templates will not have technical skills .

How can i do this? Please note that owners will be placed, which can be replaced directly, as well as duplicate elements that should be contained in the tables. The number of these elements may vary from contract to contract.

After reviewing many solutions, gems, and available examples, I cannot find one that works for my situation. This is what I have tried so far:

  • Docx processing by extracting document.xml and replacing placeholders. This is not very reliable and reliable because spellchecking or line breaks separate XML nodes containing placeholders.
  • wicked_pdf and other html> pdf generators: are not viable since I cannot expect my clients to supply custom CSS to style them.
  • Shrimp: more suitable for creating documents from scratch. The functionality of the template just does not do what I need, and does not support the replacement of placeholder data and duplicate elements.
  • Google Drive: Cancel the template on Google and use the Drive API to change the document and pull out the PDF when it's done: add extra reliability to the external service. More as a last resort. Hope to find out which solution I can execute locally.

I have the feeling that I'm missing something obvious. I can’t imagine that such a mundane task, like creating a document, is so complicated when using Ruby on Rails.

+4
source share
4 answers

After considering the alternatives, I decided to go the other way, and I came across this: github.com/sandrods/odf-report

This is the ODF (open office) gem for Rails, which allows you to do the same thing as ruby-docx-templater, but it feels much more reliable and does not break as easily as docx options ... Even spell checking can break parts of the [Name] block and cause it to stop working

+2
source

I created the library just for this purpose:

It is called Docxgen and can be found on github: https://github.com/edi9999/docxgenjs

Here is an example of how to use it:

Content Used: 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 an example is shown on my website: http://javascript-ninja.fr/docxgenjs/examples/demo.html

Ok, this is javascript, but:

it starts when node is installed globally at the command line:

 docxgen <inputFileDocx> <inputFileJson> 

Learn more about installing in the github repository: https://github.com/edi9999/docxgenjs#node-installation-and-usage

Hope this helps

+2
source

Take a look at ruby-docx-templater

I use it for exactly one purpose.

+2
source

Perhaps this stone is interesting for you.

https://github.com/trade-informatics/caracal/

It's like a shrimp, but with docx.

+1
source

Source: https://habr.com/ru/post/1497527/


All Articles