hackademic 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/hackademic.gemspec +1 -1
- data/lib/hackademic/compile.rb +30 -41
- data/test/Resources/Config.yml +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b9dc2e329f95c94dce330f01ec5f4bcebdd23ed
|
4
|
+
data.tar.gz: 7aed02ebdfe1f94e1ed93a685d31700a6b53abd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d1b3c3b9e987bf8ddb5558e130030d98c70a3aeb1dcc2726836b4537faf61ff95b0dc2579d527d1c02f7a58c2361ad272f5bbe36493fab244c53d3777668edd
|
7
|
+
data.tar.gz: e50b1368db7426679b6108482b899468bb7eb66cce13d98805bc5a4c29953be37f30f6521cedb1af5edde16b03e712bee15630ec1bf7de0112df6f6289dd124b
|
data/hackademic.gemspec
CHANGED
data/lib/hackademic/compile.rb
CHANGED
@@ -12,10 +12,9 @@ module Hackademic
|
|
12
12
|
|
13
13
|
desc "pdf", "compile a pdf"
|
14
14
|
def pdf
|
15
|
-
check_installation
|
16
15
|
read_draft_file
|
17
16
|
write_master_markdown_file
|
18
|
-
system
|
17
|
+
system pdf_command
|
19
18
|
say "Writing out PDF file: #{config.output_directory}/#{config.transcluded_draft.gsub(/\..*$/, '')}.pdf"
|
20
19
|
end
|
21
20
|
|
@@ -31,7 +30,6 @@ module Hackademic
|
|
31
30
|
|
32
31
|
desc "docx", "compile a docx"
|
33
32
|
def docx
|
34
|
-
check_installation
|
35
33
|
read_draft_file
|
36
34
|
write_master_markdown_file
|
37
35
|
system docx_command
|
@@ -40,7 +38,6 @@ module Hackademic
|
|
40
38
|
|
41
39
|
desc "latex", "compile a latex document"
|
42
40
|
def latex
|
43
|
-
check_installation
|
44
41
|
read_draft_file
|
45
42
|
write_master_markdown_file
|
46
43
|
%x[pandoc #{config.output_directory}/#{config.transcluded_draft} --from=markdown+#{pandoc_from_options.join("+")} --filter pandoc-citeproc --bibliography=#{config.bibliography} --csl=#{config.citation_style} --latex-engine=xelatex --template=#{config.latex_template} -s -o "#{latex_file}"]
|
@@ -54,14 +51,33 @@ module Hackademic
|
|
54
51
|
end
|
55
52
|
|
56
53
|
def libre_office_binary
|
54
|
+
# TODO: Check/Test this works as intended
|
57
55
|
config.libre_office_binary || "/Applications/LibreOffice.app/Contents/MacOS/soffice"
|
58
56
|
end
|
59
57
|
|
58
|
+
def add_extra_pandoc_variables(command)
|
59
|
+
if config.pandoc_variables.is_a? Hash
|
60
|
+
config.pandoc_variables.each do |key, val|
|
61
|
+
command << %{ -V #{key}="#{val}" }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
command
|
65
|
+
end
|
66
|
+
|
60
67
|
def docx_command
|
61
68
|
if File.exists?(libre_office_binary)
|
62
69
|
command = ""
|
63
70
|
# Use pandoc to create an ODT file"
|
64
|
-
command << %[pandoc
|
71
|
+
command << %[pandoc \
|
72
|
+
--template=#{config.odt_template} \
|
73
|
+
--from=markdown+#{pandoc_from_options.join("+")} \
|
74
|
+
--filter pandoc-citeproc \
|
75
|
+
--bibliography=#{config.bibliography} \
|
76
|
+
--csl=#{config.citation_style} \
|
77
|
+
-o temp.odt \
|
78
|
+
#{config.output_directory}/#{config.transcluded_draft} \
|
79
|
+
]
|
80
|
+
command = add_extra_pandoc_variables(command)
|
65
81
|
command << " && "
|
66
82
|
# Use LibreOffice to create a DOCX file"
|
67
83
|
command << "#{libre_office_binary} --invisible --convert-to docx temp.odt"
|
@@ -70,56 +86,31 @@ module Hackademic
|
|
70
86
|
command << "rm temp.odt"
|
71
87
|
command << " && "
|
72
88
|
# Rename the temp.docx and move it into the Versions directory
|
73
|
-
command << "
|
74
|
-
|
75
|
-
|
89
|
+
command << "cp temp.docx #{config.output_directory}/#{config.draft_name.gsub(/\..*$/,'')}.docx"
|
90
|
+
command << " && "
|
91
|
+
command << "rm temp.docx"
|
92
|
+
else # Run without LibreOffice
|
93
|
+
command = %[pandoc #{config.output_directory}/#{config.transcluded_draft} --from=markdown+#{pandoc_from_options.join("+")} --filter pandoc-citeproc --bibliography=#{config.bibliography} --csl=#{config.citation_style} --reference-docx=#{config.docx_template} -s -o "#{config.output_directory}/#{config.draft_name.gsub(/\..*$/,'')}.docx"]
|
94
|
+
command = add_extra_pandoc_variables(command)
|
76
95
|
end
|
96
|
+
command.gsub(/\s+/, ' ')
|
77
97
|
end
|
78
98
|
|
79
99
|
def pdf_command
|
80
100
|
cmd = %{pandoc \
|
81
101
|
--template=#{config.pdf_template} \
|
82
102
|
-t html5 \
|
103
|
+
--from=markdown+#{pandoc_from_options.join("+")} \
|
83
104
|
--bibliography=#{config.bibliography} \
|
84
105
|
--csl=#{config.citation_style} \
|
85
106
|
-s \
|
86
107
|
-o "#{config.output_directory}/#{config.draft_name.gsub(/\..*$/,'')}.pdf" \
|
87
108
|
#{config.output_directory}/#{config.transcluded_draft} \
|
88
109
|
}
|
89
|
-
|
90
|
-
config.pandoc_variables.each do |key, val|
|
91
|
-
cmd << %{-V #{key}="#{val}"}
|
92
|
-
end
|
93
|
-
end
|
110
|
+
cmd = add_extra_pandoc_variables(cmd)
|
94
111
|
cmd.gsub(/\s+/, ' ')
|
95
112
|
end
|
96
113
|
|
97
|
-
# TODO: Move to Hackademy::Setup
|
98
|
-
def check_installation
|
99
|
-
check_versions_directory
|
100
|
-
check_latex_installation
|
101
|
-
# check pandoc installation
|
102
|
-
# check python3 installation (panzer dependency)
|
103
|
-
# check panzer installation
|
104
|
-
end
|
105
|
-
|
106
|
-
def check_latex_installation
|
107
|
-
# TODO: Make sure user has latex/xetex/etc.
|
108
|
-
end
|
109
|
-
|
110
|
-
def check_versions_directory
|
111
|
-
begin
|
112
|
-
if !Dir.open('versions')
|
113
|
-
File.mkdir("versions")
|
114
|
-
# %x[mkdir versions]
|
115
|
-
end
|
116
|
-
rescue => exception
|
117
|
-
FileUtils.mkdir("versions") unless Dir.exists?('versions')
|
118
|
-
puts exception
|
119
|
-
say "Something went wrong. Make sure versions isn't a plan old file!", :red
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
114
|
def transclude(file)
|
124
115
|
file = "#{config.drafts_dir}/#{file}" unless file[Regexp.compile("^#{config.drafts_dir}")]
|
125
116
|
if File.exists?(file)
|
@@ -141,8 +132,6 @@ module Hackademic
|
|
141
132
|
@draft = File.open("#{config.drafts_dir}/#{config.draft_name}", "r").read
|
142
133
|
say "...Generating the *TRANSCLUDED* source...", :blue
|
143
134
|
transclude(config.draft_name)
|
144
|
-
# @draft.gsub!("__VERSION__", "v#{version}") if @draft[/__VERSION__/]
|
145
|
-
# @draft.gsub!("__DATETIME__", timestamp) if @draft[/__DATETIME__/]
|
146
135
|
end
|
147
136
|
|
148
137
|
def write_master_markdown_file
|
data/test/Resources/Config.yml
CHANGED
@@ -13,5 +13,6 @@ hackademic:
|
|
13
13
|
latex_template: Resources/templates/xelatex.template
|
14
14
|
html_template: Resources/templates/default.html5
|
15
15
|
pdf_template: Resources/templates/default.html5
|
16
|
+
odt_template: Resources/templates/default.odt
|
16
17
|
support_directory: Resources
|
17
18
|
libre_office_binary: /Applications/LibreOffice.app/Contents/MacOS/soffice
|