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.
Files changed (48) hide show
  1. checksums.yaml +15 -0
  2. data/bin/texas +1 -1
  3. data/lib/texas.rb +13 -2
  4. data/lib/texas/build.rb +32 -0
  5. data/lib/texas/build/base.rb +47 -24
  6. data/lib/texas/build/config.rb +118 -0
  7. data/lib/texas/build/config_loader.rb +93 -0
  8. data/lib/texas/build/dry.rb +1 -1
  9. data/lib/texas/build/final.rb +2 -2
  10. data/lib/texas/build/task/add_default_templates_to_build_path.rb +4 -0
  11. data/lib/texas/build/task/base.rb +2 -0
  12. data/lib/texas/build/task/copy_contents_to_build_path.rb +3 -0
  13. data/lib/texas/build/task/execute_after_scripts.rb +18 -0
  14. data/lib/texas/build/task/execute_before_scripts.rb +18 -0
  15. data/lib/texas/build/task/open_pdf.rb +7 -21
  16. data/lib/texas/build/task/publish_pdf.rb +35 -27
  17. data/lib/texas/build/task/run_master_template.rb +2 -0
  18. data/lib/texas/build/task/script.rb +28 -0
  19. data/lib/texas/core_ext.rb +2 -1
  20. data/lib/texas/core_ext/hash.rb +34 -0
  21. data/lib/texas/core_ext/string.rb +1 -128
  22. data/lib/texas/option_parser.rb +153 -124
  23. data/lib/texas/output_helper.rb +58 -0
  24. data/lib/texas/runner.rb +32 -51
  25. data/lib/texas/task/base.rb +1 -0
  26. data/lib/texas/task/new_project.rb +1 -1
  27. data/lib/texas/task/watch.rb +29 -18
  28. data/lib/texas/template.rb +6 -2
  29. data/lib/texas/template/helper/base.rb +60 -9
  30. data/lib/texas/template/helper/tex.rb +2 -4
  31. data/lib/texas/template/runner.rb +2 -5
  32. data/lib/texas/template/runner/base.rb +59 -11
  33. data/lib/texas/template/runner/md.rb +2 -2
  34. data/lib/texas/template/runner/tex.rb +2 -2
  35. data/lib/texas/template/template_error.rb +19 -5
  36. data/lib/texas/version.rb +1 -1
  37. data/spec/fixtures/basic-tex/contents/{unused_template.tex.erb → sub_dir/unused_template.tex.erb} +0 -0
  38. data/spec/fixtures/new-project/lib/init.rb +1 -1
  39. data/spec/fixtures/pdflatex-error/contents/contents.tex.erb +1 -0
  40. data/spec/spec_helper.rb +16 -7
  41. data/spec/texas/build/base_spec.rb +53 -9
  42. data/spec/texas/build/config_spec.rb +73 -0
  43. data/spec/texas/build/task/base_spec.rb +21 -0
  44. data/spec/texas/option_parser_spec.rb +53 -0
  45. data/spec/texas/task/base_spec.rb +49 -0
  46. data/spec/texas_spec.rb +49 -3
  47. metadata +76 -73
  48. data/lib/texas/build/task/run_before_scripts.rb +0 -22
@@ -1,6 +1,10 @@
1
1
  module Texas
2
2
  module Build
3
3
  module Task
4
+ # This build task copies those templates from Texas' own template
5
+ # directory that are still missing in the current project's build
6
+ # directory (e.g. the preambel partial)
7
+ #
4
8
  class AddDefaultTemplatesToBuildPath < Base
5
9
  def build_path
6
10
  build.__path__
@@ -2,11 +2,13 @@ module Texas
2
2
  module Build
3
3
  module Task
4
4
  class Base
5
+ include Texas::OutputHelper
5
6
  attr_reader :build
6
7
 
7
8
  def initialize(_build = nil)
8
9
  @build = _build
9
10
  end
11
+
10
12
  def run
11
13
  end
12
14
  end
@@ -1,6 +1,9 @@
1
1
  module Texas
2
2
  module Build
3
3
  module Task
4
+ # This build task copies all the templates in the current project's
5
+ # contents directory to the build directory.
6
+ #
4
7
  class CopyContentsToBuildPath < Base
5
8
  def run
6
9
  ensure_build_path_exists
