forked from dergachev/gdocs-export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
108 lines (81 loc) · 3.97 KB
/
Makefile
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#===============================================================================
# DEFAULT MAKE VARIABLES
#===============================================================================
# defaults to "Test doc for gd-pandoc"
doc = https://docs.google.com/a/evolvingweb.ca/document/d/1dwYaiiy4P0KA7PvNwAP2fsPAf6qMMNzwaq8W66mwyds/edit#heading=h.4lk08p1hx3w
outdir=build
doc_id = $(shell echo $(doc) | sed -e 's@^https.*document/d/@@' -e 's@/edit.*@@')
name = default
input_file = input/$(name).html
OUTPUT=$(outdir)/$(name)
auth_file = google-api-authorization.yaml
docker_workdir=/var/gdocs-export/
docker_run_cmd = docker run -t -i -v `pwd`:$(docker_workdir) -p 12736:12736 dergachev/gdocs-export
# directory containing customized header.tex, etc...
theme = sample
all: convert
#===============================================================================
# GOOGLE_DRIVE_API TARGETS
#===============================================================================
install_auth_file:
cp $(workdir)$(auth_file) ~/.google-api.yaml
api_auth:
bundle exec ruby bin/authorize.rb \
$(CLIENT_ID) $(CLIENT_SECRET) \
https://www.googleapis.com/auth/drive.readonly \
> $(auth_file)
api_download: install_auth_file
bundle exec google-api execute \
-u "https://docs.google.com/feeds/download/documents/export/Export?id=$(doc_id)&exportFormat=html" \
> $(input_file)
#===============================================================================
# PANDOC TARGETS
#===============================================================================
latex:
mkdir -p $(OUTPUT)
cp assets/default/* $(OUTPUT)
test -z "$(theme)" || cp assets/$(theme)/* $(OUTPUT)
cp $(input_file) $(OUTPUT)/in.html
bundle exec ruby -C$(OUTPUT) "$$PWD/lib/pandoc-preprocess.rb" in.html > $(OUTPUT)/preprocessed.html
pandoc --parse-raw $(OUTPUT)/preprocessed.html -t json > $(OUTPUT)/pre.json
cat $(OUTPUT)/pre.json | ./lib/pandoc-filter.py > $(OUTPUT)/post.json
# use pandoc to create metadata.tex, main.tex (these are included by ew-template.tex)
pandoc $(OUTPUT)/post.json --no-wrap -t latex --template $(OUTPUT)/template-metadata.tex > $(OUTPUT)/metadata.tex
pandoc $(OUTPUT)/post.json --chapters --no-wrap -t latex > $(OUTPUT)/main.tex
# must use -o with docx output format, since its binary
pandoc $(OUTPUT)/post.json -s -t docx -o $(OUTPUT)/$(name).docx
pandoc $(OUTPUT)/post.json -s -t rtf -o $(OUTPUT)/$(name).rtf
pdf:
# convert latex to PDF
echo "Created $(OUTPUT)/$(name).tex, compiling into $(name).pdf"
# rubber will set output PDF filename based on latex input filename
cp -f $(OUTPUT)/template.tex $(OUTPUT)/$(name).tex
( cd $(OUTPUT); latexmk -pdf $(name))
convert: latex pdf
diff:
/usr/bin/perl "`which latexdiff`" --flatten $(outdir)/$(before)/$(before).tex $(OUTPUT)/$(name).tex > $(OUTPUT)/diff.tex
(cd $(OUTPUT); latexmk -pdf diff)
#===============================================================================
# DOCKER TARGETS
#===============================================================================
build_docker:
@echo "Warning: building can take a while (~15m)."
dpkg -l squid-deb-proxy || sudo apt-get install -y squid-deb-proxy
docker build -t dergachev/gdocs-export .
docker_debug:
$(docker_run_cmd) /bin/bash
latest:
docker run -t -i `docker images -q | head -n 1` /bin/bash
docker_api_auth:
$(docker_run_cmd) make api_auth CLIENT_ID=$(CLIENT_ID) CLIENT_SECRET=$(CLIENT_SECRET)
docker_api_download:
$(docker_run_cmd) make api_download doc_id=$(doc_id) input_file=$(input_file) workdir=$(docker_workdir)
docker_convert:
$(docker_run_cmd) make convert OUTPUT=$(OUTPUT) name=$(name) input_file=$(input_file) theme=$(theme)
docker_diff:
docker run -t -i -v `pwd`:$(docker_workdir) -p 12736:12736 dergachev/gdocs-export make diff OUTPUT=$(OUTPUT) name=$(name) input_file=$(input_file) before=$(before)
#===============================================================================
# MISC TARGETS
#===============================================================================
test:
bundle exec rspec