-
Notifications
You must be signed in to change notification settings - Fork 5
/
x3-init
executable file
·86 lines (53 loc) · 1.28 KB
/
x3-init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env ruby
#
# A tool to quickly initialize a Multimarkdown "project" based on an x3-template
#
require 'fileutils'
def usage
"""
Usage: x3-init <template-name> <init-path>
(init-path must exist)
"""
end
def error(msg)
abort "Error: #{msg}"
end
def write_file(name, content)
error "Refusing to overwrite content in #{name}!" if File.exists? name
File.open(name, 'w') {|f| f.write(content) }
end
error(usage) if ARGV.length != 2
error(usage) if !File.directory? ARGV[1]
template = ARGV[0]
target = ARGV[1]
puts "Initializing template #{template} in path #{target}"
FileUtils.chdir(target)
puts "Creating content.md"
content_md = <<-EOF
Base Header Level: 3
latex input: document-info
latex footer: #{template}-end
# Hello world
EOF
write_file("content.md", content_md)
puts "Creating document-info.tex"
documentinfo_tex = <<-EOF
\\input{#{template}-preamble}
%
% Begin: Author and Document Information
%
%
% End: Author and Document Information
%
\\input{#{template}-begin}
EOF
write_file("document-info.tex", documentinfo_tex)
puts "Creating build.sh"
build_sh = <<-EOF
#!/bin/bash
multimarkdown --to=latex content.md > content.tex &&
omgtex.rb -o content.tex
EOF
write_file("build.sh", build_sh)
`chmod +x build.sh`
puts "Done!"