@@ -0,0 +1,18 @@
1
+ module Texas
2
+ module Build
3
+ module Task
4
+ # This build task checks the 'after' script in
5
+ # the config's script section and executes it, if present.
6
+ #
7
+ class ExecuteAfterScripts < Script
8
+ def cmd
9
+ cmd_from_config :after
10
+ end
11
+
12
+ def run
13
+ execute cmd if cmd
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Texas
2
+ module Build
3
+ module Task
4
+ # This build task checks the 'before' script in
5
+ # the config's script section and executes it, if present.
6
+ #
7
+ class ExecuteBeforeScripts < Script
8
+ def cmd
9
+ cmd_from_config :before
10
+ end
11
+
12
+ def run
13
+ execute cmd if cmd
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,32 +1,18 @@
1
1
  module Texas
2
2
  module Build
3
3
  module Task
4
- class OpenPDF < Base
5
- DEFAULT_OPEN_CMD = "evince"
4
+ # This build task opens the generated PDF file.
5
+ #
6
+ class OpenPDF < Script
7
+ DEFAULT_OPEN_CMD = 'evince "<%= build.dest_file %>"'
6
8
 
7
9
  def cmd
8
- @cmd ||= scripts && scripts['open']
9
- end
10
-
11
- def scripts
12
- build.config['script']
10
+ cmd_from_config :open, DEFAULT_OPEN_CMD
13
11
  end
14
12
 
15
13
  def run
16
- return unless build.options.open_pdf
17
- if open_pdf_cmd
18
- system "#{open_pdf_cmd} #{build.dest_file}"
19
- else
20
- puts "Can't open PDF: no default command recognized. Specify in #{Build::Base::CONFIG_FILE}"
21
- end
22
- end
23
-
24
- def open_pdf_cmd
25
- if cmd
26
- cmd
27
- else
28
- default = `which #{DEFAULT_OPEN_CMD}`.strip
29
- default.empty? ? nil : default
14
+ if cmd && build.options.open_pdf
15
+ execute cmd
30
16
  end
31
17
  end
32
18
 
@@ -1,11 +1,10 @@
1
1
  module Texas
2
2
  module Build
3
3
  module Task
4
- class PublishPDF < Base
5
-
6
- def master_file
7
- build.master_file
8
- end
4
+ # This build task compiles the generated *.tex files into a PDF.
5
+ #
6
+ class PublishPDF < Script
7
+ DEFAULT_COMPILE_CMD = 'pdflatex -halt-on-error "<%= File.basename(build.master_file) %>"'
9
8
 
10
9
  def build_path
11
10
  build.__path__
@@ -16,36 +15,45 @@ module Texas
16
15
  end
17
16
 
18
17
  def run
19
- run_pdflatex
20
- copy_pdf_file_to_dest_dir
18
+ latex_cmd_output = compile_pdf
19
+ if compile_pdf_successfull?
20
+ compile_pdf # again
21
+ copy_pdf_file_to_dest_dir
22
+ else
23
+ trace latex_cmd_output
24
+ raise "Error while running: `#{compile_cmd.cyan}`"
25
+ end
21
26
  end
22
-
27
+
28
+ def compile_pdf_successfull?
29
+ $?.to_i == 0
30
+ end
31
+
23
32
  def copy_pdf_file_to_dest_dir
24
- tmp_file = File.join(build_path, "#{File.basename(master_file, '.tex')}.pdf")
33
+ basename = File.basename(build.master_file, '.tex')
34
+ tmp_file = File.join(build_path, "#{basename}.pdf")
25
35
  FileUtils.mkdir_p File.dirname(dest_file)
26
36
  FileUtils.copy tmp_file, dest_file
27
- verbose {
28
- file = File.join(build_path, "master.log")
29
- output = `grep "Output written on" #{file}`
30
- numbers = output.scan(/\((\d+?) pages?\, (\d+?) bytes\)\./).flatten
31
- @page_count = numbers.first.to_i
32
- "Written PDF in #{dest_file.gsub(build.root, '')} (#{@page_count} pages)".green
33
- }
37
+ verbose { verbose_info }
38
+ end
39
+
40
+ def compile_cmd
41
+ cmd_from_config :compile, DEFAULT_COMPILE_CMD
34
42
  end
35
43
 
36
- def run_pdflatex
37
- verbose { "Running pdflatex in #{build_path} ..." }
38
- run_in build_path do
39
- `pdflatex #{File.basename(master_file)}`
40
- `pdflatex #{File.basename(master_file)}`
41
- end
44
+ def compile_pdf
45
+ execute compile_cmd
46
+ end
47
+
48
+ def tex_log_file
49
+ File.join(build_path, "master.log")
42
50
  end
