Class: Texico::Compiler
- Inherits:
-
Object
- Object
- Texico::Compiler
- Defined in:
- lib/texico/compiler.rb
Constant Summary collapse
- COMMAND =
'latexmk'
- LATEXMK_OPTIONS =
{ pdf: true, output_directory: '.build', latexoption: { interaction: 'nonstopmode', file_line_error: true }.freeze }.freeze
- OUTPUT_PATTERN =
%r{\AOutput written on ([^\s]+) \((\d+) page, (\d+) bytes\)}
Instance Method Summary collapse
- #compile(file) ⇒ Object
-
#initialize(**options) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(**options) ⇒ Compiler
Returns a new instance of Compiler.
19 20 21 22 23 |
# File 'lib/texico/compiler.rb', line 19 def initialize(**) @args = LATEXMK_OPTIONS .merge() .map { |k, v| transform_option(k, v) }.join ' ' end |
Instance Method Details
#compile(file) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/texico/compiler.rb', line 25 def compile(file) # TODO: This looks very hacky... build_result = false Open3.popen2("#{COMMAND} #@args #{file}") do |_, stdout, _| stdout.each_line do |line| if m = line.match(OUTPUT_PATTERN) build_result = { file: m[1], pages: m[2], bytes: m[3] } break end end end build_result end |