89
|
1 #!/usr/bin/env ruby
|
|
2
|
|
3 # 2014, Zeger Van de Vannet
|
|
4 #
|
|
5 # mkreport: Create a new latex report from template
|
|
6
|
|
7 require 'optparse'
|
|
8 require 'ostruct'
|
|
9 require 'erb'
|
|
10
|
|
11 TEMPLATE_DIR = File.expand_path(".templates", "~")
|
|
12 LANGS = {
|
|
13 "nl" => 'dutch',
|
|
14 "en" => 'english'
|
|
15 }
|
6
|
16
|
89
|
17 options = OpenStruct.new
|
|
18 # defaults
|
|
19 options.title = "TITLE HERE"
|
|
20 options.lang = "english"
|
|
21 options.class_opts = ["a4paper"]
|
|
22
|
|
23 OptionParser.new do |opts|
|
|
24 opts.banner = "Usage: mkreport [options] [filename]"
|
|
25 opts.on('-t', '--title TITLE', 'Set the title') { |opt| options.title = opt }
|
|
26 opts.on('-l','--language LANG', 'Set the language' ) { |opt| options.lang = LANGS[opt] || options.lang }
|
|
27 opts.on('--toc', 'Add Table of contents') { |opt| options.toc = true }
|
|
28 opts.on('-v', '--verbose', 'Show more (debugging) information') { |opt| options.verbose = true }
|
|
29 opts.on('--titlepage', 'Set a title page') { |opt| options.class_opts << 'titlepage' }
|
|
30 end.parse!
|
|
31
|
|
32 if ARGV.empty?
|
|
33 options.filename = 'report.tex'
|
33
|
34 else
|
89
|
35 options.filename = "#{ARGV.first}.tex"
|
|
36 end
|
|
37
|
|
38 puts options.inspect if options.verbose
|
33
|
39
|
89
|
40 template = File.read(File.expand_path('report.tex.erb', TEMPLATE_DIR))
|
|
41
|
|
42 File.open(options.filename, 'w') do |report|
|
|
43 @options = options
|
|
44 report.puts ERB.new(template).result()
|
|
45 puts "Created #{options.filename}"
|
|
46 end
|