Module: DocxTemplater

Defined in:
lib/docx_templater.rb,
lib/docx_templater/command.rb,
lib/docx_templater/version.rb,
lib/docx_templater/docx_creator.rb,
lib/docx_templater/template_processor.rb

Defined Under Namespace

Classes: Command, DocxCreator, TemplateProcessor

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.log(str) ⇒ Object



8
9
10
11
# File 'lib/docx_templater.rb', line 8

def log(str)
  # braindead logging
  puts str if ENV['DEBUG']
end

.open_output_file(output_file) ⇒ Object

Open word file in mac os(with word installed)



36
37
38
39
40
41
42
43
44
45
# File 'lib/docx_templater.rb', line 36

def open_output_file(output_file)
  puts "\n************************************"
  puts '   >>> Only will work on mac <<<'
  puts 'NOW attempting to open created file in Word.'
  cmd = "open #{output_file}"
  puts "  will run '#{cmd}'"
  puts '************************************'

  system cmd
end

.template_docx(options = {}) ⇒ Object

template docx file

Examples:

options = {
  input_file: 'xxx',
  output_file: 'xxx',
  data: { key: value }
}

Parameters:

  • options (Hash) (defaults to: {})

    -



23
24
25
26
27
28
29
30
31
32
# File 'lib/docx_templater.rb', line 23

def template_docx(options = {})
  puts "options: #{options}"

  DocxTemplater::DocxCreator.new(options[:input_file], options[:data]).generate_docx_file(options[:output_file])

  archive = Zip::File.open(options[:output_file])
  archive.close

  DocxTemplater.open_output_file options[:output_file]
end