Skip to content

Commit

Permalink
Improves code style.
Browse files Browse the repository at this point in the history
Applies a number of auto-fixes from RubyMine/RuboCop.
Pertains to issue #93.
  • Loading branch information
reitzig committed Feb 24, 2018
1 parent 76f69b3 commit 8111f83
Show file tree
Hide file tree
Showing 31 changed files with 1,119 additions and 1,145 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Metrics/LineLength:
Enabled: false
24 changes: 12 additions & 12 deletions constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
# You should have received a copy of the GNU General Public License
# 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
# TODO move this constant to HashManager?
# TODO: move to a properties file?
NAME = 'ltx2any'.freeze
VERSION = '0.9b'.freeze
YEAR = '2018'.freeze
AUTHOR = 'Raphael Reitzig'.freeze
TMPSUFFIX = '_tmp'.freeze
HASHFILE = '.hashes'.freeze # relative to tmp directory
# TODO: move this constant to HashManager?

LIBDIR = 'lib'
EXTDIR = 'extensions'
ENGDIR = 'engines'
LOGWDIR = 'logwriters'
LIBDIR = 'lib'.freeze
EXTDIR = 'extensions'.freeze
ENGDIR = 'engines'.freeze
LOGWDIR = 'logwriters'.freeze
15 changes: 8 additions & 7 deletions engines/lualatex.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2010-2016, Raphael Reitzig
# Copyright 2010-2018, Raphael Reitzig
# <[email protected]>
#
# This file is part of ltx2any.
Expand All @@ -18,35 +18,36 @@

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

# TODO: document
class LuaLaTeX < Engine

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

@target_file = "#{ParameterManager.instance[:jobname]}.#{extension}"
@old_hash = hash_result
end

def do?
!File.exist?(@target_file) || hash_result != @old_hash
end

def hash_result
HashManager.hash_file(@target_file,
HashManager.hash_file(@target_file,
without: /\/CreationDate|\/ModDate|\/ID|\/Type\/XRef\/Index/)
end

def exec
@old_hash = hash_result

# Command for the main LaTeX compilation work
params = ParameterManager.instance
lualatex = '"lualatex -file-line-error -interaction=nonstopmode #{params[:enginepar]} \"#{params[:jobfile]}\""'

f = IO::popen(eval(lualatex))
f = IO.popen(eval(lualatex))
log = f.readlines.map! { |s| Log.fix(s) }

{ success: File.exist?(@target_file), messages: TeXLogParser.parse(log), log: log.join('').strip! }
Expand Down
13 changes: 7 additions & 6 deletions engines/pdflatex.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2010-2016, Raphael Reitzig
# Copyright 2010-2018, Raphael Reitzig
# <[email protected]>
#
# This file is part of ltx2any.
Expand All @@ -18,22 +18,23 @@

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

class PdfLaTeX < Engine
# TODO: document
class PdfLaTeX < Engine

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

@target_file = "#{ParameterManager.instance[:jobname]}.#{extension}"
@old_hash = hash_result
end

def do?
!File.exist?(@target_file) || hash_result != @old_hash
end

def hash_result
HashManager.hash_file(@target_file, without: /\/CreationDate|\/ModDate|\/ID/)
end
Expand All @@ -45,7 +46,7 @@ def exec
params = ParameterManager.instance
pdflatex = '"pdflatex -file-line-error -interaction=nonstopmode #{params[:enginepar]} \"#{params[:jobfile]}\""'

f = IO::popen(eval(pdflatex))
f = IO.popen(eval(pdflatex))
log = f.readlines.map! { |s| Log.fix(s) }

{ success: File.exist?(@target_file), messages: TeXLogParser.parse(log), log: log.join('').strip! }
Expand Down
14 changes: 7 additions & 7 deletions engines/xelatex.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2010-2016, Raphael Reitzig
# Copyright 2010-2018, Raphael Reitzig
# <[email protected]>
#
# This file is part of ltx2any.
Expand All @@ -18,34 +18,34 @@

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

# TODO: document
class XeLaTeX < Engine

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

@target_file = "#{ParameterManager.instance[:jobname]}.#{extension}"
@old_hash = hash_result
end

def do?
!File.exist?(@target_file) || hash_result != @old_hash
end

def hash_result
HashManager.hash_file(@target_file, drop_from: /CIDFontType0C|Type1C/)
end

def exec
@old_hash = hash_result

# Command for the main LaTeX compilation work
params = ParameterManager.instance
xelatex = '"xelatex -file-line-error -interaction=nonstopmode #{params[:enginepar]} \"#{params[:jobfile]}\""'

f = IO::popen(eval(xelatex))
f = IO.popen(eval(xelatex))
log = f.readlines.map! { |s| Log.fix(s) }

{ success: File.exist?(@target_file), messages: TeXLogParser.parse(log), log: log.join('').strip! }
Expand Down
21 changes: 11 additions & 10 deletions extensions/10_biber.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2010-2016, Raphael Reitzig
# Copyright 2010-2018, Raphael Reitzig
# <[email protected]>
#
# This file is part of ltx2any.
Expand All @@ -18,6 +18,7 @@

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

# TODO: document
class Biber < Extension
def initialize
super
Expand All @@ -28,12 +29,12 @@ def initialize

def do?(time)
return false unless time == 1

params = ParameterManager.instance

usesbib = File.exist?("#{params[:jobname]}.bcf")
needrerun = false

if usesbib
# Collect sources (needed for log parsing)
@sources = []
Expand All @@ -43,8 +44,8 @@ def do?(time)
end
}
@sources.uniq!


