-
Notifications
You must be signed in to change notification settings - Fork 29
/
make-snap
executable file
·64 lines (51 loc) · 1.04 KB
/
make-snap
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
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
$LOAD_PATH.push("script")
load 'make-common'
def usage
puts <<USAGE
Usage:
make-html [markdown]
Options:
-d, --debug : debuging
USAGE
exit
end
# re-generate all if nothing
if ARGV.empty?
$DEBUG = true
Dir["#$here/chap*/doc.markdown"].each do |file|
ARGV.push(file)
end
end
# load history
deps = {}
if File.exist?(".snap-dep")
deps = eval(File.read(".snap-dep"))
end
def in_dir(dir, &block)
old = pwd()
cd(dir)
block.call
cd(old)
end
ARGV.sort.map do |file|
chap = /chap(\d+)/.match(file)[1]
puts " [!] Reading markdown #{file}" if $DEBUG
snap = `./make-md -s #{file}`
snap and snap.each do |line|
line = line.rstrip
puts " [!] #{line}" if $DEBUG
# image output
out = /-o ([^ ]+)/.match(line)[1]
# check if exist
if deps[out] != line or !File.exist?("img/" + out)
system(line.gsub(out, "img/" + out))
deps[out] = line
end
end
end
# update dependencies
File.open(".snap-dep", "w") do |f|
f.write(deps.inspect)
end