texas 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/bin/texas +1 -1
- data/lib/texas.rb +13 -2
- data/lib/texas/build.rb +32 -0
- data/lib/texas/build/base.rb +47 -24
- data/lib/texas/build/config.rb +118 -0
- data/lib/texas/build/config_loader.rb +93 -0
- data/lib/texas/build/dry.rb +1 -1
- data/lib/texas/build/final.rb +2 -2
- data/lib/texas/build/task/add_default_templates_to_build_path.rb +4 -0
- data/lib/texas/build/task/base.rb +2 -0
- data/lib/texas/build/task/copy_contents_to_build_path.rb +3 -0
- data/lib/texas/build/task/execute_after_scripts.rb +18 -0
- data/lib/texas/build/task/execute_before_scripts.rb +18 -0
- data/lib/texas/build/task/open_pdf.rb +7 -21
- data/lib/texas/build/task/publish_pdf.rb +35 -27
- data/lib/texas/build/task/run_master_template.rb +2 -0
- data/lib/texas/build/task/script.rb +28 -0
- data/lib/texas/core_ext.rb +2 -1
- data/lib/texas/core_ext/hash.rb +34 -0
- data/lib/texas/core_ext/string.rb +1 -128
- data/lib/texas/option_parser.rb +153 -124
- data/lib/texas/output_helper.rb +58 -0
- data/lib/texas/runner.rb +32 -51
- data/lib/texas/task/base.rb +1 -0
- data/lib/texas/task/new_project.rb +1 -1
- data/lib/texas/task/watch.rb +29 -18
- data/lib/texas/template.rb +6 -2
- data/lib/texas/template/helper/base.rb +60 -9
- data/lib/texas/template/helper/tex.rb +2 -4
- data/lib/texas/template/runner.rb +2 -5
- data/lib/texas/template/runner/base.rb +59 -11
- data/lib/texas/template/runner/md.rb +2 -2
- data/lib/texas/template/runner/tex.rb +2 -2
- data/lib/texas/template/template_error.rb +19 -5
- data/lib/texas/version.rb +1 -1
- data/spec/fixtures/basic-tex/contents/{unused_template.tex.erb → sub_dir/unused_template.tex.erb} +0 -0
- data/spec/fixtures/new-project/lib/init.rb +1 -1
- data/spec/fixtures/pdflatex-error/contents/contents.tex.erb +1 -0
- data/spec/spec_helper.rb +16 -7
- data/spec/texas/build/base_spec.rb +53 -9
- data/spec/texas/build/config_spec.rb +73 -0
- data/spec/texas/build/task/base_spec.rb +21 -0
- data/spec/texas/option_parser_spec.rb +53 -0
- data/spec/texas/task/base_spec.rb +49 -0
- data/spec/texas_spec.rb +49 -3
- metadata +76 -73
- data/lib/texas/build/task/run_before_scripts.rb +0 -22
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper/md'
|
2
2
|
|
3
3
|
class Texas::Template::Runner::Markdown < Texas::Template::Runner::Base
|
4
4
|
include Texas::Template::Helper::Markdown
|
5
5
|
|
6
6
|
def after_write
|
7
7
|
if `which pandoc`.empty?
|
8
|
-
|
8
|
+
trace "\nAborting build: pandoc not found in PATH (required for Markdown rendering)"
|
9
9
|
exit
|
10
10
|
end
|
11
11
|
tex_filename = Texas::Template.basename(@output_filename) + ".tex"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../helper/tex'
|
2
2
|
|
3
3
|
class Texas::Template::Runner::TeX < Texas::Template::Runner::Base
|
4
4
|
include Texas::Template::Helper::TeX
|
@@ -8,4 +8,4 @@ class Texas::Template::Runner::TeX < Texas::Template::Runner::Base
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
Texas::Template.register_handler %w(tex tex
|
11
|
+
Texas::Template.register_handler %w(tex.erb tex), Texas::Template::Runner::TeX
|
@@ -5,6 +5,11 @@ class TemplateError < StandardError
|
|
5
5
|
super(message)
|
6
6
|
self.template = template
|
7
7
|
self.original = original
|
8
|
+
parse_backtrace_for_origin
|
9
|
+
end
|
10
|
+
|
11
|
+
def __backtrace__
|
12
|
+
original ? original.backtrace : backtrace
|
8
13
|
end
|
9
14
|
|
10
15
|
def filename
|
@@ -12,11 +17,12 @@ class TemplateError < StandardError
|
|
12
17
|
end
|
13
18
|
|
14
19
|
def parse_backtrace_for_origin
|
15
|
-
arr =
|
20
|
+
arr = __backtrace__ || []
|
16
21
|
arr.each_with_index do |line, index|
|
17
22
|
if line =~ /\(erb\):(\d+)/
|
23
|
+
@pre_erb_backtrace = arr[0...index]
|
18
24
|
@line_number = $1.to_i
|
19
|
-
line_before =
|
25
|
+
line_before = arr[index-1]
|
20
26
|
@method_name = line_before =~ /\d+:in\s+`([^\)]+)'/ && $1
|
21
27
|
return
|
22
28
|
end
|
@@ -24,11 +30,19 @@ class TemplateError < StandardError
|
|
24
30
|
end
|
25
31
|
|
26
32
|
def origin
|
27
|
-
|
28
|
-
|
33
|
+
"#{filename}:#{@line_number}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def pre_erb_backtrace
|
37
|
+
if @pre_erb_backtrace
|
38
|
+
arr = @pre_erb_backtrace.map do |line|
|
39
|
+
line.gsub(template.build.root, '.')
|
40
|
+
end
|
41
|
+
str = arr.empty? ? "" : arr.join("\n").dark + "\n"
|
42
|
+
end
|
29
43
|
end
|
30
44
|
|
31
45
|
def message
|
32
|
-
super + "\n#{origin}"
|
46
|
+
super + "\n#{pre_erb_backtrace}#{origin.cyan}"
|
33
47
|
end
|
34
48
|
end
|
data/lib/texas/version.rb
CHANGED
data/spec/fixtures/basic-tex/contents/{unused_template.tex.erb → sub_dir/unused_template.tex.erb}
RENAMED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
\aaaaaa
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,13 @@ require 'rspec'
|
|
6
6
|
require 'fileutils'
|
7
7
|
|
8
8
|
require 'texas'
|
9
|
+
module Texas
|
10
|
+
module OutputHelper
|
11
|
+
def trace(*args)
|
12
|
+
# void
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
9
16
|
|
10
17
|
def default_options
|
11
18
|
{:open_pdf => false, :warnings => false}
|
@@ -23,7 +30,7 @@ def original_test_data_dir(scenario)
|
|
23
30
|
File.join(File.dirname(__FILE__), 'fixtures', scenario.to_s)
|
24
31
|
end
|
25
32
|
|
26
|
-
def test_data_dir(scenario)
|
33
|
+
def test_data_dir(scenario = "")
|
27
34
|
File.join(tmp_dir, scenario.to_s)
|
28
35
|
end
|
29
36
|
|
@@ -38,7 +45,7 @@ def use_scenario(scenario)
|
|
38
45
|
end
|
39
46
|
|
40
47
|
def run_scenario(scenario, options = {}, &block)
|
41
|
-
options = default_options.merge(options)
|
48
|
+
options = default_options.merge(options) if options.is_a?(Hash)
|
42
49
|
work_dir = use_scenario(scenario)
|
43
50
|
runner = Texas::Runner.new(options)
|
44
51
|
if block_given?
|
@@ -52,13 +59,15 @@ def match_should_templates(work_dir)
|
|
52
59
|
should_templates = Dir[File.join(work_dir, "tmp", "build", "**/*.tex.should")]
|
53
60
|
should_templates.each do |should_file|
|
54
61
|
generated_file = should_file.gsub(/\.should$/, '')
|
55
|
-
File.
|
62
|
+
if File.exist?(generated_file)
|
63
|
+
File.read(generated_file).should == File.read(should_file)
|
64
|
+
end
|
56
65
|
end
|
57
66
|
end
|
58
67
|
|
59
68
|
RSpec.configure do |config|
|
60
|
-
config.before(:each)
|
61
|
-
|
62
|
-
|
63
|
-
|
69
|
+
config.before(:each) do
|
70
|
+
FileUtils.mkdir_p test_data_dir
|
71
|
+
Dir.chdir test_data_dir
|
72
|
+
end
|
64
73
|
end
|
@@ -2,6 +2,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
2
2
|
|
3
3
|
describe Texas::Build::Base do
|
4
4
|
|
5
|
+
def fake_options
|
6
|
+
options = OpenStruct.new({
|
7
|
+
:work_dir => "/tmp/test_project",
|
8
|
+
:contents_dir => "contents",
|
9
|
+
:contents_template => "contents"
|
10
|
+
})
|
11
|
+
end
|
12
|
+
|
13
|
+
def fake_build
|
14
|
+
Texas::Build::Base.new(fake_options)
|
15
|
+
end
|
16
|
+
|
5
17
|
def test_build
|
6
18
|
@test_build ||= get_runner_instance
|
7
19
|
end
|
@@ -12,15 +24,6 @@ describe Texas::Build::Base do
|
|
12
24
|
end
|
13
25
|
end
|
14
26
|
|
15
|
-
describe "#ran_templates" do
|
16
|
-
it "returns the templates" do
|
17
|
-
filenames = test_build.ran_templates.map(&:filename)
|
18
|
-
basenames = filenames.map { |f| f.gsub(test_build.__path__+'/', '') }
|
19
|
-
basenames.size.should > 0
|
20
|
-
basenames.include?("unused_template.tex.erb").should == false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
27
|
class FoobarTask
|
25
28
|
class << self
|
26
29
|
attr_accessor :foo
|
@@ -41,5 +44,46 @@ describe Texas::Build::Base do
|
|
41
44
|
FoobarTask.foo.should == :bar
|
42
45
|
end
|
43
46
|
end
|
47
|
+
|
48
|
+
describe "#ran_templates" do
|
49
|
+
it "returns the templates" do
|
50
|
+
filenames = test_build.ran_templates.map(&:filename)
|
51
|
+
basenames = filenames.map { |f| f.gsub(test_build.__path__+'/', '') }
|
52
|
+
basenames.size.should > 0
|
53
|
+
basenames.include?("sub_dir/unused_template.tex.erb").should == false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#__path__" do
|
58
|
+
it "should return the build path" do
|
59
|
+
build = fake_build
|
60
|
+
build.__path__.should == "#{fake_options.work_dir}/tmp/build"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#store" do
|
65
|
+
it "should return an object that can store values" do
|
66
|
+
build = fake_build
|
67
|
+
store = build.store
|
68
|
+
store.test_value.should be_nil
|
69
|
+
store.test_value = 42
|
70
|
+
store.test_value.should == 42
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#config" do
|
75
|
+
it "should return an object that can be accessed by []" do
|
76
|
+
build = fake_build
|
77
|
+
config = build.config
|
78
|
+
config[:test_value].should be_nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#dest_file" do
|
83
|
+
it "should return the PDF's filename" do
|
84
|
+
build = fake_build
|
85
|
+
build.dest_file.should == "#{fake_options.work_dir}/bin/#{fake_options.contents_template}.pdf"
|
86
|
+
end
|
87
|
+
end
|
44
88
|
|
45
89
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Texas::Build::Config do
|
4
|
+
|
5
|
+
def texasrc_filename
|
6
|
+
File.join(original_test_data_dir(:texasrc), ".texasrc")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#new" do
|
10
|
+
it "takes a hash and makes it accessible via methods" do
|
11
|
+
config = Texas::Build::Config.new({:foo => :bar})
|
12
|
+
config.foo.should == :bar
|
13
|
+
lambda { config.some_value }.should raise_error(NoMethodError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#[]" do
|
18
|
+
it "takes a string" do
|
19
|
+
config = Texas::Build::Config.new({:foo => :bar})
|
20
|
+
config["foo"].should == :bar
|
21
|
+
end
|
22
|
+
|
23
|
+
it "takes a symbol" do
|
24
|
+
config = Texas::Build::Config.new({:foo => :bar})
|
25
|
+
config[:foo].should == :bar
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#document" do
|
30
|
+
it "takes a hash" do
|
31
|
+
config = Texas::Build::Config.new({:document => {:foo => :bar}})
|
32
|
+
config.document.should_not be_nil
|
33
|
+
config.document.foo.should == :bar
|
34
|
+
end
|
35
|
+
it "does not raise errors for none existing keys" do
|
36
|
+
config = Texas::Build::Config.new({:document => {:foo => :bar}})
|
37
|
+
config.document.some_other_value.should be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#merge!" do
|
42
|
+
it "deep_merges a key into the config" do
|
43
|
+
hash = {
|
44
|
+
:document => {:foo => :bar, :some_other_value => true},
|
45
|
+
:other_mode => {:document => {:foo => 42}}
|
46
|
+
}
|
47
|
+
config = Texas::Build::Config.new(hash)
|
48
|
+
config.document.should_not be_nil
|
49
|
+
config.document.foo.should == :bar
|
50
|
+
config.document.some_other_value.should be_true
|
51
|
+
config.merge! "other_mode"
|
52
|
+
config.document.foo.should == 42
|
53
|
+
config.document.some_other_value.should be_true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#create" do
|
58
|
+
it "takes a filename" do
|
59
|
+
config = Texas::Build::Config.create({:document => {:some_value => 42}})
|
60
|
+
config.document.should_not be_nil
|
61
|
+
config.document.some_value.should == 42
|
62
|
+
config.document.some_other_value.should be_nil
|
63
|
+
end
|
64
|
+
|
65
|
+
it "takes a filename and a merge key" do
|
66
|
+
config = Texas::Build::Config.create({:document => {:some_value => 42}, :other_mode => {:document => {:some_value => 24, :some_other_value => 42}}}, "other_mode")
|
67
|
+
config.document.should_not be_nil
|
68
|
+
config.document.some_value.should == 24
|
69
|
+
config.document.some_other_value.should be_true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe Texas::Build::Task::Base do
|
4
|
+
|
5
|
+
describe "#new" do
|
6
|
+
it "should not require a build" do
|
7
|
+
Texas::Build::Task::Base.new()
|
8
|
+
end
|
9
|
+
it "should take a build" do
|
10
|
+
build = Object.new
|
11
|
+
Texas::Build::Task::Base.new(build)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#run" do
|
16
|
+
it "should not raise errors" do
|
17
|
+
Texas::Build::Task::Base.new.run
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Texas::OptionParser do
|
4
|
+
describe "#initialize" do
|
5
|
+
it "takes an array" do
|
6
|
+
op = Texas::OptionParser.new(%w(-d))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#parse" do
|
11
|
+
it "should abort if check_mandatory fails" do
|
12
|
+
op = Texas::OptionParser.new(%w(-d))
|
13
|
+
lambda { op.parse }.should raise_error SystemExit
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should identify the right contents_dir and contents_template options" do
|
17
|
+
use_scenario "basic-tex"
|
18
|
+
|
19
|
+
options = Texas::OptionParser.new(%w()).parse
|
20
|
+
options.contents_dir.should == "contents"
|
21
|
+
options.contents_template.should == "contents"
|
22
|
+
|
23
|
+
options = Texas::OptionParser.new(%w(contents/input_template)).parse
|
24
|
+
options.contents_dir.should == "contents"
|
25
|
+
options.contents_template.should == "input_template"
|
26
|
+
|
27
|
+
options = Texas::OptionParser.new(%w(contents/sub_dir/unused_template)).parse
|
28
|
+
options.contents_dir.should == "contents"
|
29
|
+
options.contents_template.should == "sub_dir/unused_template"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".parse_additional_options" do
|
34
|
+
it "should take a block" do
|
35
|
+
Texas::OptionParser.parse_additional_options do |parser, options|
|
36
|
+
options.check_mandatory_arguments = false
|
37
|
+
options.foo = true
|
38
|
+
parser.on("--[no-]foo", "Switch foo") do |v|
|
39
|
+
options.foo = v
|
40
|
+
end
|
41
|
+
end
|
42
|
+
op = Texas::OptionParser.new(%w())
|
43
|
+
options = op.parse
|
44
|
+
options.foo.should be_true
|
45
|
+
op = Texas::OptionParser.new(%w(--foo))
|
46
|
+
options = op.parse
|
47
|
+
options.foo.should be_true
|
48
|
+
op = Texas::OptionParser.new(%w(--no-foo))
|
49
|
+
options = op.parse
|
50
|
+
options.foo.should be_false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Texas::Task::Base do
|
4
|
+
|
5
|
+
describe "#new" do
|
6
|
+
it "should not require a build" do
|
7
|
+
options = OpenStruct.new
|
8
|
+
Texas::Task::Base.new(options)
|
9
|
+
end
|
10
|
+
it "should take options and a build" do
|
11
|
+
options = OpenStruct.new
|
12
|
+
build = MockBuild.new
|
13
|
+
Texas::Task::Base.new(options, build)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class MockBuild
|
18
|
+
attr_accessor :foo
|
19
|
+
|
20
|
+
def initialize(*args); end
|
21
|
+
|
22
|
+
def run
|
23
|
+
@foo = :bar
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#run" do
|
28
|
+
it "should not raise errors" do
|
29
|
+
options = OpenStruct.new
|
30
|
+
build = MockBuild.new
|
31
|
+
Texas::Task::Base.new(options, build).run
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#build" do
|
36
|
+
it "should not raise errors" do
|
37
|
+
options = OpenStruct.new
|
38
|
+
build = MockBuild.new
|
39
|
+
task = Texas::Task::Base.new(options, build)
|
40
|
+
task.build.should == build
|
41
|
+
end
|
42
|
+
it "should lazy init the build object" do
|
43
|
+
options = OpenStruct.new
|
44
|
+
task = Texas::Task::Base.new(options)
|
45
|
+
task.build(MockBuild).should_not be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/spec/texas_spec.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
+
def pandoc_present?
|
4
|
+
where = `which pandoc`
|
5
|
+
!where.empty?
|
6
|
+
end
|
7
|
+
|
3
8
|
describe Texas::Runner do
|
4
9
|
describe "#initialize" do
|
5
10
|
|
@@ -7,7 +12,19 @@ describe Texas::Runner do
|
|
7
12
|
run_scenario "basic-tex"
|
8
13
|
end
|
9
14
|
|
10
|
-
it "run basic
|
15
|
+
it "run basic tex scenario with some arguments" do
|
16
|
+
run_scenario "basic-tex", %w(-d -v)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "run basic tex scenario with another contents_template" do
|
20
|
+
run_scenario "basic-tex", %w(-d contents/input_template)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "run basic tex scenario with another subdir contents_template" do
|
24
|
+
run_scenario "basic-tex", %w(-d contents/sub_dir/unused_template)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "run basic markdown scenario", :if => pandoc_present? do
|
11
28
|
run_scenario "basic-md"
|
12
29
|
end
|
13
30
|
|
@@ -15,12 +32,41 @@ describe Texas::Runner do
|
|
15
32
|
run_scenario "different-master-tex"
|
16
33
|
end
|
17
34
|
|
18
|
-
it "run scenario for TeX helper methods" do
|
35
|
+
it "run scenario for TeX helper methods", :if => pandoc_present? do
|
19
36
|
run_scenario "helper-methods-tex"
|
20
37
|
end
|
21
38
|
|
22
39
|
it "run scenario for .texasrc" do
|
23
|
-
run_scenario "texasrc"
|
40
|
+
run_scenario "texasrc" do |runner|
|
41
|
+
build = runner.task_instance
|
42
|
+
config = build.config
|
43
|
+
lambda {
|
44
|
+
config.some_other_value_from_parent_dir_config.should be_true
|
45
|
+
}.should raise_error
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "run scenario for .texasrc with a parent .texasrc" do
|
50
|
+
other_config_file = File.join(test_data_dir(""), ".texasrc")
|
51
|
+
FileUtils.cp File.join(test_data_dir("texasrc"), ".other.texasrc"), other_config_file
|
52
|
+
run_scenario "texasrc" do |runner|
|
53
|
+
FileUtils.rm other_config_file # remove parent .texasrc
|
54
|
+
build = runner.task_instance
|
55
|
+
config = build.config
|
56
|
+
config.document.some_other_value_from_parent_dir_config.should be_true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "run scenario for .texasrc with --merge-config and fail" do
|
61
|
+
lambda {
|
62
|
+
run_scenario "texasrc", :merge_config => "other_mode"
|
63
|
+
}.should raise_error
|
64
|
+
end
|
65
|
+
|
66
|
+
it "run scenario for pdflatex-error and fail" do
|
67
|
+
lambda {
|
68
|
+
run_scenario "pdflatex-error"
|
69
|
+
}.should raise_error
|
24
70
|
end
|
25
71
|
|
26
72
|
it "run scenario for lib/ helpers" do
|