43
51
 
44
- def run_in(path)
45
- old_path = Dir.pwd
46
- Dir.chdir path
47
- yield
48
- Dir.chdir old_path
52
+ def verbose_info
53
+ output = `grep "Output written on" #{tex_log_file}`
54
+ numbers = output.scan(/\((\d+?) pages?\, (\d+?) bytes\)\./).flatten
55
+ @page_count = numbers.first.to_i
56
+ verbose { TraceInfo.new(:written, "#{dest_file.gsub(build.root, '')} (#{@page_count} pages)", :magenta) }
49
57
  end
50
58
 
51
59
  end
@@ -1,6 +1,8 @@
1
1
  module Texas
2
2
  module Build
3
3
  module Task
4
+ # This build task finds and runs the master template.
5
+ #
4
6
  class RunMasterTemplate < Base
5
7
 
6
8
  def find_master_template(possible_templates)
@@ -0,0 +1,28 @@
1
+ module Texas
2
+ module Build
3
+ module Task
4
+ class Script < Base
5
+
6
+ def cmd_from_config(key, default_value = nil)
7
+ if cmd = build.config.script(key) || default_value
8
+ ERB.new(cmd).result(binding)
9
+ end
10
+ end
11
+
12
+ def execute(cmd)
13
+ verbose { TraceInfo.new(:run, "`#{cmd}`", :cyan) }
14
+ execute_in(build.__path__) { `#{cmd}` }
15
+ end
16
+
17
+ def execute_in(path)
18
+ old_path = Dir.pwd
19
+ Dir.chdir path
20
+ return_value = yield
21
+ Dir.chdir old_path
22
+ return_value
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1 +1,2 @@
1
- require_relative 'core_ext/string'
1
+ require_relative 'core_ext/hash'
2
+ require_relative 'core_ext/string'
@@ -0,0 +1,34 @@
1
+ class Hash
2
+ # Returns a new hash with self and other_hash merged recursively.
3
+ #
4
+ def deep_merge(other_hash)
5
+ dup.deep_merge!(other_hash)
6
+ end
7
+
8
+ # Returns a new hash with self and other_hash merged recursively.
9
+ # Modifies the receiver in place.
10
+ #
11
+ def deep_merge!(other_hash)
12
+ other_hash.each_pair do |k,v|
13
+ tv = self[k]
14
+ self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
15
+ end
16
+ self
17
+ end
18
+
19
+ # Destructively convert all keys to strings.
20
+ #
21
+ def stringify_keys
22
+ dup.stringify_keys!
23
+ end
24
+
25
+ # Destructively convert all keys to strings.
26
+ # Modifies the receiver in place.
27
+ #
28
+ def stringify_keys!
29
+ keys.each do |key|
30
+ self[key.to_s] = delete(key)
31
+ end
32
+ self
33
+ end
34
+ end
@@ -2,131 +2,4 @@ require 'term/ansicolor'
2
2
 
3
3
  class String
4
4
 
