Class: Rubbr::Runner::Base

Inherits:
Object
  • Object
show all
Includes:
Cli
Defined in:
lib/rubbr/runner.rb

Direct Known Subclasses

BibTeX, DviPs, LaTeX, PdfLaTeX, Ps2Pdf

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cli

#color?, #disable_stderr, #disable_stdinn, #disable_stdout, #error, #executable?, #notice, #valid_executable, #warning

Methods included from OS

#os

Constructor Details

#initialize(input_file, executable) ⇒ Base

Returns a new instance of Base.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rubbr/runner.rb', line 27

def initialize(input_file, executable)
  @input_file = input_file
  @executable = valid_executable executable
  @verboser_warnings = []
  @errors = []

  if File.exists? @input_file
    run
  else
    error "Running of #@executable aborted. " +
          "Input file: #@input_file not found"
  end
end

Instance Attribute Details

#errorsObject

Contains a list of possible errors after a run.



25
26
27
# File 'lib/rubbr/runner.rb', line 25

def errors
  @errors
end

#executableObject

The executable to be run.



16
17
18
# File 'lib/rubbr/runner.rb', line 16

def executable
  @executable
end

#input_fileObject

The file to be run trough the latex process.



13
14
15
# File 'lib/rubbr/runner.rb', line 13

def input_file
  @input_file
end

#verboser_warningsObject

Contains a list of possible verboser warnings after a run.



22
23
24
# File 'lib/rubbr/runner.rb', line 22

def verboser_warnings
  @verboser_warnings
end

#warningsObject

Contains a list of possible warnings after a run.



19
20
21
# File 'lib/rubbr/runner.rb', line 19

def warnings
  @warnings
end

Instance Method Details

#feedbackObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rubbr/runner.rb', line 68

def feedback
  unless @warnings.empty?
    notice "Warnings from #@executable:"
    @warnings.each do |message|
      warning message
    end
  end
  unless @verboser_warnings.empty?
    notice "Verboser warnings from #@executable:"
    @verboser_warnings.each do |message|
      warning message
    end
  end
  unless @errors.empty?
    notice "Errors from #@executable:"
    @errors.each do |message|
      error message
    end

    raise GotErrors
  end
end

#runObject



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
# File 'lib/rubbr/runner.rb', line 41

def run
  disable_stdinn do # No input in case of error correction dialogue
    messages = /^(Overfull|Underfull|No file|Package \w+ Warning:|LaTeX Warning:)/
    verbose_messages = /^(Overfull \\hbox|Underfull \\hbox)/

    run = `#@executable #@input_file`
    lines = run.split("\n")
    @warnings = lines.grep(messages).sort.uniq

    if Rubbr.options[:verboser]

      lines.each_with_index do |line, i|
        if line =~ verbose_messages
          @verboser_warnings << line
          @verboser_warnings << lines[i+1]
        end
      end
    end

    while lines.shift
      if lines.first =~ /^!/ # LaTeX Error, processing halted
        3.times { @errors << lines.shift }
      end
    end
  end
end