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

Constructor Details

#initialize(input_file, executable) ⇒ Base

Returns a new instance of Base.



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

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.



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

def errors
  @errors
end

#executableObject

The executable to be run.



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

def executable
  @executable
end

#input_fileObject

The file to be run trough the latex process.



11
12
13
# File 'lib/rubbr/runner.rb', line 11

def input_file
  @input_file
end

#verboser_warningsObject

Contains a list of possible verboser warnings after a run.



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

def verboser_warnings
  @verboser_warnings
end

#warningsObject

Contains a list of possible warnings after a run.



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

def warnings
  @warnings
end

Instance Method Details

#feedbackObject



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

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
    exit
  end
end

#runObject



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

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 = run.grep(messages).sort

    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