Skip to content

BaseCampOps/docx_templater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 => '[email protected]',
          :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

Contributors 2

  •  
  •  

Languages