Fix Rubocop style issues
This commit is contained in:
parent
15727a2f92
commit
bfdff5745b
106
rubberin
106
rubberin
|
@ -25,17 +25,18 @@
|
||||||
# Public License for more details.
|
# Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License along
|
# You should have received a copy of the GNU General Public License along
|
||||||
# with this p rogram; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
require 'getoptlong'
|
require "getoptlong"
|
||||||
require 'rb-inotify'
|
require "rb-inotify"
|
||||||
require 'pathname'
|
require "pathname"
|
||||||
|
|
||||||
# Small necessary Pathname class extension.
|
# Small necessary Pathname class extension.
|
||||||
class Pathname
|
class Pathname
|
||||||
def extname=(ext)
|
def extname=(ext)
|
||||||
raise "Invalid extension" unless ext.is_a? String and ext.match(/^\./)
|
raise "Invalid extension" unless ext.is_a?(String) && ext.match(/^\./)
|
||||||
|
|
||||||
@path.sub!(/#{extname}$/, ext)
|
@path.sub!(/#{extname}$/, ext)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -44,7 +45,7 @@ end
|
||||||
|
|
||||||
# Print the usage.
|
# Print the usage.
|
||||||
def usage
|
def usage
|
||||||
puts "Usage: #{Program} [options]... [tex-file] [rubber-options]..."
|
puts "Usage: #{PROGRAM} [options]... [tex-file] [rubber-options]..."
|
||||||
end
|
end
|
||||||
|
|
||||||
# Print the command line help.
|
# Print the command line help.
|
||||||
|
@ -62,34 +63,35 @@ end
|
||||||
|
|
||||||
# Compile the input file using the right options based on the mode.
|
# Compile the input file using the right options based on the mode.
|
||||||
def compile(infile, mode)
|
def compile(infile, mode)
|
||||||
mode_opt = {:pdf => "--pdf",
|
mode_opt = { pdf: "--pdf",
|
||||||
:ps => "--ps",
|
ps: "--ps",
|
||||||
:pspdf => "--ps --pdf"}[mode]
|
pspdf: "--ps --pdf" }[mode]
|
||||||
params = ARGV.join(' ')
|
params = ARGV.join(" ")
|
||||||
err_file = infile.with_extname('err')
|
err_file = infile.with_extname("err")
|
||||||
|
|
||||||
_ret = system "rubber --inplace #{mode_opt} #{params} #{infile} 2> #{err_file}"
|
_ret = system "rubber --inplace #{mode_opt} #{params} #{infile} 2> #{err_file}"
|
||||||
File.open(err_file) { |file| puts file.read }
|
File.open(err_file) { |file| puts file.read }
|
||||||
# Remove the output save file if compile was succesful.
|
# Remove the output save file if compile was succesful.
|
||||||
#clean(infile) if ret
|
# clean(infile) if ret
|
||||||
end
|
end
|
||||||
|
|
||||||
# Start the right viewer based on the mode.
|
# Start the right viewer based on the mode.
|
||||||
def view(infile, mode)
|
def view(infile, mode)
|
||||||
case mode
|
case mode
|
||||||
when :dvi
|
when :dvi
|
||||||
exec "xdvi.bin", "-watchfile", "1",
|
exec "xdvi.bin",
|
||||||
"-name", "xdvi", infile.with_extname('dvi').to_s
|
"-watchfile", "1",
|
||||||
when :ps
|
"-name", "xdvi", infile.with_extname("dvi").to_s
|
||||||
exec "evince", infile.with_extname('ps').to_s
|
when :ps
|
||||||
when :pdf, :pspdf
|
exec "evince", infile.with_extname("ps").to_s
|
||||||
exec "evince", infile.with_extname('pdf').to_s
|
when :pdf, :pspdf
|
||||||
|
exec "evince", infile.with_extname("pdf").to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clean up cruft related to compilation of the input file.
|
# Clean up cruft related to compilation of the input file.
|
||||||
def clean(infile)
|
def clean(infile)
|
||||||
err_file = infile.with_extname('err')
|
err_file = infile.with_extname("err")
|
||||||
File.unlink(err_file) if err_file.exist?
|
File.unlink(err_file) if err_file.exist?
|
||||||
system "rubber --clean --inplace #{infile}"
|
system "rubber --clean --inplace #{infile}"
|
||||||
end
|
end
|
||||||
|
@ -97,55 +99,55 @@ end
|
||||||
# Reload the right viewer based on the mode.
|
# Reload the right viewer based on the mode.
|
||||||
def reload(infile, mode)
|
def reload(infile, mode)
|
||||||
case mode
|
case mode
|
||||||
when :ps
|
when :ps
|
||||||
system "evince", infile.with_extname('ps').to_s
|
system "evince", infile.with_extname("ps").to_s
|
||||||
when :pdf, :pspdf
|
when :pdf, :pspdf
|
||||||
system "evince", infile.with_extname('pdf').to_s
|
system "evince", infile.with_extname("pdf").to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
## Initialisation
|
## Initialisation
|
||||||
Program = File.basename $0
|
PROGRAM = File.basename($PROGRAM_NAME).freeze
|
||||||
Version = '0.6'
|
VERSION = "0.6".freeze
|
||||||
|
|
||||||
# Parse the command line options.
|
# Parse the command line options.
|
||||||
# Determine the compile mode from the options.
|
# Determine the compile mode from the options.
|
||||||
mode = :dvi
|
mode = :dvi
|
||||||
opts = GetoptLong.new(
|
opts = GetoptLong.new(["--help", "-h", GetoptLong::NO_ARGUMENT],
|
||||||
[ "--help", "-h", GetoptLong::NO_ARGUMENT ],
|
["--ps", "-p", GetoptLong::NO_ARGUMENT],
|
||||||
[ "--ps", "-p", GetoptLong::NO_ARGUMENT ],
|
["--pdf", "-d", GetoptLong::NO_ARGUMENT],
|
||||||
[ "--pdf", "-d", GetoptLong::NO_ARGUMENT ],
|
["--version", "-v", GetoptLong::NO_ARGUMENT])
|
||||||
[ "--version", "-v", GetoptLong::NO_ARGUMENT ])
|
|
||||||
opts.ordering = GetoptLong::REQUIRE_ORDER
|
opts.ordering = GetoptLong::REQUIRE_ORDER
|
||||||
opts.quiet = true
|
opts.quiet = true
|
||||||
opts.each do |opt, arg|
|
opts.each do |opt, _arg|
|
||||||
case opt
|
case opt
|
||||||
when "--help"
|
when "--help"
|
||||||
help
|
help
|
||||||
exit 0
|
exit 0
|
||||||
when "--ps"
|
when "--ps"
|
||||||
mode = :ps
|
mode = :ps
|
||||||
when "--pdf"
|
when "--pdf"
|
||||||
mode = if mode == :ps then :pspdf
|
mode = if mode == :ps then :pspdf
|
||||||
else :pdf
|
else :pdf
|
||||||
end
|
end
|
||||||
when "--version"
|
when "--version"
|
||||||
puts "#{Program} #{Version}"
|
puts "#{PROGRAM} #{VERSION}"
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the input file from the arguments.
|
# Get the input file from the arguments.
|
||||||
if ARGV.length < 1
|
if ARGV.empty?
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
infile = Pathname.new(ARGV.shift)
|
infile = Pathname.new(ARGV.shift)
|
||||||
def infile.base
|
def infile.base
|
||||||
self.basename(self.extname)
|
basename(extname)
|
||||||
end
|
end
|
||||||
|
|
||||||
def infile.with_extname(ext)
|
def infile.with_extname(ext)
|
||||||
file = self.base
|
file = base
|
||||||
file.extname = ".#{ext}"
|
file.extname = ".#{ext}"
|
||||||
file
|
file
|
||||||
end
|
end
|
||||||
|
@ -154,8 +156,8 @@ end
|
||||||
# Check the input file.
|
# Check the input file.
|
||||||
begin
|
begin
|
||||||
File.open(infile) {}
|
File.open(infile) {}
|
||||||
rescue => err
|
rescue SystemCallError => e
|
||||||
puts "#{Program}: #{err}"
|
puts "#{PROGRAM}: #{e}"
|
||||||
exit 2
|
exit 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -177,9 +179,10 @@ view(infile, mode) if not viewer_pid
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# If xdvi exits, this program should exit too.
|
|
||||||
|
# If xdvi/evince exits, this program should exit too.
|
||||||
Signal.trap("CLD") do
|
Signal.trap("CLD") do
|
||||||
puts "#{Program}: viewer exited, so will I!"
|
puts "#{PROGRAM}: viewer exited, so will I!"
|
||||||
clean(infile)
|
clean(infile)
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
@ -195,6 +198,7 @@ dirs.each do |dir|
|
||||||
# Only compile if a dependency of the input file has been modified
|
# Only compile if a dependency of the input file has been modified
|
||||||
file_path = (dir + ev.name).to_s
|
file_path = (dir + ev.name).to_s
|
||||||
next unless files.include? file_path
|
next unless files.include? file_path
|
||||||
|
|
||||||
puts "I: file #{ev.name} modified, compiling #{infile}..."
|
puts "I: file #{ev.name} modified, compiling #{infile}..."
|
||||||
compile(infile, mode)
|
compile(infile, mode)
|
||||||
reload(infile, mode)
|
reload(infile, mode)
|
||||||
|
|
Loading…
Reference in New Issue