5
- end
6
-
7
- module Term
8
- # The ANSIColor module can be used for namespacing and mixed into your own
9
- # classes.
10
- module NoColor
11
- # :stopdoc:
12
- ATTRIBUTES = [
13
- [ :clear , 0 ], # String#clear is already used to empty string in Ruby 1.9
14
- [ :reset , 0 ], # synonym for :clear
15
- [ :bold , 1 ],
16
- [ :dark , 2 ],
17
- [ :italic , 3 ], # not widely implemented
18
- [ :underline , 4 ],
19
- [ :underscore , 4 ], # synonym for :underline
20
- [ :blink , 5 ],
21
- [ :rapid_blink , 6 ], # not widely implemented
22
- [ :negative , 7 ], # no reverse because of String#reverse
23
- [ :concealed , 8 ],
24
- [ :strikethrough , 9 ], # not widely implemented
25
- [ :black , 30 ],
26
- [ :red , 31 ],
27
- [ :green , 32 ],
28
- [ :yellow , 33 ],
29
- [ :blue , 34 ],
30
- [ :magenta , 35 ],
31
- [ :cyan , 36 ],
32
- [ :white , 37 ],
33
- [ :on_black , 40 ],
34
- [ :on_red , 41 ],
35
- [ :on_green , 42 ],
36
- [ :on_yellow , 43 ],
37
- [ :on_blue , 44 ],
38
- [ :on_magenta , 45 ],
39
- [ :on_cyan , 46 ],
40
- [ :on_white , 47 ],
41
- [ :intense_black , 90 ], # High intensity, aixterm (works in OS X)
42
- [ :intense_red , 91 ],
43
- [ :intense_green , 92 ],
44
- [ :intense_yellow , 93 ],
45
- [ :intense_blue , 94 ],
46
- [ :intense_magenta , 95 ],
47
- [ :intense_cyan , 96 ],
48
- [ :intense_white , 97 ],
49
- [ :on_intense_black , 100 ], # High intensity background, aixterm (works in OS X)
50
- [ :on_intense_red , 101 ],
51
- [ :on_intense_green , 102 ],
52
- [ :on_intense_yellow , 103 ],
53
- [ :on_intense_blue , 104 ],
54
- [ :on_intense_magenta , 105 ],
55
- [ :on_intense_cyan , 106 ],
56
- [ :on_intense_white , 107 ]
57
- ]
58
-
59
- ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
60
- # :startdoc:
61
-
62
- # Returns true if Term::ANSIColor supports the +feature+.
63
- #
64
- # The feature :clear, that is mixing the clear color attribute into String,
65
- # is only supported on ruby implementations, that do *not* already
66
- # implement the String#clear method. It's better to use the reset color
67
- # attribute instead.
68
- def support?(feature)
69
- case feature
70
- when :clear
71
- !String.instance_methods(false).map(&:to_sym).include?(:clear)
72
- end
73
- end
74
- # Returns true, if the coloring function of this module
75
- # is switched on, false otherwise.
76
- def self.coloring?
77
- @coloring
78
- end
79
-
80
- # Turns the coloring on or off globally, so you can easily do
81
- # this for example:
82
- # Term::ANSIColor::coloring = STDOUT.isatty
83
- def self.coloring=(val)
84
- @coloring = val
85
- end
86
- self.coloring = true
87
-
88
- ATTRIBUTES.each do |c, v|
89
- eval <<-EOT
90
- def #{c}(string = nil)
91
- result = ''
92
- if block_given?
93
- result << yield
94
- elsif string.respond_to?(:to_str)
95
- result << string.to_str
96
- elsif respond_to?(:to_str)
97
- result << to_str
98
- else
99
- return result #only switch on
100
- end
101
- result
102
- end
103
- EOT
104
- end
105
-
106
- # Regular expression that is used to scan for ANSI-sequences while
107
- # uncoloring strings.
108
- COLORED_REGEXP = /\e\[(?:(?:[349]|10)[0-7]|[0-9])?m/
109
-
110
- # Returns an uncolored version of the string, that is all
111
- # ANSI-sequences are stripped from the string.
112
- def uncolored(string = nil) # :yields:
113
- if block_given?
114
- yield.to_str.gsub(COLORED_REGEXP, '')
115
- elsif string.respond_to?(:to_str)
116
- string.to_str.gsub(COLORED_REGEXP, '')
117
- elsif respond_to?(:to_str)
118
- to_str.gsub(COLORED_REGEXP, '')
119
- else
120
- ''
121
- end
122
- end
123
-
124
- module_function
125
-
126
- # Returns an array of all Term::ANSIColor attributes as symbols.
127
- def attributes
128
- ATTRIBUTE_NAMES
129
- end
130
- extend self
131
- end
132
- end
5
+ end
@@ -5,6 +5,7 @@ require 'pathname'
5
5
 
6
6
  module Texas
7
7
  class OptionParser
8
+ include Texas::OutputHelper
8
9
  attr_reader :args, :options
9
10
 
10
11
  def initialize(args)
@@ -12,140 +13,37 @@ module Texas
12
13
  @options = OpenStruct.new
13
14
  end
14
15
 
15
- # Return a structure describing the options.
16
+ # Returns a structure describing the options.
16
17
  #
17
18
  def parse
18
- # The options specified on the command line will be collected in *options*.
19
- # We set default values here.
20
- options.task = :build
21
- options.work_dir = find_work_dir
22
- options.check_mandatory_arguments = true
23
- options.load_local_libs = true
24
- options.contents_dir = Texas.contents_subdir_name
25
- options.contents_template = find_contents_file("contents")
26
- options.backtrace = false
27
- options.colors = true
28
- options.merge_config = nil
29
- options.verbose = false
30
- options.warnings = true
31
- options.open_pdf = true
32
-
19
+ set_default_options
33
20
  lookup_and_execute_require_option(args)
34
-
35
- opts = ::OptionParser.new do |opts|
36
- opts.banner = "Usage: texas [CONTENTS_TEMPLATE] [options]"
37
-
38
- opts.separator ""
39
- opts.separator "Specific options:"
40
-
41
- opts.on("-d", "--dry-run", "Run without pdf generation") do |contents_template|
42
- options.task = :dry
43
- end
44
-
45
- opts.on("-m", "--merge-config [CONFIG]",
46
- "Merge config with key from .texasrc") do |key|
47
- options.merge_config = key
48
- end
49
-
50
- opts.on("-n", "--new [NAME]",
51
- "Create new texas project directory") do |name|
52
- options.task = :new_project
53
- options.check_mandatory_arguments = false
54
- options.load_local_libs = false
55
- options.new_project_name = name
56
- end
57
-
58
- opts.on("-r", "--require [LIBRARY]", "Require library before running texas") do |lib|
59
- # this block does nothing
60
- # require was already performed by lookup_and_execute_require_option
61
- # this option is here to ensure the -r switch is listed in the help option
62
- end
63
-
64
- opts.on("--watch", "Watch the given template") do |contents_template|
65
- options.task = :watch
66
- options.open_pdf = false
67
- end
68
-
69
- parse_additional_options(opts)
70
-
71
- opts.separator ""
72
- opts.separator "Common options:"
73
-
74
- opts.on("--[no-]backtrace", "Switch backtrace") do |v|
75
- options.backtrace = v
76
- end
77
-
78
- opts.on("-c", "--[no-]color", "Switch colors") do |v|
79
- options.colors = v
80
- end
81
-
82
- opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
83
- options.verbose = v
84
- end
85
-
86
- opts.on("-w", "--[no-]warnings", "Switch warnings") do |v|
87
- options.warnings = v
88
- end
89
-
90
- # No argument, shows at tail. This will print an options summary.
91
- # Try it and see!
92
- opts.on_tail("-h", "--help", "Show this message") do
93
- puts opts
94
- exit
95
- end
96
-
97
- # Another typical switch to print the version.
98
- opts.on_tail("--version", "Show version") do
99
- puts Texas::VERSION::STRING
100
- exit
101
- end
102
- end
103
-
104
- opts.parse!(args)
105
-
106
- unless args.empty?
107
- f = args.shift
108
- options.contents_template = find_contents_file(f)
109
- options.contents_dir = find_contents_dir(f)
110
- end
111
- if options.check_mandatory_arguments
112
- check_mandatory! options
113
- end
21
+ parse_options
22
+ set_contents_template_from_args unless args.empty?
23
+ check_mandatory! if options.check_mandatory_arguments
114
24
  options
115
25
  end
116
26
 
117
27
  private
118
28
 
119
- # Is empty. It can be overwritten by other libraries to
120
- # parse and display additional options.
121
- #
122
- def parse_additional_options(opts)
123
- end
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.
29
+ # Kills the program if any mandatory options are missing.
129
30
  #
130
- def lookup_and_execute_require_option(args)
131
- args.each_with_index do |v, i|
132
- if %w(-r --require).include?(v)
133
- require args[i+1]
134
- end
135
- end
136
- end
137
-
138
- def check_mandatory!(options)
31
+ def check_mandatory!
139
32
  if options.work_dir.nil?
140
- warn "texas: missing file operand\nTry `texas --help' for more information."
141
- exit 1
33
+ kill "missing file operand"
142
34
  end
143
35
  if options.contents_template.nil?
144
- warn "texas: could not find contents template\nTry `texas --help' for more information."
145
- exit 1
36
+ kill "could not find contents template"
146
37
  end
147
38
  end
148
39
 
40
+ # Displays an error message and exits the program afterwards.
41
+ #
42
+ def kill(msg)
43
+ trace "texas: #{msg}\nTry `texas --help' for more information."
44
+ exit 1
45
+ end
46
+
149
47
  def find_work_dir(start_dir = Dir.pwd)
150
48
  results = Dir[File.join(start_dir, Texas.contents_subdir_name)]
151
49
  if !results.empty?
@@ -161,10 +59,10 @@ module Texas
161
59
  end
162
60
 
163
61
  def find_contents_dir(file)
164
- if Dir["#{file}*"].empty?
165
- nil
62
+ if file =~ /#{Texas.contents_subdir_name}/
63
+ Texas.contents_subdir_name
166
64
  else
167
- File.dirname(file)
65
+ nil
168
66
  end
169
67
  end
170
68
 
@@ -177,6 +75,137 @@ module Texas
177
75
  file
178
76
  end
179
77
  end
180
- end
181
78
 
182
- end
79
+ # Parses the given arguments for the --require option and requires
80
+ # it if present. This is done separately from the regular option parsing
81
+ # to enable the required library to modify Texas,
82
+ # e.g. overwrite OptionParser#parse_additional_options.
83
+ #
84
+ def lookup_and_execute_require_option(args)
85
+ args.each_with_index do |v, i|
86
+ if %w(-r --require).include?(v)
87
+ require args[i+1]
88
+ end
89
+ end
90
+ end
91
+
92
+ def parse_options
93
+ parser = ::OptionParser.new do |parser|
94
+ parser.banner = "Usage: texas [CONTENTS_TEMPLATE] [options]"
95
+ parse_specific_options(parser)
96
+ parse_additional_options(parser)
97
+ parse_common_options(parser)
98
+ end
99
+ parser.parse!(args)
100
+ end
101
+
102
+ def parse_additional_options(parser)
103
+ if arr = self.class.parse_options_procs
104
+ parser.separator ""
105
+ parser.separator "Custom options:"
106
+ arr.each do |proc|
107
+ proc.(parser, options)
108
+ end
109
+ end
110
+ end
111
+
112
+ def self.parse_options_procs
113
+ @@parse_options_procs ||= []
114
+ end
115
+
116
+ def self.parse_additional_options(&block)
117
+ parse_options_procs << block
118
+ end
119
+
120
+ def parse_common_options(parser)
121
+ parser.separator ""
122
+ parser.separator "Common options:"
123
+
124
+ parser.on("--[no-]backtrace", "Switch backtrace") do |v|
125
+ options.backtrace = v
126
+ end
127
+
128
+ parser.on("-c", "--[no-]color", "Switch colors") do |v|
129
+ options.colors = v
130
+ end
131
+
132
+ parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
133
+ options.verbose = v
134
+ end
135
+
136
+ parser.on("-w", "--[no-]warnings", "Switch warnings") do |v|
137
+ options.warnings = v
138
+ end
139
+
140
+ # No argument, shows at tail. This will print an options summary.
141
+ # Try it and see!
142
+ parser.on_tail("-h", "--help", "Show this message") do
143
+ trace parser
144
+ exit
145
+ end
146
+
147
+ # Another typical switch to print the version.
148
+ parser.on_tail("--version", "Show version") do
149
+ trace Texas::VERSION::STRING
150
+ exit
151
+ end
152
+ end
153
+
154
+ # Parses the specific options.
155
+ #
156
+ def parse_specific_options(parser)
157
+ parser.separator ""
158
+ parser.separator "Specific options:"
159
+
160
+ parser.on("-d", "--dry-run", "Run without pdf generation") do |contents_template|
161
+ options.task = :dry
162
+ end
163
+
164
+ parser.on("-m", "--merge-config [CONFIG]",
165
+ "Merge config with key from .texasrc") do |key|
166
+ options.merge_config = key
167
+ end
168
+
169
+ parser.on("-n", "--new [NAME]",
170
+ "Create new texas project directory") do |name|
171
+ options.task = :new_project
172
+ options.check_mandatory_arguments = false
173
+ options.load_local_libs = false
174
+ options.new_project_name = name
175
+ end
176
+
177
+ parser.on("-r", "--require [LIBRARY]", "Require library before running texas") do |lib|
178
+ # this block does nothing
179
+ # require was already performed by lookup_and_execute_require_option
180
+ # this option is here to ensure the -r switch is listed in the help option
181
+ end
182
+
183
+ parser.on("--watch", "Watch the given template") do |contents_template|
184
+ options.task = :watch
185
+ options.open_pdf = false
186
+ end
187
+ end
188
+
189
+ def set_default_options
190
+ options.task = :build
191
+ options.work_dir = find_work_dir
192
+ options.check_mandatory_arguments = true
193
+ options.load_local_libs = true
194
+ options.contents_dir = Texas.contents_subdir_name
195
+ options.contents_template = find_contents_file("contents")
196
+ options.backtrace = false
197
+ options.colors = true
198
+ options.merge_config = nil
199
+ options.verbose = false
200
+ options.warnings = true
201
+ options.open_pdf = true
202
+ end
203
+
204
+ def set_contents_template_from_args
205
+ f = args.shift
206
+ options.contents_template = find_contents_file(f)
207
+ options.contents_dir = find_contents_dir(f)
208
+ end
209
+
210
+ end
211
+ end