# Aside from the first run (no bbl),
# there are two things that prompt us to rerun:
# * changes to the bcf file (which includes all kinds of things,
Expand All @@ -53,21 +54,21 @@ def do?(time)
needrerun = !File.exist?("#{params[:jobname]}.bbl") | # Is this the first run?
HashManager.instance.files_changed?("#{params[:jobname]}.bcf",
*@sources)
# Note: non-strict OR so that hashes are computed for next run
# Note: non-strict OR so that hashes are computed for next run
end

usesbib && needrerun
end

def exec(time, progress)
params = ParameterManager.instance

# Command to process bibtex bibliography if necessary.
# Uses the following variables:
# * jobname -- name of the main LaTeX file (without file ending)
biber = '"biber \"#{params[:jobname]}\""'

f = IO::popen(eval(biber))
f = IO.popen(eval(biber))
log = f.readlines

# Dig trough output and find errors
Expand All @@ -92,5 +93,5 @@ def exec(time, progress)
{ success: !errors, messages: msgs, log: log.join('').strip! }
end
end

Extension.add Biber
41 changes: 21 additions & 20 deletions extensions/10_bibtex.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2010-2016, Raphael Reitzig
# Copyright 2010-2018, Raphael Reitzig
# <[email protected]>
#
# This file is part of ltx2any.
Expand All @@ -18,48 +18,49 @@

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

# TODO: document
class BibTeX < Extension
def initialize
super
super
@name = 'BibTeX'
@description = 'Creates bibliographies (old)'
# For checking whether bibtex has to rerun, we need to keep the

# 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'
end

def do?(time)
return false unless time == 1

params = ParameterManager.instance

# Collect used bibdata files and style file
stylefile = []
bibdata = []
grepdata = []
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]]
grepdata.push line.strip
elsif /^\\bibstyle\{(.+?)\}$/ =~ line
grepdata.push line.strip
elsif /^\\bibstyle{(.+?)}$/ =~ line
stylefile.push "#{$~[1]}.bst"
grepdata.push line.strip
grepdata.push line.strip
elsif /^\\(bibcite|citation)/ =~ line
grepdata.push line.strip
end
grepdata.push line.strip
end
end
}
end
end

# Check whether bibtex is necessary at all
usesbib = bibdata.size > 0
usesbib = !bibdata.empty?

# Write relevant part of the _.aux file into a separate file for hashing
if usesbib
File.open(@grepfile, 'w') { |f|
Expand All @@ -78,13 +79,13 @@ def do?(time)

def exec(time, progress)
params = ParameterManager.instance

# Command to process bibtex bibliography if necessary.
# Uses the following variables:
# * jobname -- name of the main LaTeX file (without file ending)
bibtex = '"bibtex \"#{params[:jobname]}\""'

f = IO::popen(eval(bibtex))
f = IO.popen(eval(bibtex))
log = f.readlines

# Dig trough output and find errors
Expand All @@ -103,7 +104,7 @@ def exec(time, progress)
msg = lastline
logline = [linectr - 1, linectr]
end

msgs.push(LogMessage.new(:error, $~[3], [Integer($~[2])], logline, msg))
errors = true
end
Expand All @@ -114,5 +115,5 @@ def exec(time, progress)
{ success: !errors, messages: msgs, log: log.join('').strip! }
end
end

Extension.add BibTeX
Loading

0 comments on commit 8111f83

Please sign in to comment.