Mercurial > dotfiles.old
comparison bin/mkreport @ 89:016c657f0c31
Supercharge mkreport script
author | zegervdv <zegervdv@me.com> |
---|---|
date | Sat, 02 Aug 2014 17:44:15 +0200 |
parents | 3bc2e4f5cc59 |
children |
comparison
equal
deleted
inserted
replaced
88:d561c94bdefd | 89:016c657f0c31 |
---|---|
1 #!/bin/sh | 1 #!/usr/bin/env ruby |
2 # Create a new latex report from template | |
3 | 2 |
4 if [ $1 ]; then | 3 # 2014, Zeger Van de Vannet |
5 name=$1 | 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 } | |
16 | |
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' | |
6 else | 34 else |
7 name='report.tex' | 35 options.filename = "#{ARGV.first}.tex" |
8 fi | 36 end |
9 | 37 |
10 cp $HOME/.templates/report.tex $name | 38 puts options.inspect if options.verbose |
11 echo "Created $name" | 39 |
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 |