rubbr 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ == 1.0.0 / 2008-02-01
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
5
+
data/Manifest.txt ADDED
@@ -0,0 +1,26 @@
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/cli.rb
9
+ lib/rubbr/options.rb
10
+ lib/rubbr/runner.rb
11
+ lib/rubbr/scm.rb
12
+ lib/rubbr/spell.rb
13
+ lib/rubbr/viewer.rb
14
+ lib/rubbr/builder/tex.rb
15
+ lib/rubbr/builder/ps.rb
16
+ lib/rubbr/builder/dvi.rb
17
+ lib/rubbr/runner/ps2pdf.rb
18
+ lib/rubbr/runner/pdflatex.rb
19
+ lib/rubbr/runner/latex.rb
20
+ lib/rubbr/runner/dvips.rb
21
+ lib/rubbr/runner/bibtex.rb
22
+ lib/rubbr/scm/subversion.rb
23
+ lib/rubbr/scm/mercurial.rb
24
+ lib/rubbr/viewer/ps.rb
25
+ lib/rubbr/viewer/pdf.rb
26
+ lib/rubbr/viewer/dvi.rb
data/README.txt ADDED
@@ -0,0 +1,70 @@
1
+ rubbr
2
+ by Eivind Uggedal
3
+ http://rubbr.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Build LaTeX documents.
8
+
9
+ == SYNOPSIS:
10
+
11
+ Usage: rubbr [options]
12
+ -f, --format [FORMAT] Select output format (dvi, ps, pdf)
13
+ -v, --view View the document
14
+ -s, --spell Spell check source files
15
+ -h, --help Show this help message
16
+
17
+ Standard project layout:
18
+
19
+ root_dir = Dir.pwd
20
+ source_dir = 'src'
21
+
22
+ @defaults ||= {
23
+ :root_dir => File.pwd,
24
+ :source_dir => source_dir,
25
+ :build_dir => 'tmp',
26
+ :distribution_dir => 'dist',
27
+ :template_file => 'template.erb',
28
+ :base_file => 'base',
29
+ :vendor_dir => source_dir + '/vendor',
30
+ :graphics_dir => source_dir + '/graphics',
31
+ :spell_dir => source_dir,
32
+ :spell_file => 'dictionary.ispell',
33
+ :distribution_name => distribution_name(root_dir)
34
+ }
35
+
36
+ All these can be changed with a config.yml in the root_dir:
37
+
38
+ ---
39
+ build_dir: build
40
+ graphics_dir: src/figures
41
+
42
+
43
+ == INSTALL:
44
+
45
+ gem install rubbr
46
+
47
+ == LICENSE:
48
+
49
+ (The MIT License)
50
+
51
+ Copyright (c) 2008 Eivind Uggedal
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of this software and associated documentation files (the
55
+ 'Software'), to deal in the Software without restriction, including
56
+ without limitation the rights to use, copy, modify, merge, publish,
57
+ distribute, sublicense, and/or sell copies of the Software, and to
58
+ permit persons to whom the Software is furnished to do so, subject to
59
+ the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be
62
+ included in all copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
65
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/rubbr.rb'
6
+
7
+ Hoe.new('rubbr', Rubbr::VERSION) do |p|
8
+ p.rubyforge_name = 'rubbr'
9
+ p.author = 'Eivind Uggedal'
10
+ p.email = 'eu@redflavor.com'
11
+ p.summary = 'LaTeX builder'
12
+ # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
13
+ # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
14
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
+ p.remote_rdoc_dir = ''
16
+ end
17
+
18
+ # vim: syntax=Ruby
data/bin/rubbr ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubbr'
3
+
4
+ Rubbr.run
data/lib/rubbr.rb ADDED
@@ -0,0 +1,80 @@
1
+ require 'optparse'
2
+ $:.unshift File.dirname(__FILE__)
3
+
4
+ module Rubbr
5
+ VERSION = '1.0.0'
6
+
7
+ autoload :Options, 'rubbr/options'
8
+ autoload :Cli, 'rubbr/cli'
9
+ autoload :Config, 'rubbr/config'
10
+ autoload :Scm, 'rubbr/scm'
11
+ autoload :Template, 'rubbr/template'
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
+ # Setting up an options accessor.
19
+ def options
20
+ @@options ||= Rubbr::Options.setup
21
+ end
22
+
23
+ def run(args = ARGV)
24
+ options = {}
25
+
26
+ opts = OptionParser.new do |opts|
27
+ opts.version = Rubbr::VERSION
28
+ opts.banner = 'Usage: rubbr [options]'
29
+
30
+ opts.on('-f', '--format [FORMAT]', [:dvi, :ps, :pdf],
31
+ 'Select output format (dvi, ps, pdf)') do |format|
32
+ options[:format] = format
33
+ end
34
+
35
+ opts.on('-v', '--view', 'View the document') do
36
+ options[:view] = true
37
+ end
38
+
39
+ opts.on('-s', '--spell', 'Spell check source files') do
40
+ options[:spell] = true
41
+ end
42
+
43
+ opts.on('-h', '--help', 'Show this help message') do
44
+ puts opts
45
+ exit 1
46
+ end
47
+ end
48
+
49
+ begin
50
+ opts.parse!(args)
51
+ rescue OptionParser::ParseError
52
+ puts opts
53
+ exit 1
54
+ end
55
+
56
+ if options[:spell]
57
+ spell
58
+ elsif options[:view]
59
+ view(options[:format])
60
+ else
61
+ build(options[:format])
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def build(format)
68
+ Rubbr::Builder.build(format)
69
+ end
70
+
71
+ def view(format)
72
+ build(format)
73
+ Rubbr::Viewer.view(format)
74
+ end
75
+
76
+ def spell
77
+ Rubbr::Spell.check
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,68 @@
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
+
13
+ # Build to the spesified format.
14
+ def self.build(format)
15
+ case format
16
+ when :dvi
17
+ Rubbr::Builder::Tex.build
18
+ when :ps
19
+ Rubbr::Builder::Tex.build
20
+ Rubbr::Builder::Dvi.build
21
+ else
22
+ Rubbr::Builder::Tex.build
23
+ Rubbr::Builder::Dvi.build
24
+ Rubbr::Builder::Ps.build
25
+ end
26
+ end
27
+
28
+ class Base
29
+ class << self
30
+ include Rubbr::Cli
31
+
32
+ protected
33
+
34
+ def build_dir
35
+ prepare_dir(Rubbr.options[:build_dir]) do
36
+ yield
37
+ end
38
+ end
39
+
40
+ def distribute_file(base_file)
41
+ prepare_dir(Rubbr.options[:distribution_dir]) do
42
+ FileUtils.cp(File.join(Rubbr.options[:build_dir],
43
+ "#{base_file.gsub(/.\w+$/, '')}.#@output_format"),
44
+ File.join(Rubbr.options[:distribution_dir],
45
+ Rubbr.options[:distribution_name] +
46
+ ".#@output_format"))
47
+ end
48
+ end
49
+
50
+ def prepare_dir(dir)
51
+ if dir
52
+ FileUtils.mkdir_p dir unless File.exists? dir
53
+ FileUtils.cd dir do
54
+ yield
55
+ end
56
+ else
57
+ yield
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ %w(tex dvi ps).each do
64
+ |f| require File.dirname(__FILE__) + "/builder/#{f}"
65
+ end
66
+ end
67
+ end
68
+
@@ -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,71 @@
1
+ module Rubbr
2
+ module Builder
3
+ class Tex < Base
4
+ class << self
5
+ def build(output_format = 'dvi')
6
+ @output_format = output_format
7
+
8
+ clean_build_dir
9
+
10
+ base_latex_file = Rubbr.options[:base_latex_file]
11
+ base_bibtex_file = Rubbr.options[:base_bibtex_file]
12
+
13
+ if output_format == 'pdf'
14
+ preprocessor = Rubbr::Runner::PdfLaTeX
15
+ else
16
+ preprocessor = Rubbr::Runner::LaTeX
17
+ end
18
+
19
+ build_dir do
20
+ copy_source_files
21
+ copy_vendor_files
22
+
23
+ latex = preprocessor.new(base_latex_file, true)
24
+ if base_bibtex_file && latex.warnings.join =~ /No file .+\.bbl/
25
+ bibtex = Rubbr::Runner::BibTeX.new(base_bibtex_file, true)
26
+ end
27
+ if latex.warnings.join =~ /No file .+\.(aux|toc)/
28
+ latex = preprocessor.new(base_latex_file, true)
29
+ end
30
+ if latex.warnings.join =~ /There were undefined citations/
31
+ latex = preprocessor.new(base_latex_file, true)
32
+ end
33
+ latex.silent = false
34
+ latex.feedback
35
+ if bibtex
36
+ bibtex.silent = false
37
+ bibtex.feedback
38
+ end
39
+ end
40
+ distribute_file(base_latex_file)
41
+ notice "Build of #@output_format completed for: #{base_latex_file} " +
42
+ "in #{Rubbr.options[:build_dir]}"
43
+ end
44
+
45
+ private
46
+
47
+ def clean_build_dir
48
+ if File.exists? Rubbr.options[:build_dir]
49
+ FileUtils.rm_r Rubbr.options[:build_dir]
50
+ end
51
+ end
52
+
53
+ def copy_source_files
54
+ copy_files(Rubbr.options[:source_dir], %w(tex bib cls))
55
+ end
56
+
57
+ def copy_vendor_files
58
+ copy_files(Rubbr.options[:vendor_dir], %w(sty clo cls cfg))
59
+ end
60
+
61
+ def copy_files(source_dir, file_extensions)
62
+ file_extensions.each do |file_extension|
63
+ Dir["#{source_dir}/*.#{file_extension}"].each do |file|
64
+ FileUtils.cp(file, Rubbr.options[:build_dir])
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
data/lib/rubbr/cli.rb ADDED
@@ -0,0 +1,38 @@
1
+ module Rubbr
2
+
3
+ # Handles command line output and input.
4
+ module Cli
5
+ def notice(message)
6
+ puts message
7
+ end
8
+
9
+ def warning(message)
10
+ puts " - #{message}"
11
+ end
12
+
13
+ def error(message)
14
+ puts " * #{message}"
15
+ end
16
+
17
+ def disable_stdout
18
+ old_stdout = STDOUT.dup
19
+ STDOUT.reopen('/dev/null')
20
+ yield
21
+ STDOUT.reopen(old_stdout)
22
+ end
23
+
24
+ def disable_stderr
25
+ old_stderr = STDERR.dup
26
+ STDERR.reopen('/dev/null')
27
+ yield
28
+ STDERR.reopen(old_stderr)
29
+ end
30
+
31
+ def disable_stdinn
32
+ old_stdinn = STDIN.dup
33
+ STDIN.reopen('/dev/null')
34
+ yield
35
+ STDIN.reopen(old_stdinn)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,76 @@
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
+ :template_file => 'template.erb',
15
+ :base_file => 'base',
16
+ :vendor_dir => source_dir + '/vendor',
17
+ :graphics_dir => source_dir + '/graphics',
18
+ :spell_dir => source_dir,
19
+ :spell_file => 'dictionary.ispell',
20
+ :distribution_name => distribution_name(root_dir)
21
+ }
22
+ end
23
+
24
+ # Fetching options from a config file if present and merges it
25
+ # with the defaults.
26
+ def setup
27
+ preference_file = "#{defaults[:root_dir]}/config.yml"
28
+ preferences = {}
29
+ if File.exists? preference_file
30
+ require 'yaml'
31
+ File.open(preference_file) { |file| preferences = YAML.load(file) }
32
+ end
33
+ base_file_variations(absolute_paths(defaults.merge(preferences)))
34
+ end
35
+
36
+ private
37
+
38
+ def distribution_name(root)
39
+ name = File.basename(root)
40
+ name << ".#{user_name}"
41
+ if stats = Rubbr::Scm.stats(root)
42
+ name << ".r#{stats[:revision].gsub(':', '_')}"
43
+ end
44
+ name
45
+ end
46
+
47
+ def user_name
48
+ `whoami`.strip
49
+ end
50
+
51
+ def absolute_paths(options)
52
+ relatives = %w(source_dir
53
+ build_dir
54
+ distribution_dir
55
+ template_file
56
+ vendor_dir
57
+ graphics_dir
58
+ spell_dir)
59
+ relatives.each do |key|
60
+ options[key.to_sym] = File.join(options[:root_dir],
61
+ options[key.to_sym])
62
+ end
63
+ options
64
+ end
65
+
66
+ def base_file_variations(options)
67
+ options[:base_latex_file] = options[:base_file] + '.tex'
68
+ options[:base_bibtex_file] = options[:base_file] + '.aux'
69
+ options[:base_dvi_file] = options[:base_file] + '.dvi'
70
+ options[:base_ps_file] = options[:base_file] + '.ps'
71
+ options[:base_pdf_file] = options[:base_file] + '.pdf'
72
+ options
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,67 @@
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
+ # If true no messages is sendt to standard out. Defaults to false.
14
+ attr_accessor :silent
15
+
16
+ # The executable to be run.
17
+ attr_accessor :executable
18
+
19
+ # Contains a list of possible warnings after a run.
20
+ attr_accessor :warnings
21
+
22
+ # Contains a list of possible errors after a run.
23
+ attr_accessor :errors
24
+
25
+ def initialize(input_file, silent, executable)
26
+ @input_file = input_file
27
+ disable_stdout do
28
+ disable_stderr do
29
+ @executable = executable if system "which #{executable}"
30
+ end
31
+ end
32
+ @silent = silent
33
+ @errors = []
34
+
35
+ if File.exists? @input_file
36
+ run
37
+ else
38
+ error "Running of #@executable aborted. " +
39
+ "Input file: #@input_file not found"
40
+ end
41
+ end
42
+
43
+ def run
44
+ end
45
+
46
+ def feedback
47
+ return if @silent
48
+ unless @warnings.empty?
49
+ notice "Warnings from #@executable:"
50
+ @warnings.each do |message|
51
+ warning message
52
+ end
53
+ end
54
+ unless @errors.empty?
55
+ notice "Errors from #@executable:"
56
+ @errors.each do |message|
57
+ error message
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ %w(latex bibtex dvips ps2pdf pdflatex).each do
64
+ |f| require File.dirname(__FILE__) + "/runner/#{f}"
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,15 @@
1
+ module Rubbr
2
+ module Runner
3
+ class BibTeX < Base
4
+ def initialize(input_file, silent=false, 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, silent=false, 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,24 @@
1
+ module Rubbr
2
+ module Runner
3
+ class LaTeX < Base
4
+ def initialize(input_file, silent=false, executable='latex')
5
+ super
6
+ end
7
+
8
+ def run
9
+ disable_stdinn do
10
+ messages = /^(Overfull|Underfull|No file|Package \w+ Warning:)/
11
+ run = `#@executable #@input_file`
12
+ @warnings = run.grep(messages)
13
+ lines = run.split("\n")
14
+ while lines.shift
15
+ if lines.first =~ /^!/
16
+ 3.times { @errors << lines.shift }
17
+ end
18
+ end
19
+ feedback
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Rubbr
2
+ module Runner
3
+ class PdfLaTeX < Base
4
+ def initialize(input_file, silent=false, executable='pdflatex')
5
+ super
6
+ end
7
+
8
+ def run
9
+ disable_stdinn do
10
+ messages = /^(Overfull|Underfull|No file|Package \w+ Warning:)/
11
+ run = `#@executable #@input_file`
12
+ @warnings = run.grep(messages)
13
+ lines = run.split("\n")
14
+ while lines.shift
15
+ if lines.first =~ /^!/
16
+ 3.times { @errors << lines.shift }
17
+ end
18
+ end
19
+ feedback
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module Rubbr
2
+ module Runner
3
+ class Ps2Pdf < Base
4
+ def initialize(input_file, silent=false, 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
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,35 @@
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
+ disable_stdout do
14
+ disable_stderr do
15
+ @executable = 'hg' if system 'which hg'
16
+ end
17
+ end
18
+
19
+ @revision, @date = parse_scm_stats
20
+
21
+ yield self if block_given?
22
+ end
23
+
24
+ def parse_scm_stats
25
+ return [nil, nil] unless @executable
26
+
27
+ raw_stats = `hg tip`
28
+ revision = raw_stats.scan(/^changeset: +(.+)/).first.first
29
+ date = raw_stats.scan(/^date: +(.+)/).first.first
30
+
31
+ [revision, date]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
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
+ disable_stdout do
14
+ disable_stderr do
15
+ @executable = 'svn' if system 'which svn'
16
+ end
17
+ end
18
+
19
+ @revision, @date = parse_scm_stats
20
+
21
+ yield self if block_given?
22
+ end
23
+
24
+ def parse_scm_stats
25
+ return [nil, nil] unless @executable
26
+
27
+ raw_stats = `svn info`
28
+ revision = raw_stats.scan(/^Revision: (\d+)/).first.first
29
+ date = raw_stats.scan(/^Last Changed Date: (.+)/).first.first
30
+
31
+ [revision, date]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ module Rubbr
2
+ class Spell
3
+ def self.check
4
+ source_files = Dir["#{Rubbr.options[:source_dir]}/*.tex"]
5
+ source_files.delete(File.join(Rubbr.options[:source_dir],
6
+ Rubbr.options[:base_latex_file]))
7
+
8
+ dictionary_path = File.join(Rubbr.options[:spell_dir],
9
+ Rubbr.options[:spell_file])
10
+ source_files.each do |file|
11
+ system "ispell -t -x -p #{dictionary_path} #{file}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,56 @@
1
+ module Rubbr
2
+ module Viewer
3
+
4
+ # View the spesified format.
5
+ def self.view(format)
6
+ case format
7
+ when :dvi
8
+ Rubbr::Viewer::Dvi.new.launch
9
+ when :ps
10
+ Rubbr::Viewer::Ps.new.launch
11
+ else
12
+ Rubbr::Viewer::Pdf.new.launch
13
+ end
14
+ end
15
+
16
+ class Base
17
+ include Rubbr::Cli
18
+
19
+ # The name prefix of the distribution file.
20
+ attr_accessor :distribution_name
21
+
22
+ def distribution_file
23
+ File.join(Rubbr.options[:distribution_dir],
24
+ "#@distribution_name.#@view_name")
25
+ end
26
+
27
+ def initialize
28
+ @distribution_name = Rubbr.options[:distribution_name]
29
+
30
+ @view_name = 'base'
31
+ @executables = []
32
+ end
33
+
34
+ def find_viewer
35
+ @executables.each do |executable|
36
+ disable_stdout do
37
+ disable_stderr do
38
+ return executable if system "which #{executable}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ def launch
45
+ return unless viewer = find_viewer
46
+ system "#{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
@@ -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
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubbr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eivind Uggedal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-02-04 00:00:00 +01:00
13
+ default_executable:
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.5.0
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/cli.rb
43
+ - lib/rubbr/options.rb
44
+ - lib/rubbr/runner.rb
45
+ - lib/rubbr/scm.rb
46
+ - lib/rubbr/spell.rb
47
+ - lib/rubbr/viewer.rb
48
+ - lib/rubbr/builder/tex.rb
49
+ - lib/rubbr/builder/ps.rb
50
+ - lib/rubbr/builder/dvi.rb
51
+ - lib/rubbr/runner/ps2pdf.rb
52
+ - lib/rubbr/runner/pdflatex.rb
53
+ - lib/rubbr/runner/latex.rb
54
+ - lib/rubbr/runner/dvips.rb
55
+ - lib/rubbr/runner/bibtex.rb
56
+ - lib/rubbr/scm/subversion.rb
57
+ - lib/rubbr/scm/mercurial.rb
58
+ - lib/rubbr/viewer/ps.rb
59
+ - lib/rubbr/viewer/pdf.rb
60
+ - lib/rubbr/viewer/dvi.rb
61
+ has_rdoc: true
62
+ homepage: Build LaTeX documents.
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --main
66
+ - README.txt
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: rubbr
84
+ rubygems_version: 1.0.1
85
+ signing_key:
86
+ specification_version: 2
87
+ summary: LaTeX builder
88
+ test_files: []
89
+