be9-rubbr 1.1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,62 @@
1
+ == 1.1.4.1 / 2009-01-20 (by be9)
2
+
3
+ * Loop mode (--loop). Build, wait a bit, check for changes, rebuild if changed, repeat.
4
+ * Build even if files were not changed since last build with --force option.
5
+ * Bugfix: color was not reset in color messages.
6
+
7
+ == 1.1.4 / 2008-06-20
8
+
9
+ * Bugfix: Very verbose messages needs to come in addition to normal verbose
10
+ messages.
11
+
12
+ == 1.1.3 / 2008-06-20
13
+
14
+ * Overfull and underfull hbox output can now be shown specifically with -V
15
+ switch.
16
+
17
+ == 1.1.2 / 2008-04-08
18
+
19
+ * BiBTeX style files (*.bst) now are copied from the vendor dir to
20
+ the build dir if needed.
21
+
22
+ == 1.1.1 / 2008-04-07
23
+
24
+ * Bugfix: lib/rubbr/change.rb not included because of faulty manifest.
25
+
26
+ == 1.1.1 / 2008-04-07
27
+
28
+ * Support for colorized cli output.
29
+
30
+ == 1.1.0 / 2008-04-06
31
+
32
+ * Source files are now compiled only if they've changed since last build.
33
+
34
+ == 1.0.6 / 2008-04-01
35
+
36
+ * New option: more verbose output.
37
+ * Somehow a graphic files were not copied to the builddir. This
38
+ was unnoticed since I've used the \graphicspath{} macro.
39
+
40
+ == 1.0.5 / 2008-03-30
41
+
42
+ * Small bugfixes and no default output on successful builds.
43
+
44
+ == 1.0.4 / 2008-03-07
45
+
46
+ * Added support for the pdflatex engine.
47
+
48
+ == 1.0.3 / 2008-02-28
49
+
50
+ * Rerun latex when labels are updated.
51
+
52
+ == 1.0.2 / 2008-02-28
53
+
54
+ * Exit program on errors and sort warnings
55
+
56
+ == 1.0.1 / 2008-02-10
57
+
58
+ * Many small bugfixes and code refactorings
59
+
60
+ == 1.0.0 / 2008-02-01
61
+
62
+ * First public release
data/Manifest.txt ADDED
@@ -0,0 +1,27 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/rubbr
6
+ lib/rubbr.rb
7
+ lib/rubbr/builder.rb
8
+ lib/rubbr/change.rb
9
+ lib/rubbr/cli.rb
10
+ lib/rubbr/options.rb
11
+ lib/rubbr/runner.rb
12
+ lib/rubbr/scm.rb
13
+ lib/rubbr/spell.rb
14
+ lib/rubbr/viewer.rb
15
+ lib/rubbr/builder/tex.rb
16
+ lib/rubbr/builder/ps.rb
17
+ lib/rubbr/builder/dvi.rb
18
+ lib/rubbr/runner/ps2pdf.rb
19
+ lib/rubbr/runner/pdflatex.rb
20
+ lib/rubbr/runner/latex.rb
21
+ lib/rubbr/runner/dvips.rb
22
+ lib/rubbr/runner/bibtex.rb
23
+ lib/rubbr/scm/subversion.rb
24
+ lib/rubbr/scm/mercurial.rb
25
+ lib/rubbr/viewer/ps.rb
26
+ lib/rubbr/viewer/pdf.rb
27
+ lib/rubbr/viewer/dvi.rb
data/README.txt ADDED
@@ -0,0 +1,78 @@
1
+ = rubbr
2
+
3
+ * http://rubyforge.org/projects/rubbr/
4
+ * by Eivind Uggedal <eu@redflavor.com>
5
+
6
+ == DESCRIPTION:
7
+
8
+ Build LaTeX documents.
9
+
10
+ == SYNOPSIS:
11
+
12
+ Usage: rubbr [options]
13
+ -f, --format [FORMAT] Select output format (dvi, ps, pdf)
14
+ -F, --force Force rebuild (even if files not changed)
15
+ -e, --engine [ENGINE] Select processing engine (latex, pdflatex)
16
+ -d, --display Display the document
17
+ -s, --spell Spell check source files
18
+ -l, --loop Go into a build loop
19
+ -D, --loop-delay [DELAY] Set loop delay in seconds (default: 0.5)
20
+ -v, --verbose Enable verbose feedback
21
+ -V, --verboser Enable very verbose feedback
22
+ -h, --help Show this help message
23
+
24
+ Standard project layout:
25
+
26
+ root_dir = Dir.pwd
27
+ source_dir = 'src'
28
+
29
+ @defaults ||= {
30
+ :root_dir => File.pwd,
31
+ :source_dir => source_dir,
32
+ :build_dir => 'tmp',
33
+ :distribution_dir => 'dist',
34
+ :template_file => 'template.erb',
35
+ :base_file => 'base',
36
+ :vendor_dir => source_dir + '/vendor',
37
+ :graphics_dir => source_dir + '/graphics',
38
+ :spell_dir => source_dir,
39
+ :spell_file => 'dictionary.ispell',
40
+ :distribution_name => distribution_name(root_dir),
41
+ :loop_delay => 0.5
42
+ }
43
+
44
+ All these can be changed with a config.yml in the root_dir:
45
+
46
+ ---
47
+ build_dir: build
48
+ graphics_dir: src/figures
49
+
50
+
51
+ == INSTALL:
52
+
53
+ gem install rubbr
54
+
55
+ == LICENSE:
56
+
57
+ (The MIT License)
58
+
59
+ Copyright (c) 2008 Eivind Uggedal <eu@redflavor.com>
60
+
61
+ Permission is hereby granted, free of charge, to any person obtaining
62
+ a copy of this software and associated documentation files (the
63
+ 'Software'), to deal in the Software without restriction, including
64
+ without limitation the rights to use, copy, modify, merge, publish,
65
+ distribute, sublicense, and/or sell copies of the Software, and to
66
+ permit persons to whom the Software is furnished to do so, subject to
67
+ the following conditions:
68
+
69
+ The above copyright notice and this permission notice shall be
70
+ included in all copies or substantial portions of the Software.
71
+
72
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
73
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
74
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
75
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
76
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
77
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
78
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require 'spec/rake/spectask'
4
+ require './lib/rubbr.rb'
5
+
6
+ Hoe.new('rubbr', Rubbr::VERSION) do |p|
7
+ p.rubyforge_name = 'rubbr'
8
+ p.author = 'Eivind Uggedal'
9
+ p.email = 'eu@redflavor.com'
10
+ p.summary = 'LaTeX builder'
11
+ # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
12
+ # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
13
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
14
+ p.remote_rdoc_dir = ''
15
+ end
16
+
17
+ desc "Run all specs"
18
+ Spec::Rake::SpecTask.new('specs') do |t|
19
+ t.spec_opts = ["--format", "specdoc", "--colour"]
20
+ t.spec_files = Dir['specs/*_spec.rb'].sort
21
+ end
22
+
23
+ task :cultivate do
24
+ system "touch Manifest.txt; rake check_manifest | grep -v \"(in \" | patch"
25
+ system "rake debug_gem | grep -v \"(in \" > `basename \\`pwd\\``.gemspec"
26
+ end
data/bin/rubbr ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubbr'
3
+
4
+ Rubbr.run
@@ -0,0 +1,18 @@
1
+ module Rubbr
2
+ module Builder
3
+ class Dvi < Base
4
+ def self.build
5
+ @output_format = 'ps'
6
+ base_dvi_file = Rubbr.options[:base_dvi_file]
7
+
8
+ build_dir do
9
+ dvips = Rubbr::Runner::DviPs.new(base_dvi_file)
10
+ end
11
+
12
+ distribute_file(base_dvi_file)
13
+ notice "Build of #{@output_format} completed for: #{base_dvi_file} " +
14
+ "in #{Rubbr.options[:build_dir]}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Rubbr
2
+ module Builder
3
+ class Ps < Base
4
+ def self.build
5
+ @output_format = 'pdf'
6
+ base_ps_file = Rubbr.options[:base_ps_file]
7
+
8
+ build_dir do
9
+ dvips = Rubbr::Runner::Ps2Pdf.new(base_ps_file)
10
+ end
11
+
12
+ distribute_file(base_ps_file)
13
+ notice "Build of #{@output_format} completed for: #{base_ps_file} " +
14
+ "in #{Rubbr.options[:build_dir]}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,88 @@
1
+ module Rubbr
2
+ module Builder
3
+ class Tex < Base
4
+ class << self
5
+ def build
6
+
7
+ clean_build_dir
8
+
9
+ base_latex_file = Rubbr.options[:base_latex_file]
10
+ base_bibtex_file = Rubbr.options[:base_bibtex_file]
11
+
12
+ case Rubbr.options[:engine]
13
+ when :pdflatex
14
+ @output_format = :pdf
15
+ preprocessor = Rubbr::Runner::PdfLaTeX
16
+ else
17
+ @output_format = :dvi
18
+ preprocessor = Rubbr::Runner::LaTeX
19
+ end
20
+
21
+ build_dir do
22
+ copy_source_files
23
+ copy_vendor_files
24
+ copy_graphic_files
25
+
26
+ # first run
27
+ latex = preprocessor.new(base_latex_file)
28
+
29
+ if base_bibtex_file && latex.warnings.join =~ /No file .+\.bbl/
30
+ bibtex = Rubbr::Runner::BibTeX.new(base_bibtex_file)
31
+ end
32
+
33
+ if latex.warnings.join =~ /No file .+\.(aux|toc)/
34
+ latex = preprocessor.new(base_latex_file)
35
+ end
36
+
37
+ if latex.warnings.join =~ /There were undefined citations/
38
+ latex = preprocessor.new(base_latex_file)
39
+ end
40
+
41
+ if latex.warnings.join =~ /Label\(s\) may have changed\. Rerun/
42
+ latex = preprocessor.new(base_latex_file)
43
+ end
44
+
45
+ # last run needed to get lof to be proper
46
+ latex = preprocessor.new(base_latex_file)
47
+
48
+ latex.feedback
49
+ if bibtex
50
+ bibtex.feedback
51
+ end
52
+ end
53
+ distribute_file(base_latex_file)
54
+ notice "Build of #@output_format completed for: #{base_latex_file} " +
55
+ "in #{Rubbr.options[:build_dir]}"
56
+ end
57
+
58
+ private
59
+
60
+ def clean_build_dir
61
+ if File.exists? Rubbr.options[:build_dir]
62
+ FileUtils.rm_r Rubbr.options[:build_dir]
63
+ end
64
+ end
65
+
66
+ def copy_source_files
67
+ copy_files(Rubbr.options[:source_dir], %w(tex bib cls))
68
+ end
69
+
70
+ def copy_vendor_files
71
+ copy_files(Rubbr.options[:vendor_dir], %w(sty clo cls cfg bst))
72
+ end
73
+
74
+ def copy_graphic_files
75
+ copy_files(Rubbr.options[:graphics_dir], %w(eps mps png))
76
+ end
77
+
78
+ def copy_files(source_dir, file_extensions)
79
+ file_extensions.each do |file_extension|
80
+ Dir["#{source_dir}/*.#{file_extension}"].each do |file|
81
+ FileUtils.cp(file, Rubbr.options[:build_dir])
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,101 @@
1
+ require 'fileutils'
2
+
3
+ module Rubbr
4
+
5
+ # Handles the business of building latex (and bibtex if needed) source
6
+ # files into binary formats as dvi, ps, and pdf. The latex and bibtex
7
+ # utilites need to be run a certain number of times so that things like
8
+ # table of contents, references, citations, etc become proper. This module
9
+ # tries to solve this issue by running the needed utilities only as many
10
+ # times as needed.
11
+ module Builder
12
+ extend Rubbr::Cli
13
+
14
+ # Build to the spesified format.
15
+ def self.build
16
+ if Rubbr::Change.d?
17
+ do_build
18
+ elsif Rubbr.options[:force]
19
+ notice "No changes in #{Rubbr.options[:build_dir]} since last build, building anyway (--force)"
20
+ do_build
21
+ else
22
+ notice "No changes in #{Rubbr.options[:build_dir]} since last build"
23
+ end
24
+ end
25
+
26
+ def self.build_in_a_loop
27
+ delay = Rubbr.options[:loop_delay]
28
+ delay = 0.5 if delay == 0.0
29
+
30
+ notice "Entering build loop. Press Ctrl-C to break out."
31
+
32
+ while true
33
+ if Rubbr::Change.d?
34
+ notice "Change detected, building"
35
+
36
+ do_build
37
+ end
38
+
39
+ sleep delay
40
+ end
41
+ end
42
+
43
+ def self.do_build
44
+ if Rubbr.options[:engine] == :pdflatex
45
+ Rubbr::Builder::Tex.build
46
+ else
47
+ case Rubbr.options[:format]
48
+ when :dvi
49
+ Rubbr::Builder::Tex.build
50
+ when :ps
51
+ Rubbr::Builder::Tex.build
52
+ Rubbr::Builder::Dvi.build
53
+ else
54
+ Rubbr::Builder::Tex.build
55
+ Rubbr::Builder::Dvi.build
56
+ Rubbr::Builder::Ps.build
57
+ end
58
+ end
59
+ end
60
+
61
+ class Base
62
+ class << self
63
+ include Rubbr::Cli
64
+
65
+ protected
66
+
67
+ def build_dir
68
+ prepare_dir(Rubbr.options[:build_dir]) do
69
+ yield
70
+ end
71
+ end
72
+
73
+ def distribute_file(base_file)
74
+ prepare_dir(Rubbr.options[:distribution_dir]) do
75
+ FileUtils.cp(File.join(Rubbr.options[:build_dir],
76
+ "#{base_file.gsub(/.\w+$/, '')}.#@output_format"),
77
+ File.join(Rubbr.options[:distribution_dir],
78
+ Rubbr.options[:distribution_name] +
79
+ ".#@output_format"))
80
+ end
81
+ end
82
+
83
+ def prepare_dir(dir)
84
+ if dir
85
+ FileUtils.mkdir_p dir unless File.exists? dir
86
+ FileUtils.cd dir do
87
+ yield
88
+ end
89
+ else
90
+ yield
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ %w(tex dvi ps).each do
97
+ |f| require File.dirname(__FILE__) + "/builder/#{f}"
98
+ end
99
+ end
100
+ end
101
+
@@ -0,0 +1,47 @@
1
+ module Rubbr
2
+
3
+ # Checks if source files have changed since last time they was accessed by
4
+ # computing and storing a hash of their contents.
5
+ class Change
6
+ require 'digest/md5'
7
+ require 'yaml'
8
+
9
+ def self.d?
10
+ sums = inventory
11
+ if changes?(sums)
12
+ write_inventory sums
13
+ true
14
+ else
15
+ false
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def self.inventory
22
+ source_files = Dir["#{Rubbr.options[:source_dir]}/*.tex"]
23
+ source_files.collect do |f|
24
+ [f, digest(File.read(f))]
25
+ end
26
+ end
27
+
28
+ def self.write_inventory(sums)
29
+ File.open(Rubbr.options[:inventory_file], 'w') do |f|
30
+ f.write(sums.to_yaml)
31
+ end
32
+ end
33
+
34
+ def self.read_inventory
35
+ YAML.load_file(Rubbr.options[:inventory_file])
36
+ end
37
+
38
+ def self.changes?(sums)
39
+ return true unless File.exists?(Rubbr.options[:inventory_file])
40
+ sums != read_inventory
41
+ end
42
+
43
+ def self.digest(contents)
44
+ Digest::MD5.hexdigest contents
45
+ end
46
+ end
47
+ end
data/lib/rubbr/cli.rb ADDED
@@ -0,0 +1,58 @@
1
+ module Rubbr
2
+
3
+ # Handles command line output and input.
4
+ module Cli
5
+ def notice(message)
6
+ puts color?(message, "\e[32m") if Rubbr.options[:verbose]
7
+ end
8
+
9
+ def warning(message)
10
+ puts color?(" - #{message}", "\e[33m") if Rubbr.options[:verbose]
11
+ end
12
+
13
+ def error(message)
14
+ puts color?(" * #{message}", "\e[31m")
15
+ end
16
+
17
+ def color?(msg, code)
18
+ Rubbr.options[:color] ? "#{code}#{msg}\e[0m" : msg
19
+ end
20
+
21
+ def disable_stdout
22
+ old_stdout = STDOUT.dup
23
+ STDOUT.reopen('/dev/null')
24
+ yield
25
+ STDOUT.reopen(old_stdout)
26
+ end
27
+
28
+ def disable_stderr
29
+ old_stderr = STDERR.dup
30
+ STDERR.reopen('/dev/null')
31
+ yield
32
+ STDERR.reopen(old_stderr)
33
+ end
34
+
35
+ def disable_stdinn
36
+ old_stdinn = STDIN.dup
37
+ STDIN.reopen('/dev/null')
38
+ yield
39
+ STDIN.reopen(old_stdinn)
40
+ end
41
+
42
+ def executable?(executable)
43
+ disable_stdout do
44
+ @existing = system("which #{executable}")
45
+ end
46
+ @existing
47
+ end
48
+
49
+ def valid_executable(executable)
50
+ if executable?(executable)
51
+ executable
52
+ else
53
+ error "Missing executable #{executable}"
54
+ exit
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,77 @@
1
+ module Rubbr
2
+ class Options
3
+ class << self
4
+ include Rubbr::Cli
5
+ def defaults
6
+ root_dir = Dir.pwd
7
+ source_dir = 'src'
8
+
9
+ @defaults ||= {
10
+ :root_dir => root_dir,
11
+ :source_dir => source_dir,
12
+ :build_dir => 'tmp',
13
+ :distribution_dir => 'dist',
14
+ :base_file => 'base',
15
+ :vendor_dir => source_dir + '/vendor',
16
+ :graphics_dir => source_dir + '/graphics',
17
+ :spell_dir => source_dir,
18
+ :spell_file => 'dictionary.ispell',
19
+ :inventory_file => '.inventory',
20
+ :distribution_name => distribution_name(root_dir),
21
+ :verbose => false,
22
+ :verboser => false,
23
+ :color => false,
24
+ :format => :dvi,
25
+ :engine => :latex,
26
+ :loop_delay => 0.5
27
+ }
28
+ end
29
+
30
+ # Fetching options from a config file if present and merges it
31
+ # with the defaults.
32
+ def setup
33
+ preference_file = "#{defaults[:root_dir]}/config.yml"
34
+ preferences = {}
35
+ if File.exists? preference_file
36
+ require 'yaml'
37
+ File.open(preference_file) { |file| preferences = YAML.load(file) }
38
+ end
39
+ base_file_variations(absolute_paths(defaults.merge(preferences)))
40
+ end
41
+
42
+ private
43
+
44
+ def distribution_name(root)
45
+ name = File.basename(root)
46
+ name << ".#{user_name}"
47
+ if stats = Rubbr::Scm.stats(root)
48
+ name << ".r#{stats[:revision].gsub(':', '_')}"
49
+ end
50
+ name
51
+ end
52
+
53
+ def user_name
54
+ `whoami`.strip
55
+ end
56
+
57
+ def absolute_paths(options)
58
+ options.each_key do |key|
59
+ if key.to_s =~ /\w+_dir/ && key != :root_dir
60
+ options[key.to_sym] = File.join(options[:root_dir],
61
+ options[key.to_sym])
62
+ end
63
+ end
64
+ options
65
+ end
66
+
67
+ def base_file_variations(options)
68
+ options[:base_latex_file] = options[:base_file] + '.tex'
69
+ options[:base_bibtex_file] = options[:base_file] + '.aux'
70
+ options[:base_dvi_file] = options[:base_file] + '.dvi'
71
+ options[:base_ps_file] = options[:base_file] + '.ps'
72
+ options[:base_pdf_file] = options[:base_file] + '.pdf'
73
+ options
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,15 @@
1
+ module Rubbr
2
+ module Runner
3
+ class BibTeX < Base
4
+ def initialize(input_file, executable='bibtex')
5
+ super
6
+ end
7
+
8
+ def run
9
+ messages = /^I (found no|couldn't open)/
10
+ @warnings = `#@executable #@input_file`.grep(messages)
11
+ feedback
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module Rubbr
2
+ module Runner
3
+ class DviPs < Base
4
+ def initialize(input_file, executable='dvips')
5
+ super
6
+ end
7
+
8
+ def run
9
+ disable_stderr do
10
+ @warnings = `#@executable -Ppdf #@input_file`.split("\n")
11
+ end
12
+ feedback
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module Rubbr
2
+ module Runner
3
+ class LaTeX < Base
4
+ def initialize(input_file, executable='latex')
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Rubbr
2
+ module Runner
3
+ class PdfLaTeX < Base
4
+ def initialize(input_file, executable='pdflatex')
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Rubbr
2
+ module Runner
3
+ class Ps2Pdf < Base
4
+ def initialize(input_file, executable='ps2pdf')
5
+ super
6
+ end
7
+
8
+ def run
9
+ disable_stderr do
10
+ @warnings = `#@executable #@input_file`.split("\n")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,93 @@
1
+ module Rubbr
2
+
3
+ # Takes care of running latex and related utilities. Gives helpful
4
+ # information if input files are missing and also cleans up the output of
5
+ # these utilities.
6
+ module Runner
7
+ class Base
8
+ include Rubbr::Cli
9
+
10
+ # The file to be run trough the latex process.
11
+ attr_accessor :input_file
12
+
13
+ # The executable to be run.
14
+ attr_accessor :executable
15
+
16
+ # Contains a list of possible warnings after a run.
17
+ attr_accessor :warnings
18
+
19
+ # Contains a list of possible verboser warnings after a run.
20
+ attr_accessor :verboser_warnings
21
+
22
+ # Contains a list of possible errors after a run.
23
+ attr_accessor :errors
24
+
25
+ def initialize(input_file, executable)
26
+ @input_file = input_file
27
+ @executable = valid_executable executable
28
+ @verboser_warnings = []
29
+ @errors = []
30
+
31
+ if File.exists? @input_file
32
+ run
33
+ else
34
+ error "Running of #@executable aborted. " +
35
+ "Input file: #@input_file not found"
36
+ end
37
+ end
38
+
39
+ def run
40
+ disable_stdinn do # No input in case of error correction dialogue
41
+ messages = /^(Overfull|Underfull|No file|Package \w+ Warning:|LaTeX Warning:)/
42
+ verbose_messages = /^(Overfull \\hbox|Underfull \\hbox)/
43
+
44
+ run = `#@executable #@input_file`
45
+ lines = run.split("\n")
46
+ @warnings = run.grep(messages).sort
47
+
48
+ if Rubbr.options[:verboser]
49
+
50
+ lines.each_with_index do |line, i|
51
+ if line =~ verbose_messages
52
+ @verboser_warnings << line
53
+ @verboser_warnings << lines[i+1]
54
+ end
55
+ end
56
+ end
57
+
58
+ while lines.shift
59
+ if lines.first =~ /^!/ # LaTeX Error, processing halted
60
+ 3.times { @errors << lines.shift }
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def feedback
67
+ unless @warnings.empty?
68
+ notice "Warnings from #@executable:"
69
+ @warnings.each do |message|
70
+ warning message
71
+ end
72
+ end
73
+ unless @verboser_warnings.empty?
74
+ notice "Verboser warnings from #@executable:"
75
+ @verboser_warnings.each do |message|
76
+ warning message
77
+ end
78
+ end
79
+ unless @errors.empty?
80
+ notice "Errors from #@executable:"
81
+ @errors.each do |message|
82
+ error message
83
+ end
84
+ exit
85
+ end
86
+ end
87
+ end
88
+
89
+ %w(latex bibtex dvips ps2pdf pdflatex).each do
90
+ |f| require File.dirname(__FILE__) + "/runner/#{f}"
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,31 @@
1
+ module Rubbr
2
+
3
+ # Extracts changeset stats from various SCM systems. This info can be
4
+ # included in the title page of the latex document and is especially helpful
5
+ # when working with draft versions.
6
+ module Scm
7
+ class Mercurial < Base
8
+
9
+ def initialize
10
+ super
11
+
12
+ @name = 'Mercurial'
13
+ @executable = valid_executable :hg
14
+
15
+ @revision, @date = parse_scm_stats
16
+
17
+ yield self if block_given?
18
+ end
19
+
20
+ def parse_scm_stats
21
+ return [nil, nil] unless @executable
22
+
23
+ raw_stats = `#@executable tip`
24
+ revision = raw_stats.scan(/^changeset: +(.+)/).first.first
25
+ date = raw_stats.scan(/^date: +(.+)/).first.first
26
+
27
+ [revision, date]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module Rubbr
2
+
3
+ # Extracts changeset stats from various SCM systems. This info can be
4
+ # included in the title page of the latex document and is especially helpful
5
+ # when working with draft versions.
6
+ module Scm
7
+ class Subversion < Base
8
+
9
+ def initialize
10
+ super
11
+
12
+ @name = 'Subversion'
13
+ @executable = valid_executable :svn
14
+
15
+ @revision, @date = parse_scm_stats
16
+
17
+ yield self if block_given?
18
+ end
19
+
20
+ def parse_scm_stats
21
+ return [nil, nil] unless @executable
22
+
23
+ raw_stats = `#@executable info`
24
+ revision = raw_stats.scan(/^Revision: (\d+)/).first.first
25
+ date = raw_stats.scan(/^Last Changed Date: (.+)/).first.first
26
+
27
+ [revision, date]
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/rubbr/scm.rb ADDED
@@ -0,0 +1,38 @@
1
+ module Rubbr
2
+
3
+ # Extracts changeset stats from various SCM systems. This info can be
4
+ # included in the title page of the latex document and is especially helpful
5
+ # when working with draft versions.
6
+ module Scm
7
+ class Base
8
+ include Rubbr::Cli
9
+
10
+ # The name of the SCM system.
11
+ attr_accessor :name
12
+
13
+ # The Mercurial executable.
14
+ attr_accessor :executable
15
+
16
+ # The revision and date of the tip/head/latest changeset.
17
+ attr_accessor :revision, :date
18
+
19
+ def collect_scm_stats
20
+ { :name => @name,
21
+ :revision => @revision,
22
+ :date => @date }
23
+ end
24
+ end
25
+
26
+ def self.stats(dir)
27
+ if File.exists? File.join(dir, '.svn')
28
+ Rubbr::Scm::Subversion.new.collect_scm_stats
29
+ elsif File.exists? File.join(dir, '.hg')
30
+ Rubbr::Scm::Mercurial.new.collect_scm_stats
31
+ end
32
+ end
33
+
34
+ %w(mercurial subversion).each do
35
+ |f| require File.dirname(__FILE__) + "/scm/#{f}"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ module Rubbr
2
+ class Spell
3
+ include Rubbr::Cli
4
+
5
+ def check
6
+ base_file_path = File.join(Rubbr.options[:source_dir],
7
+ Rubbr.options[:base_latex_file])
8
+ source_files = Dir["#{Rubbr.options[:source_dir]}/*.tex"]
9
+ source_files.delete base_file_path
10
+
11
+ dictionary_path = File.join(Rubbr.options[:spell_dir],
12
+ Rubbr.options[:spell_file])
13
+ executable = valid_executable(:ispell)
14
+
15
+ source_files.each do |file|
16
+ system "#{executable} -t -x -p #{dictionary_path} #{file}"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ module Rubbr
2
+ module Viewer
3
+ class Dvi < Base
4
+ def initialize(*args)
5
+ super
6
+ @view_name = 'dvi'
7
+ @executables = %w(evince xdvi kdvi)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Rubbr
2
+ module Viewer
3
+ class Pdf < Base
4
+ def initialize(*args)
5
+ super
6
+ @view_name = 'pdf'
7
+ @executables = %w(evince acroread xpdf gv)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Rubbr
2
+ module Viewer
3
+ class Ps < Base
4
+ def initialize(*args)
5
+ super
6
+ @view_name = 'ps'
7
+ @executables = %w(evince gv)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ module Rubbr
2
+ module Viewer
3
+
4
+ # View the spesified format.
5
+ def self.view
6
+ if Rubbr.options[:engine] == :pdflatex
7
+ Rubbr::Viewer::Pdf.new.launch
8
+ else
9
+ case Rubbr.options[:format]
10
+ when :dvi
11
+ Rubbr::Viewer::Dvi.new.launch
12
+ when :ps
13
+ Rubbr::Viewer::Ps.new.launch
14
+ else
15
+ Rubbr::Viewer::Pdf.new.launch
16
+ end
17
+ end
18
+ end
19
+
20
+ class Base
21
+ include Rubbr::Cli
22
+
23
+ # The name prefix of the distribution file.
24
+ attr_accessor :distribution_name
25
+
26
+ def distribution_file
27
+ File.join(Rubbr.options[:distribution_dir],
28
+ "#@distribution_name.#@view_name")
29
+ end
30
+
31
+ def initialize
32
+ @distribution_name = Rubbr.options[:distribution_name]
33
+
34
+ @view_name = 'base'
35
+ @executables = []
36
+ end
37
+
38
+ def find_viewer
39
+ @executables.each do |executable|
40
+ return executable if executable? executable
41
+ end
42
+ end
43
+
44
+ def launch
45
+ return unless viewer = find_viewer
46
+ fork { exec "#{viewer} #{distribution_file}" }
47
+ notice "Display of #@view_name completed for: #{@distribution_name}" +
48
+ ".#@view_name in #{Rubbr.options[:distribution_dir]}"
49
+ end
50
+ end
51
+
52
+ %w(dvi ps pdf).each do
53
+ |f| require File.dirname(__FILE__) + "/viewer/#{f}"
54
+ end
55
+ end
56
+ end
data/lib/rubbr.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'optparse'
2
+ $:.unshift File.dirname(__FILE__)
3
+
4
+ module Rubbr
5
+ VERSION = '1.1.4.1'
6
+
7
+ autoload :Options, 'rubbr/options'
8
+ autoload :Cli, 'rubbr/cli'
9
+ autoload :Config, 'rubbr/config'
10
+ autoload :Scm, 'rubbr/scm'
11
+ autoload :Change, 'rubbr/change'
12
+ autoload :Runner, 'rubbr/runner'
13
+ autoload :Builder, 'rubbr/builder'
14
+ autoload :Viewer, 'rubbr/viewer'
15
+ autoload :Spell, 'rubbr/spell'
16
+
17
+ class << self
18
+ @@cmd_opts = {}
19
+
20
+ def options
21
+ @@global_opts ||= Rubbr::Options.setup.merge(@@cmd_opts)
22
+ end
23
+
24
+ def run(args = ARGV)
25
+ opts = OptionParser.new do |opts|
26
+ opts.version = Rubbr::VERSION
27
+ opts.banner = 'Usage: rubbr [options]'
28
+
29
+ opts.on('-f', '--format [FORMAT]', [:dvi, :ps, :pdf],
30
+ 'Select output format (dvi, ps, pdf)') do |format|
31
+ @@cmd_opts[:format] = format
32
+ end
33
+
34
+ opts.on('-F', '--force', 'Force rebuild (even if files not changed)') do
35
+ @@cmd_opts[:force] = true
36
+ end
37
+
38
+ opts.on('-e', '--engine [ENGINE]', [:pdflatex, :ps, :pdf],
39
+ 'Select processing engine (latex, pdflatex)') do |engine|
40
+ @@cmd_opts[:engine] = engine
41
+ end
42
+
43
+ opts.on('-d', '--display', 'Display the document') do
44
+ @@cmd_opts[:view] = true
45
+ end
46
+
47
+ opts.on('-s', '--spell', 'Spell check source files') do
48
+ @@cmd_opts[:spell] = true
49
+ end
50
+
51
+ opts.on('-l', '--loop', 'Go into a build loop') do
52
+ @@cmd_opts[:loop] = true
53
+ end
54
+
55
+ opts.on('-D', '--loop-delay [DELAY]', Float, 'Set loop delay in seconds (default: 0.5)') do |delay|
56
+ @@cmd_opts[:loop_delay] = delay
57
+ end
58
+
59
+ opts.on('-v', '--verbose', 'Enable verbose feedback') do
60
+ @@cmd_opts[:verbose] = true
61
+ end
62
+
63
+ opts.on('-V', '--verboser', 'Enable verbose feedback for hboxes') do
64
+ @@cmd_opts[:verbose] = true
65
+ @@cmd_opts[:verboser] = true
66
+ end
67
+
68
+ opts.on('-c', '--color', 'Enable colorized feedback') do
69
+ @@cmd_opts[:color] = true
70
+ end
71
+
72
+ opts.on('-h', '--help', 'Show this help message') do
73
+ puts opts
74
+ exit 1
75
+ end
76
+ end
77
+
78
+ begin
79
+ opts.parse!(args)
80
+ rescue OptionParser::ParseError
81
+ puts opts
82
+ exit 1
83
+ end
84
+
85
+ case
86
+ when @@cmd_opts[:spell]
87
+ Rubbr::Spell.new.check
88
+
89
+ when @@cmd_opts[:view]
90
+ Rubbr::Builder.build
91
+ Rubbr::Viewer.view
92
+
93
+ when @@cmd_opts[:loop]
94
+ Rubbr::Builder.build_in_a_loop
95
+
96
+ else
97
+ Rubbr::Builder.build
98
+ end
99
+ end
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: be9-rubbr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Eivind Uggedal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-20 00:00:00 -08:00
13
+ default_executable: rubbr
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.2
23
+ version:
24
+ description: Build LaTeX documents.
25
+ email: eu@redflavor.com
26
+ executables:
27
+ - rubbr
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - History.txt
32
+ - Manifest.txt
33
+ - README.txt
34
+ files:
35
+ - History.txt
36
+ - Manifest.txt
37
+ - README.txt
38
+ - Rakefile
39
+ - bin/rubbr
40
+ - lib/rubbr.rb
41
+ - lib/rubbr/builder.rb
42
+ - lib/rubbr/change.rb
43
+ - lib/rubbr/cli.rb
44
+ - lib/rubbr/options.rb
45
+ - lib/rubbr/runner.rb
46
+ - lib/rubbr/scm.rb
47
+ - lib/rubbr/spell.rb
48
+ - lib/rubbr/viewer.rb
49
+ - lib/rubbr/builder/tex.rb
50
+ - lib/rubbr/builder/ps.rb
51
+ - lib/rubbr/builder/dvi.rb
52
+ - lib/rubbr/runner/ps2pdf.rb
53
+ - lib/rubbr/runner/pdflatex.rb
54
+ - lib/rubbr/runner/latex.rb
55
+ - lib/rubbr/runner/dvips.rb
56
+ - lib/rubbr/runner/bibtex.rb
57
+ - lib/rubbr/scm/subversion.rb
58
+ - lib/rubbr/scm/mercurial.rb
59
+ - lib/rubbr/viewer/ps.rb
60
+ - lib/rubbr/viewer/pdf.rb
61
+ - lib/rubbr/viewer/dvi.rb
62
+ has_rdoc: true
63
+ homepage: http://rubyforge.org/projects/rubbr/
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --main
67
+ - README.txt
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: rubbr
85
+ rubygems_version: 1.2.0
86
+ signing_key:
87
+ specification_version: 2
88
+ summary: LaTeX builder
89
+ test_files: []
90
+