Skip to content

Commit

Permalink
Some cleanup as RubyMine proposes (unnecessary double quotes, parens …
Browse files Browse the repository at this point in the history
…around conditions, return statements); cf issue #93.
  • Loading branch information
akerbos committed Feb 11, 2017
1 parent 30199bb commit 2def4ff
Show file tree
Hide file tree
Showing 25 changed files with 470 additions and 455 deletions.
18 changes: 9 additions & 9 deletions constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
# along with ltx2any. If not, see <http://www.gnu.org/licenses/>.

# TODO move to a properties file?
NAME = "ltx2any"
VERSION = "0.9a"
YEAR = "2016"
AUTHOR = "Raphael Reitzig"
TMPSUFFIX = "_tmp"
HASHFILE = ".hashes" # relative to tmp directory
NAME = 'ltx2any'
VERSION = '0.9a'
YEAR = '2016'
AUTHOR = 'Raphael Reitzig'
TMPSUFFIX = '_tmp'
HASHFILE = '.hashes' # relative to tmp directory
# TODO move this constant to HashManager?

LIBDIR = "lib"
EXTDIR = "extensions"
ENGDIR = "engines"
LIBDIR = 'lib'
EXTDIR = 'extensions'
ENGDIR = 'engines'
10 changes: 5 additions & 5 deletions engines/lualatex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
# You should have received a copy of the GNU General Public License
# along with ltx2any. If not, see <http://www.gnu.org/licenses/>.

Dependency.new("lualatex", :binary, [:engine, "lualatex"], :essential)
Dependency.new('lualatex', :binary, [:engine, 'lualatex'], :essential)

class LuaLaTeX < Engine

def initialize
super
@binary = "lualatex"
@extension = "pdf"
@description = "Uses lualatex to create a PDF"
@binary = 'lualatex'
@extension = 'pdf'
@description = 'Uses lualatex to create a PDF'

@target_file = "#{ParameterManager.instance[:jobname]}.#{extension}"
@old_hash = hash_result
Expand All @@ -49,7 +49,7 @@ def exec()
f = IO::popen(eval(lualatex))
log = f.readlines.map! { |s| Log.fix(s) }

return [File.exist?(@target_file), TeXLogParser.parse(log), log.join("").strip!]
[File.exist?(@target_file), TeXLogParser.parse(log), log.join('').strip!]
end
end

Expand Down
10 changes: 5 additions & 5 deletions engines/pdflatex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
# You should have received a copy of the GNU General Public License
# along with ltx2any. If not, see <http://www.gnu.org/licenses/>.

Dependency.new("pdflatex", :binary, [:engine, "pdflatex"], :essential)
Dependency.new('pdflatex', :binary, [:engine, 'pdflatex'], :essential)

class PdfLaTeX < Engine

def initialize
super
@binary = "pdflatex"
@extension = "pdf"
@description = "Uses pdflatex to create a PDF"
@binary = 'pdflatex'
@extension = 'pdf'
@description = 'Uses pdflatex to create a PDF'

@target_file = "#{ParameterManager.instance[:jobname]}.#{extension}"
@old_hash = hash_result
Expand All @@ -48,7 +48,7 @@ def exec()
f = IO::popen(eval(pdflatex))
log = f.readlines.map! { |s| Log.fix(s) }

return [File.exist?(@target_file), TeXLogParser.parse(log), log.join("").strip!]
[File.exist?(@target_file), TeXLogParser.parse(log), log.join('').strip!]
end
end

Expand Down
10 changes: 5 additions & 5 deletions engines/xelatex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
# You should have received a copy of the GNU General Public License
# along with ltx2any. If not, see <http://www.gnu.org/licenses/>.

Dependency.new("xelatex", :binary, [:engine, "xelatex"], :essential)
Dependency.new('xelatex', :binary, [:engine, 'xelatex'], :essential)

class XeLaTeX < Engine

def initialize
super
@binary = "xelatex"
@extension = "pdf"
@description = "Uses xelatex to create a PDF"
@binary = 'xelatex'
@extension = 'pdf'
@description = 'Uses xelatex to create a PDF'

@target_file = "#{ParameterManager.instance[:jobname]}.#{extension}"
@old_hash = hash_result
Expand All @@ -48,7 +48,7 @@ def exec()
f = IO::popen(eval(xelatex))
log = f.readlines.map! { |s| Log.fix(s) }

return [File.exist?(@target_file), TeXLogParser.parse(log), log.join("").strip!]
[File.exist?(@target_file), TeXLogParser.parse(log), log.join('').strip!]
end
end

Expand Down
26 changes: 13 additions & 13 deletions extensions/10_biber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
# You should have received a copy of the GNU General Public License
# along with ltx2any. If not, see <http://www.gnu.org/licenses/>.

