Skip to content

BaseCampOps/docx_templater

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Build Status Code Climate Dependency Status

Docx Templater

Use .docx as reusable templates

In your word document put placeholder names in double pipes || e.g. ||client_email1||

Example usage:

     buffer = DocxTemplater.new.replace_file_with_content('path/to/mydocument.docx',
        {
          :client_email1 => 'test@example.com',
          :client_phone1 => '555-555-5555',
        })
     # In Rails you can send a word document via send_data
     send_data buffer.string, :filename => 'REPC.docx'
     # Or save the output to a word file
     File.open("path/to/mydocument.docx", "wb") {|f| f.write(buffer.string) }

Newline Conversion

By default newlines in replacement values are converted to word document linebreak. If you need to ignore newlines you can pass a flag.

DocxTemplater.new(convert_newlines: false)
  .replace_file_with_content('path/to/file.docx',
    {quotes: "Be Excellent\nTo each other.\n~Bill and Ted's"})

Planned Changes

  • support for different tags (ie replace <<foo>> instead of ||foo||)

About

Uses a .docx with special keywords between double pipes || and replaces those pipes and keywords with content.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages