texas 0.1.5 → 0.1.6

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.
@@ -21,7 +21,7 @@ module Texas
21
21
  verbose { "[i] work_dir: #{options.work_dir}".dark }
22
22
  verbose { "[i] contents_dir: #{@contents_dir}".dark }
23
23
  verbose { "[i] contents_template: #{@contents_template}".dark }
24
- verbose { "[i] build_path: #{@build_path}".dark }
24
+ verbose { "[i] build_path: #{__path__}".dark }
25
25
  end
26
26
 
27
27
  def __path__
@@ -65,6 +65,7 @@ module Texas
65
65
 
66
66
  def run_build_task(klass)
67
67
  klass = eval("::Texas::Build::Task::#{klass}") if [Symbol, String].include?(klass.class)
68
+ verbose { "[b] #{klass}".dark }
68
69
  klass.new(self).run
69
70
  end
70
71
 
@@ -81,12 +82,6 @@ module Texas
81
82
  end
82
83
 
83
84
  class << self
84
- def run(options)
85
- instance = self.new(options)
86
- instance.run
87
- instance
88
- end
89
-
90
85
  def tasks(key)
91
86
  @@tasks ||= {}
92
87
  initialize_tasks if @@tasks[self.to_s].nil?
@@ -17,7 +17,7 @@ module Texas
17
17
  if open_pdf_cmd
18
18
  system "#{open_pdf_cmd} #{build.dest_file}"
19
19
  else
20
- puts "Can't open PDF: no default command recognized. Specify in #{CONFIG_FILE}"
20
+ puts "Can't open PDF: no default command recognized. Specify in #{Build::Base::CONFIG_FILE}"
21
21
  end
22
22
  end
23
23
 
@@ -27,17 +27,25 @@ module Texas
27
27
  verbose {
28
28
  file = File.join(build_path, "master.log")
29
29
  output = `grep "Output written on" #{file}`
30
- numbers = output.scan(/\((\d+?) pages\, (\d+?) bytes\)\./).flatten
30
+ numbers = output.scan(/\((\d+?) pages?\, (\d+?) bytes\)\./).flatten
31
31
  @page_count = numbers.first.to_i
32
- "Written PDF in #{dest_file.gsub(root, '')} (#{@page_count} pages)".green
32
+ "Written PDF in #{dest_file.gsub(build.root, '')} (#{@page_count} pages)".green
33
33
  }
34
34
  end
35
35
 
36
36
  def run_pdflatex
37
37
  verbose { "Running pdflatex in #{build_path} ..." }
38
- Dir.chdir build_path
39
- `pdflatex #{File.basename(master_file)}`
40
- `pdflatex #{File.basename(master_file)}`
38
+ run_in build_path do
39
+ `pdflatex #{File.basename(master_file)}`
40
+ `pdflatex #{File.basename(master_file)}`
41
+ end
42
+ end
43
+
44
+ def run_in(path)
45
+ old_path = Dir.pwd
46
+ Dir.chdir path
47
+ yield
48
+ Dir.chdir old_path
41
49
  end
42
50
 
43
51
  end
@@ -12,7 +12,6 @@ module Texas
12
12
  @options = OpenStruct.new
13
13
  end
14
14
 
15
- #
16
15
  # Return a structure describing the options.
17
16
  #
18
17
  def parse
@@ -34,7 +33,7 @@ module Texas
34
33
  lookup_and_execute_require_option(args)
35
34
 
36
35
  opts = ::OptionParser.new do |opts|
37
- opts.banner = "Usage: texas [options]"
36
+ opts.banner = "Usage: texas [CONTENTS_TEMPLATE] [options]"
38
37
 
39
38
  opts.separator ""
40
39
  opts.separator "Specific options:"
@@ -117,11 +116,17 @@ module Texas
117
116
 
118
117
  private
119
118
 
120
- # This method can be overwritten by other libraries
121
- # to parse additional options
119
+ # Is empty. It can be overwritten by other libraries to
120
+ # parse and display additional options.
121
+ #
122
122
  def parse_additional_options(opts)
123
123
  end
124
124
 
125
+ # Parses the given arguments for the --require option and requires
126
+ # it if present. This is done separately from the regular option parsing
127
+ # to enable the required library to modify Texas,
128
+ # e.g. overwrite OptionParser#parse_additional_options.
129
+ #
125
130
  def lookup_and_execute_require_option(args)
126
131
  args.each_with_index do |v, i|
127
132
  if %w(-r --require).include?(v)
data/lib/texas/runner.rb CHANGED
@@ -41,6 +41,7 @@ module Texas
41
41
  end
42
42
 
43
43
  # Display the error message that caused the exception.
44
+ #
44
45
  def display_error_message(ex)
45
46
  puts "#{@options.task} aborted!"
46
47
  puts ex.message
@@ -51,11 +52,15 @@ module Texas
51
52
  end
52
53
  end
53
54
 
55
+ # Extends String with Term::ANSIColor if options demand it.
56
+ #
54
57
  def extend_string_class
55
58
  mod = @options.colors ? Term::ANSIColor : Term::NoColor
56
59
  String.send :include, mod
57
60
  end
58
61
 
62
+ # Load lib/init.rb if present in current project.
63
+ #
59
64
  def load_local_libs
60
65
  init_file = File.join(@options.work_dir, "lib", "init.rb")
61
66
  require init_file if File.exist?(init_file)
@@ -68,6 +73,8 @@ module Texas
68
73
  exit 1
69
74
  end
70
75
 
76
+ # Returns the class for the given task.
77
+ #
71
78
  def task_class
72
79
  map = {
73
80
  :build => Build::Final,
@@ -9,7 +9,7 @@ module Texas
9
9
  end
10
10
 
11
11
  def build(klass = Build::Dry)
12
- @build ||= klass.run(options)
12
+ @build ||= klass.new(options).run
13
13
  end
14
14
 
15
15
  def run
@@ -17,16 +17,16 @@ module Texas
17
17
 
18
18
  def self.directories_to_watch
19
19
  arr = []
20
- arr << "tex"
21
- arr << "figures"
20
+ arr << "tex" if Dir.exists?("tex")
21
+ arr << "contents" if Dir.exists?("contents")
22
+ arr << "figures" if Dir.exists?("figures")
22
23
  arr << Texas.texas_dir
23
24
  arr
24
25
  end
25
26
 
26
27
  def self.rebuild
27
28
  started_at = Time.now.to_i
28
- @build = Build::Final.new(run_options)
29
- @build.run
29
+ Build::Final.new(run_options).run
30
30
  finished_at = Time.now.to_i
31
31
  puts (finished_at - started_at).to_s + " seconds to rebuild"
32
32
  rescue Exception => e
@@ -29,10 +29,28 @@ module Texas
29
29
  known_extensions.concat extensions
30
30
  end
31
31
 
32
+ # Registers the methods defined in a module to use
33
+ # them in templates.
34
+ #
35
+ # Example:
36
+ # module Foo
37
+ # def bar; "foobar"; end
38
+ # end
39
+ # Template.register_helper Foo
40
+ #
41
+ # # afterwards, this prints "foobar" in any template:
42
+ # <%= bar %>
43
+ #
32
44
  def register_helper(klass)
33
45
  Template::Runner::Base.__send__ :include, klass
34
46
  end
35
47
 
48
+ # Returns a Template runner for the given filename
49
+ #
50
+ # Example:
51
+ # Template.create("some_file.tex.erb", build)
52
+ # # => #<Template::Runner::TeX ...>
53
+ #
36
54
  def create(filename, build)
37
55
  handler(filename).new(filename, build)
38
56
  end
@@ -40,7 +58,7 @@ module Texas
40
58
  # Returns the filename without the template extension
41
59
  #
42
60
  # Example:
43
- # input_path("/home/rene/github/sample_project/tmp/build/chapter-01/contents.md.erb")
61
+ # Template.basename("/home/rene/github/sample_project/tmp/build/chapter-01/contents.md.erb")
44
62
  # # => "/home/rene/github/sample_project/tmp/build/chapter-01/contents"
45
63
  #
46
64
  def basename(filename)
@@ -13,7 +13,7 @@ module Texas
13
13
  path_with_templates_basename,
14
14
  build_path,
15
15
  build.root
16
- ].compact
16
+ ].compact.uniq
17
17
  end
18
18
 
19
19
  # Returns a subdir with the current template's basename
@@ -31,12 +31,14 @@ module Texas
31
31
  # Searches for the given file in +possible_paths+, also checking for +possible_exts+ as extensions
32
32
  #
33
33
  # Example:
34
- # find_template_file(["figures", "titel"], [:pdf, :png])
34
+ # find_template_file(["figures", "some-chart"], [:pdf, :png], ["", "tmp", "tmp/build"])
35
35
  # # => will check
36
- # figures/titel.pdf
37
- # figures/titel.png
38
- # tmp/figures/titel.pdf
39
- # tmp/figures/titel.png
36
+ # figures/some-chart.pdf
37
+ # figures/some-chart.png
38
+ # tmp/figures/some-chart.pdf
39
+ # tmp/figures/some-chart.png
40
+ # tmp/build/figures/some-chart.pdf
41
+ # tmp/build/figures/some-chart.png
40
42
  #
41
43
  def find_template_file(parts, possible_exts = [], possible_paths = default_search_paths)
42
44
  possible_paths.each do |base|
@@ -57,7 +59,7 @@ module Texas
57
59
  if filename = find_template_file(parts, possible_exts, possible_paths)
58
60
  filename
59
61
  else
60
- raise TemplateError.new(self, "File doesnot exists anywhere: #{parts.size > 1 ? parts : parts.first}")
62
+ raise TemplateError.new(self, "File doesn't exists anywhere: #{parts.size > 1 ? parts : parts.first}")
61
63
  end
62
64
  end
63
65
 
@@ -67,7 +69,7 @@ module Texas
67
69
  render("_#{name}", locals)
68
70
  end
69
71
 
70
- # Renders a template with the given locals.
72
+ # Renders one or more templates with the given locals.
71
73
  #
72
74
  def render(options, locals = {})
73
75
  if [String, Symbol].include?(options.class)
data/lib/texas/version.rb CHANGED
@@ -2,7 +2,7 @@ module Texas
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- BUILD = 5
5
+ BUILD = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, BUILD].join('.').freeze
8
8
  end
@@ -2,5 +2,5 @@
2
2
  info.write_at_end_of_build = true
3
3
  %>
4
4
 
5
- <%= document.message %>
6
- <% document.message = "Hello World!" %>
5
+ <%= store.message %>
6
+ <% store.message = "Hello World!" %>
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Texas::Build::Base do
4
+
5
+ def test_build
6
+ @test_build ||= get_runner_instance
7
+ end
8
+
9
+ def get_runner_instance
10
+ run_scenario "basic" do |runner|
11
+ return runner.task_instance
12
+ end
13
+ end
14
+
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
+ class FoobarTask
25
+ class << self
26
+ attr_accessor :foo
27
+ end
28
+
29
+ def initialize(*args)
30
+ end
31
+
32
+ def run
33
+ self.class.foo = :bar
34
+ end
35
+ end
36
+
37
+ describe "#run_build_task" do
38
+ it "should instantiate the given class and call the run method" do
39
+ FoobarTask.foo.nil?.should == true
40
+ test_build.run_build_task FoobarTask
41
+ FoobarTask.foo.should == :bar
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe Texas::Build::Task::PublishPDF do
4
+
5
+ def test_build
6
+ run_scenario "basic" do |runner|
7
+ return runner.task_instance
8
+ end
9
+ end
10
+
11
+ describe "#run" do
12
+ it "should return an info object for the given template" do
13
+ test_build.run_build_task Texas::Build::Task::PublishPDF
14
+ end
15
+ end
16
+
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 0.8.8
53
+ version: '0.9'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.8
61
+ version: '0.9'
62
62
  description: A tool for creating LaTex files from ERb templates and processing them
63
63
  into PDF format.
64
64
  email: rf@bamaru.de
@@ -102,8 +102,9 @@ files:
102
102
  - lib/texas.rb
103
103
  - spec/texas/template/runner_spec.rb
104
104
  - spec/texas/template/helper/info_spec.rb
105
- - spec/texas/build_spec.rb
106
105
  - spec/texas/template_spec.rb
106
+ - spec/texas/build/task/publish_pdf_spec.rb
107
+ - spec/texas/build/base_spec.rb
107
108
  - spec/texas_spec.rb
108
109
  - spec/fixtures/different-master-tex/contents/contents.tex.erb
109
110
  - spec/fixtures/different-master-tex/contents/contents.tex.should
@@ -1,17 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Texas::Build::Base do
4
- describe "#ran_templates" do
5
-
6
- it "returns the templates" do
7
- run_scenario "basic-md" do |runner|
8
- build = runner.task_instance
9
- filenames = build.ran_templates.map(&:filename)
10
- basenames = filenames.map { |f| f.gsub(build.__path__+'/', '') }
11
- basenames.size.should > 0
12
- basenames.include?("unused_template.tex.erb").should == false
13
- end
14
- end
15
-
16
- end
17
- end