view bin/mkreport @ 182:3dc6a4eec6ac

Reload options from sessions
author zegervdv <zegervdv@me.com>
date Wed, 05 Nov 2014 22:11:31 +0100
parents 016c657f0c31
children
line wrap: on
line source

#!/usr/bin/env ruby

# 2014, Zeger Van de Vannet
#
# mkreport: Create a new latex report from template

require 'optparse'
require 'ostruct'
require 'erb'

TEMPLATE_DIR = File.expand_path(".templates", "~")
LANGS = {
  "nl" => 'dutch',
  "en" => 'english'
}

options = OpenStruct.new
# defaults
options.title = "TITLE HERE"
options.lang = "english"
options.class_opts = ["a4paper"]

OptionParser.new do |opts|
  opts.banner = "Usage: mkreport [options] [filename]"
  opts.on('-t', '--title TITLE', 'Set the title') { |opt| options.title = opt }
  opts.on('-l','--language LANG', 'Set the language' ) { |opt| options.lang = LANGS[opt] || options.lang }
  opts.on('--toc', 'Add Table of contents') { |opt| options.toc = true }
  opts.on('-v', '--verbose', 'Show more (debugging) information') { |opt| options.verbose = true }
  opts.on('--titlepage', 'Set a title page') { |opt| options.class_opts << 'titlepage' }
end.parse!

if ARGV.empty?
  options.filename = 'report.tex'
else
  options.filename = "#{ARGV.first}.tex"
end

puts options.inspect if options.verbose

template = File.read(File.expand_path('report.tex.erb', TEMPLATE_DIR))

File.open(options.filename, 'w') do |report|
  @options = options
  report.puts ERB.new(template).result()
  puts "Created #{options.filename}"
end