Dependency.new("biber", :binary, [:extension, "Biber"], :essential)
Dependency.new('biber', :binary, [:extension, 'Biber'], :essential)

class Biber < Extension
def initialize
super
@name = "Biber"
@description = "Creates bibliographies (recommended)"
@name = 'Biber'
@description = 'Creates bibliographies (recommended)'
@sources = []
end

Expand All @@ -34,11 +34,11 @@ def do?(time)
usesbib = File.exist?("#{params[:jobname]}.bcf")
needrerun = false

if ( usesbib )
if usesbib
# Collect sources (needed for log parsing)
@sources = []
IO.foreach("#{params[:jobname]}.bcf") { |line|
if ( /<bcf:datasource[^>]*type="file"[^>]*>(.*?)<\/bcf:datasource>/ =~ line )
if /<bcf:datasource[^>]*type="file"[^>]*>(.*?)<\/bcf:datasource>/ =~ line
@sources.push($~[1])
end
}
Expand All @@ -54,9 +54,9 @@ def do?(time)
HashManager.instance.files_changed?("#{params[:jobname]}.bcf",
*@sources)
# Note: non-strict OR so that hashes are computed for next run
end
return usesbib && needrerun
end

usesbib && needrerun
end

def exec(time, progress)
Expand All @@ -75,21 +75,21 @@ def exec(time, progress)
errors = false
linectr = 1
log.each { |line|
if ( /^INFO - (.*)$/ =~ line )
if /^INFO - (.*)$/ =~ line
msgs.push(LogMessage.new(:info, nil, nil, [linectr], $~[1]))
elsif ( /^WARN - (.*)$/ =~ line )
elsif /^WARN - (.*)$/ =~ line
msgs.push(LogMessage.new(:warning, nil, nil, [linectr], $~[1]))
elsif ( /^ERROR - BibTeX subsystem: .*?(#{@sources.map { |s| Regexp.escape(s) }.join("|")}).*?, line (\d+), (.*)$/ =~ line )
elsif /^ERROR - BibTeX subsystem: .*?(#{@sources.map { |s| Regexp.escape(s) }.join('|')}).*?, line (\d+), (.*)$/ =~ line
msgs.push(LogMessage.new(:error, $~[1], [Integer($~[2])], [linectr], $~[3].strip))
errors = true
elsif ( /^ERROR - (.*)$/ =~ line )
elsif /^ERROR - (.*)$/ =~ line
msgs.push(LogMessage.new(:error, nil, nil, [linectr], $~[1]))
errors = true
end
linectr += 1
}

return [!errors, msgs, log.join("").strip!]
[!errors, msgs, log.join('').strip!]
end
end

Expand Down
34 changes: 17 additions & 17 deletions extensions/10_bibtex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
# You should have received a copy of the GNU General Public License
# along with ltx2any. If not, see <http://www.gnu.org/licenses/>.

Dependency.new("bibtex", :binary, [:extension, "BibTeX"], :essential)
Dependency.new('bibtex', :binary, [:extension, 'BibTeX'], :essential)

class BibTeX < Extension
def initialize
super
@name = "BibTeX"
@description = "Creates bibliographies (old)"
@name = 'BibTeX'
@description = 'Creates bibliographies (old)'

# For checking whether bibtex has to rerun, we need to keep the
# relevant parts of the _.aux file handy.
# TODO use internal store?
@grepfile = "bibtex_aux_grep"
@grepfile = 'bibtex_aux_grep'
end

def do?(time)
Expand All @@ -39,18 +39,18 @@ def do?(time)
stylefile = []
bibdata = []
grepdata = []
if ( File.exist?("#{params[:jobname]}.aux") )
File.open("#{params[:jobname]}.aux", "r") { |file|
if File.exist?("#{params[:jobname]}.aux")
File.open("#{params[:jobname]}.aux", 'r') { |file|
while ( line = file.gets )
if ( /^\\bibdata\{(.+?)\}$/ =~ line )
if /^\\bibdata\{(.+?)\}$/ =~ line
# If commas occur, add both a split version (multiple files)
# and the hole string (filename with comma), to be safe.
bibdata += $~[1].split(",").map { |s| "#{s}.bib" } + [$~[1]]
bibdata += $~[1].split(',').map { |s| "#{s}.bib" } + [$~[1]]
grepdata.push line.strip
elsif ( /^\\bibstyle\{(.+?)\}$/ =~ line )
elsif /^\\bibstyle\{(.+?)\}$/ =~ line
stylefile.push "#{$~[1]}.bst"
grepdata.push line.strip
elsif ( /^\\(bibcite|citation)/ =~ line )
elsif /^\\(bibcite|citation)/ =~ line
grepdata.push line.strip
end
end
Expand All @@ -62,7 +62,7 @@ def do?(time)

# Write relevant part of the _.aux file into a separate file for hashing
if usesbib
File.open(@grepfile, "w") { |f|
File.open(@grepfile, 'w') { |f|
f.write grepdata.join("\n")
}
end
Expand All @@ -73,7 +73,7 @@ def do?(time)
# Note: non-strict OR so that hashes get computed and stored
# for next run!

return usesbib && needsrerun
usesbib && needsrerun
end

def exec(time, progress)
Expand All @@ -91,14 +91,14 @@ def exec(time, progress)
msgs = []
errors = false
linectr = 1
lastline = ""
lastline = ''
log.each { |line|
if ( /^Warning--(.*)$/ =~ line )
if /^Warning--(.*)$/ =~ line
msgs.push(LogMessage.new(:warning, nil, nil, [linectr], $~[1]))
elsif ( /^(.*?)---line (\d+) of file (.*)$/ =~ line )
elsif /^(.*?)---line (\d+) of file (.*)$/ =~ line
msg = $~[1].strip
logline = [linectr]
if ( msg == "" )
if msg == ''
# Sometimes the message can be on the last line
msg = lastline
logline = [linectr - 1, linectr]
Expand All @@ -111,7 +111,7 @@ def exec(time, progress)
lastline = line
}

return [!errors, msgs, log.join("").strip!]
[!errors, msgs, log.join('').strip!]
end
end

Expand Down
30 changes: 15 additions & 15 deletions extensions/20_makeindex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
# You should have received a copy of the GNU General Public License
# along with ltx2any. If not, see <http://www.gnu.org/licenses/>.

Dependency.new("makeindex", :binary, [:extension, "makeindex"], :essential)
Dependency.new('makeindex', :binary, [:extension, 'makeindex'], :essential)

class MakeIndex < Extension
def initialize
super

@name = "makeindex"
@description = "Creates an index"
@name = 'makeindex'
@description = 'Creates an index'
end

def do?(time)
Expand All @@ -46,13 +46,13 @@ def exec(time, progress)
# Uses the following variables:
# * jobname -- name of the main LaTeX file (without file ending)
# * mistyle -- name of the makeindex style file (with file ending)
makeindex = { "default" => '"makeindex -q \"#{params[:jobname]}\" 2>&1"',
"styled" => '"makeindex -q -s \"#{mistyle}\" \"#{params[:jobname]}\" 2>&1"'}
makeindex = {'default' => '"makeindex -q \"#{params[:jobname]}\" 2>&1"',
'styled' => '"makeindex -q -s \"#{mistyle}\" \"#{params[:jobname]}\" 2>&1"'}

version = "default"
version = 'default'
mistyle = nil
Dir["*.ist"].each { |f|
version = "styled"
Dir['*.ist'].each { |f|
version = 'styled'
mistyle = f
}

Expand All @@ -64,7 +64,7 @@ def exec(time, progress)
}

log2 = []
File.open("#{params[:jobname]}.ilg", "r") { |f|
File.open("#{params[:jobname]}.ilg", 'r') { |f|
log2 = f.readlines
}

Expand All @@ -75,27 +75,27 @@ def exec(time, progress)
linectr = 1
errors = false
log.each { |line|
if ( /^!! (.*?) \(file = (.+?), line = (\d+)\):$/ =~ line )
if /^!! (.*?) \(file = (.+?), line = (\d+)\):$/ =~ line
current = [:error, $~[2], [Integer($~[3])], [linectr], "#{$~[1]}: "]
errors = true
elsif ( /^\#\# (.*?) \(input = (.+?), line = (\d+); output = .+?, line = \d+\):$/ =~ line )
elsif /^\#\# (.*?) \(input = (.+?), line = (\d+); output = .+?, line = \d+\):$/ =~ line
current = [:warning, $~[2], [Integer($~[3])], [linectr], "#{$~[1]}: "]
elsif ( current != [] && /^\s+-- (.*)$/ =~ line )
elsif current != [] && /^\s+-- (.*)$/ =~ line
current[3][1] = linectr
msgs.push(LogMessage.new(current[0], current[1], current[2],
current[3], current[4] + $~[1].strip))
current = []
elsif ( /Option -g invalid/ =~ line )
elsif /Option -g invalid/ =~ line
msgs.push(LogMessage.new(:error, nil, nil, [linectr], line.strip))
errors = true
elsif ( /Can't create output index file/ =~ line )
elsif /Can't create output index file/ =~ line
msgs.push(LogMessage.new(:error, nil, nil, [linectr], line.strip))
errors = true
end
linectr += 1
}

return [!errors, msgs, log.join("").strip!]
[!errors, msgs, log.join('').strip!]
end
end

Expand Down
Loading

0 comments on commit 2def4ff

Please sign in to comment.