texas 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/bin/texas +6 -0
  2. data/contents/_chapter.md.erb +13 -0
  3. data/contents/_preambel.tex.erb +50 -0
  4. data/contents/master.tex.erb +7 -0
  5. data/lib/texas/build/base.rb +120 -0
  6. data/lib/texas/build/dry.rb +11 -0
  7. data/lib/texas/build/final.rb +7 -0
  8. data/lib/texas/build/task/add_default_templates_to_build_path.rb +22 -0
  9. data/lib/texas/build/task/base.rb +15 -0
  10. data/lib/texas/build/task/copy_contents_to_build_path.rb +31 -0
  11. data/lib/texas/build/task/open_pdf.rb +36 -0
  12. data/lib/texas/build/task/publish_pdf.rb +46 -0
  13. data/lib/texas/build/task/rewrite_marked_templates.rb +13 -0
  14. data/lib/texas/build/task/run_before_scripts.rb +22 -0
  15. data/lib/texas/build/task/run_master_template.rb +23 -0
  16. data/lib/texas/build.rb +15 -0
  17. data/lib/texas/core_ext/string.rb +132 -0
  18. data/lib/texas/core_ext.rb +1 -0
  19. data/lib/texas/option_parser.rb +175 -0
  20. data/lib/texas/runner.rb +71 -0
  21. data/lib/texas/task/base.rb +23 -0
  22. data/lib/texas/task/new.rb +18 -0
  23. data/lib/texas/task/watch.rb +39 -0
  24. data/lib/texas/task.rb +11 -0
  25. data/lib/texas/template/helper/base.rb +82 -0
  26. data/lib/texas/template/helper/info.rb +29 -0
  27. data/lib/texas/template/helper/md.rb +35 -0
  28. data/lib/texas/template/helper/tex.rb +83 -0
  29. data/lib/texas/template/helper.rb +6 -0
  30. data/lib/texas/template/runner/base.rb +70 -0
  31. data/lib/texas/template/runner/md.rb +16 -0
  32. data/lib/texas/template/runner/tex.rb +11 -0
  33. data/lib/texas/template/runner.rb +13 -0
  34. data/lib/texas/template.rb +62 -0
  35. data/lib/texas/version.rb +9 -0
  36. data/lib/texas.rb +18 -0
  37. data/spec/fixtures/basic/contents/contents.tex.erb +8 -0
  38. data/spec/fixtures/basic/figures/test_figure.png +0 -0
  39. data/spec/fixtures/basic-md/contents/contents.md.erb +1 -0
  40. data/spec/fixtures/basic-md/contents/contents.tex.should +3 -0
  41. data/spec/fixtures/basic-md/contents/input_template.md.erb +3 -0
  42. data/spec/fixtures/basic-tex/contents/contents.tex.erb +1 -0
  43. data/spec/fixtures/basic-tex/contents/contents.tex.should +1 -0
  44. data/spec/fixtures/basic-tex/contents/input_template.tex.erb +3 -0
  45. data/spec/fixtures/basic-tex/contents/input_template.tex.should +3 -0
  46. data/spec/fixtures/basic-tex/contents/unused_template.tex.erb +1 -0
  47. data/spec/fixtures/different-master-tex/contents/contents.tex.erb +1 -0
  48. data/spec/fixtures/different-master-tex/contents/contents.tex.should +1 -0
  49. data/spec/fixtures/different-master-tex/contents/master.tex.erb +9 -0
  50. data/spec/fixtures/different-master-tex/contents/master.tex.should +59 -0
  51. data/spec/fixtures/helper-methods-tex/contents/contents.tex.erb +7 -0
  52. data/spec/fixtures/helper-methods-tex/contents/contents.tex.should +7 -0
  53. data/spec/fixtures/helper-methods-tex/contents/input_template.tex.erb +5 -0
  54. data/spec/fixtures/helper-methods-tex/contents/input_template.tex.should +5 -0
  55. data/spec/fixtures/helper-methods-tex/contents/some_chapter/another_include.tex +1 -0
  56. data/spec/fixtures/helper-methods-tex/contents/some_chapter/test_include.tex.erb +7 -0
  57. data/spec/fixtures/helper-methods-tex/contents/some_chapter/test_include.tex.should +7 -0
  58. data/spec/fixtures/helper-methods-tex/contents/some_chapter.tex.erb +5 -0
  59. data/spec/fixtures/helper-methods-tex/contents/some_chapter.tex.should +5 -0
  60. data/spec/fixtures/helper-methods-tex/contents/template/helper/_some_partial.md.erb +1 -0
  61. data/spec/fixtures/helper-methods-tex/contents/template/helper/base.tex.erb +3 -0
  62. data/spec/fixtures/helper-methods-tex/contents/template/helper/base.tex.should +4 -0
  63. data/spec/fixtures/helper-methods-tex/contents/template/helper/info.md.erb +6 -0
  64. data/spec/fixtures/helper-methods-tex/contents/template/helper/info.tex.should +1 -0
  65. data/spec/fixtures/helper-methods-tex/contents/test_figure.tex.erb +1 -0
  66. data/spec/fixtures/helper-methods-tex/figures/test_figure.png +0 -0
  67. data/spec/fixtures/lib-helpers/contents/contents.tex.erb +3 -0
  68. data/spec/fixtures/lib-helpers/contents/contents.tex.should +3 -0
  69. data/spec/fixtures/lib-helpers/lib/helpers/document_helper.rb +7 -0
  70. data/spec/fixtures/lib-helpers/lib/init.rb +4 -0
  71. data/spec/fixtures/new/contents/contents.tex.erb +9 -0
  72. data/spec/fixtures/new/lib/helpers/document_helper.rb +11 -0
  73. data/spec/fixtures/new/lib/init.rb +4 -0
  74. data/spec/fixtures/prose/contents/chapter-1/01-some-scene.md +1 -0
  75. data/spec/fixtures/prose/contents/chapter-1/02-another-scene.md +1 -0
  76. data/spec/fixtures/prose/contents/chapter-1/03-and-another-scene.md +1 -0
  77. data/spec/fixtures/prose/contents/contents.md.erb +1 -0
  78. data/spec/fixtures/rerun/contents/contents.tex.erb +6 -0
  79. data/spec/fixtures/rerun/contents/contents.tex.should +4 -0
  80. data/spec/fixtures/texasrc/contents/contents.tex.erb +3 -0
  81. data/spec/fixtures/texasrc/contents/contents.tex.should +3 -0
  82. data/spec/spec_helper.rb +64 -0
  83. data/spec/texas/build_spec.rb +17 -0
  84. data/spec/texas/template/helper/info_spec.rb +41 -0
  85. data/spec/texas/template/runner_spec.rb +35 -0
  86. data/spec/texas/template_spec.rb +11 -0
  87. data/spec/texas_spec.rb +43 -0
  88. metadata +196 -0
@@ -0,0 +1,175 @@
1
+ require 'optparse'
2
+ require 'optparse/time'
3
+ require 'ostruct'
4
+ require 'pathname'
5
+
6
+ module Texas
7
+ class OptionParser
8
+ attr_reader :args, :options
9
+
10
+ def initialize(args)
11
+ @args = args
12
+ @options = OpenStruct.new
13
+ end
14
+
15
+ #
16
+ # Return a structure describing the options.
17
+ #
18
+ def parse
19
+ # The options specified on the command line will be collected in *options*.
20
+ # We set default values here.
21
+ options.task = :build
22
+ options.work_dir = find_work_dir
23
+ options.check_mandatory_arguments = true
24
+ options.load_local_libs = true
25
+ options.contents_dir = Texas.contents_subdir_name
26
+ options.contents_template = find_contents_file("contents")
27
+ options.colors = true
28
+ options.merge_config = nil
29
+ options.verbose = false
30
+ options.warnings = true
31
+ options.open_pdf = true
32
+
33
+ lookup_and_execute_require_option(args)
34
+
35
+ opts = ::OptionParser.new do |opts|
36
+ opts.banner = "Usage: texas [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
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
+ # Boolean switch.
75
+ opts.on("-c", "--[no-]color", "Switch colors") do |v|
76
+ options.colors = v
77
+ end
78
+
79
+ # Boolean switch.
80
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
81
+ options.verbose = v
82
+ end
83
+
84
+ # Boolean switch.
85
+ opts.on("-w", "--[no-]warnings", "Switch warnings") do |v|
86
+ options.warnings = v
87
+ end
88
+
89
+ # No argument, shows at tail. This will print an options summary.
90
+ # Try it and see!
91
+ opts.on_tail("-h", "--help", "Show this message") do
92
+ puts opts
93
+ exit
94
+ end
95
+
96
+ # Another typical switch to print the version.
97
+ opts.on_tail("--version", "Show version") do
98
+ puts Texas::VERSION::STRING
99
+ exit
100
+ end
101
+ end
102
+
103
+ opts.parse!(args)
104
+
105
+ unless args.empty?
106
+ f = args.shift
107
+ options.contents_template = find_contents_file(f)
108
+ options.contents_dir = find_contents_dir(f)
109
+ end
110
+ if options.check_mandatory_arguments
111
+ check_mandatory! options
112
+ end
113
+ options
114
+ end
115
+
116
+ private
117
+
118
+ # This method can be overwritten by other libraries
119
+ # to parse additional options
120
+ def parse_additional_options(opts)
121
+ end
122
+
123
+ def lookup_and_execute_require_option(args)
124
+ args.each_with_index do |v, i|
125
+ if %w(-r --require).include?(v)
126
+ require args[i+1]
127
+ end
128
+ end
129
+ end
130
+
131
+ def check_mandatory!(options)
132
+ if options.work_dir.nil?
133
+ warn "texas: missing file operand\nTry `texas --help' for more information."
134
+ exit 1
135
+ end
136
+ if options.contents_template.nil?
137
+ warn "texas: could not find contents template\nTry `texas --help' for more information."
138
+ exit 1
139
+ end
140
+ end
141
+
142
+ def find_work_dir(start_dir = Dir.pwd)
143
+ results = Dir[File.join(start_dir, Texas.contents_subdir_name)]
144
+ if !results.empty?
145
+ start_dir
146
+ else
147
+ path = Pathname.new(start_dir)
148
+ if path.realpath.to_s == "/"
149
+ nil
150
+ else
151
+ find_work_dir File.join(start_dir, '..')
152
+ end
153
+ end
154
+ end
155
+
156
+ def find_contents_dir(file)
157
+ if Dir["#{file}*"].empty?
158
+ nil
159
+ else
160
+ File.dirname(file)
161
+ end
162
+ end
163
+
164
+ def find_contents_file(file)
165
+ file = file.gsub("#{Texas.contents_subdir_name}/", "")
166
+ glob = File.join(Texas.contents_subdir_name, "#{file}*")
167
+ if Dir[glob].empty?
168
+ nil
169
+ else
170
+ file
171
+ end
172
+ end
173
+ end
174
+
175
+ end
@@ -0,0 +1,71 @@
1
+ def verbose(&block)
2
+ if Texas.verbose
3
+ value = block.()
4
+ if value.is_a?(String)
5
+ puts value
6
+ else
7
+ pp value
8
+ end
9
+ end
10
+ end
11
+
12
+ def warning(&block)
13
+ if Texas.warnings
14
+ value = block.()
15
+ if value.is_a?(String)
16
+ puts "[WARNING]".yellow + " #{value}"
17
+ else
18
+ pp value
19
+ end
20
+ end
21
+ end
22
+
23
+ module Texas
24
+ class Runner
25
+ attr_reader :task_instance
26
+
27
+ def initialize(force_options = nil)
28
+ @options = if force_options.nil?
29
+ Texas::OptionParser.new(ARGV).parse
30
+ else
31
+ opts = Texas::OptionParser.new([]).parse
32
+ force_options.each { |k, v| opts.send("#{k}=", v) }
33
+ opts
34
+ end
35
+ extend_string_class
36
+ Texas.verbose = @options.verbose
37
+ Texas.warnings = @options.warnings
38
+ load_local_libs if @options.load_local_libs
39
+ @task_instance = task_class.new(@options)
40
+ @task_instance.run
41
+ end
42
+
43
+ def extend_string_class
44
+ mod = @options.colors ? Term::ANSIColor : Term::NoColor
45
+ String.send :include, mod
46
+ end
47
+
48
+ def load_local_libs
49
+ init_file = File.join(@options.work_dir, "lib", "init.rb")
50
+ require init_file if File.exist?(init_file)
51
+ end
52
+
53
+ def task_class
54
+ map = {
55
+ :build => Build::Final,
56
+ :dry => Build::Dry,
57
+ }
58
+ map[@options.task] || fallback_task_class
59
+ end
60
+
61
+ def fallback_task_class
62
+ class_name = @options.task.to_s.capitalize
63
+ begin
64
+ eval("::Texas::Task::#{class_name}")
65
+ rescue
66
+ puts "Failed to fallback for ::Task::#{class_name}"
67
+ exit
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,23 @@
1
+ module Texas
2
+ module Task
3
+ class Base
4
+ attr_accessor :options
5
+
6
+ def initialize(_options, _build = nil)
7
+ self.options = _options
8
+ @build = _build if _build
9
+ end
10
+
11
+ def build(klass = Build::Dry)
12
+ @build ||= klass.run(options)
13
+ end
14
+
15
+ def track
16
+ build.track
17
+ end
18
+
19
+ def run
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ module Texas
2
+ module Task
3
+ class New < Base
4
+
5
+ def source_dir
6
+ File.join(Texas.texas_dir, "spec", "fixtures", "new")
7
+ end
8
+
9
+ def dest_dir
10
+ File.join(Dir.pwd, options.new_project_name)
11
+ end
12
+
13
+ def run
14
+ FileUtils.cp_r source_dir, dest_dir
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ require 'listen'
2
+
3
+ module Texas
4
+ module Task
5
+ class Watch < Base
6
+ class << self
7
+ attr_accessor :run_options
8
+ end
9
+
10
+ def run
11
+ self.class.run_options = options
12
+ dirs = Task::Watch.directories_to_watch
13
+ Listen.to(*dirs) do |modified, added, removed|
14
+ Task::Watch.rebuild
15
+ end
16
+ end
17
+
18
+ def self.directories_to_watch
19
+ arr = []
20
+ arr << "tex"
21
+ arr << "figures"
22
+ arr << Texas.texas_dir
23
+ arr
24
+ end
25
+
26
+ def self.rebuild
27
+ started_at = Time.now.to_i
28
+ @build = Build::Final.new(run_options)
29
+ @build.run
30
+ finished_at = Time.now.to_i
31
+ puts (finished_at - started_at).to_s + " seconds to rebuild"
32
+ rescue Exception => e
33
+ puts @build.current_template.filename
34
+ puts "[ERROR] while building \n#{e}"
35
+ end
36
+
37
+ end
38
+ end
39
+ end
data/lib/texas/task.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Texas
2
+ module Task
3
+ end
4
+ end
5
+
6
+ require_relative 'task/base'
7
+
8
+ all_rbs = Dir[ File.join( File.dirname(__FILE__), "task", "*.rb" ) ]
9
+ all_rbs.each do |t|
10
+ require t
11
+ end
@@ -0,0 +1,82 @@
1
+ # encoding: UTF-8
2
+ module Texas
3
+ module Template
4
+ module Helper
5
+ #
6
+ # Basic helper methods for finding files and template handling
7
+ #
8
+ module Base
9
+
10
+ def default_search_paths
11
+ [
12
+ __path__,
13
+ path_with_templates_basename,
14
+ build_path,
15
+ build.root
16
+ ].compact
17
+ end
18
+
19
+ def path_with_templates_basename
20
+ subdir = Template.basename @output_filename
21
+ File.directory?(subdir) ? subdir : nil
22
+ end
23
+
24
+ # Searches for the given file in +possible_paths+, also checking for +possible_exts+ as extensions
25
+ #
26
+ # Example:
27
+ # find_template_file(["figures", "titel"], [:pdf, :png])
28
+ # # => will check
29
+ # figures/titel.pdf
30
+ # figures/titel.png
31
+ # tmp/figures/titel.pdf
32
+ # tmp/figures/titel.png
33
+ #
34
+ def find_template_file(parts, possible_exts = [], possible_paths = default_search_paths)
35
+ possible_paths.each do |base|
36
+ ([""] + possible_exts).each do |ext|
37
+ path = parts.clone.map(&:to_s).map(&:dup)
38
+ path.unshift base.to_s
39
+ path.last << ".#{ext}" unless ext.empty?
40
+ filename = File.join(*path)
41
+ return filename if File.exist?(filename) && !File.directory?(filename)
42
+ end
43
+ end
44
+ nil
45
+ end
46
+
47
+ # Searches for the given file and raises an error if it is not found anywhere
48
+ #
49
+ def find_template_file!(parts, possible_exts = [], possible_paths = default_search_paths)
50
+ if filename = find_template_file(parts, possible_exts, possible_paths)
51
+ filename
52
+ else
53
+ raise "File doesnot exists anywhere: #{parts.inspect}#{possible_exts.inspect} in #{possible_paths.inspect} #{}"
54
+ end
55
+ end
56
+
57
+ def partial(name, locals = {})
58
+ render("_#{name}", locals)
59
+ end
60
+
61
+ def render(name, locals = {})
62
+ template_file = find_template_file!([name], template_extensions)
63
+ Template.create(template_file, build).__run__(locals)
64
+ end
65
+
66
+ # Returns all extensions the Template::Runner can handle.
67
+ def template_extensions
68
+ Template.known_extensions
69
+ end
70
+
71
+ def templates_by_glob(glob = "*")
72
+ files = Dir[File.join(__path__, glob)]
73
+ templates = files.map do |f|
74
+ Template.basename(f).gsub(__path__, '')
75
+ end
76
+ templates.uniq.sort
77
+ end
78
+
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ module Texas
3
+ module Template
4
+ module Helper
5
+ #
6
+ # Helper methods for describing templates via an info object
7
+ #
8
+ module Info
9
+
10
+ def info
11
+ @info ||= OpenStruct.new(:abstract => "", :summary => "")
12
+ end
13
+
14
+ def abstract
15
+ info.abstract.strip
16
+ end
17
+
18
+ def summary
19
+ info.summary.strip
20
+ end
21
+
22
+ def marked_for_rewrite?
23
+ !!info.write_at_end_of_build
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+ module Texas
3
+ module Template
4
+ module Helper
5
+ module Markdown
6
+
7
+ def chapter(opts = {})
8
+ if glob = opts[:glob]
9
+ opts[:templates] = templates_by_glob(glob)
10
+ end
11
+ store.__chapters__ ||= []
12
+ store.__chapters__ << opts
13
+ partial(:chapter, opts)
14
+ end
15
+
16
+ def center(str)
17
+ "\\begin{center}#{str}\\end{center}"
18
+ end
19
+
20
+ def gray(text)
21
+ "\\textcolor{gray}{#{text}}"
22
+ end
23
+
24
+ def page_break
25
+ "\\clearpage"
26
+ end
27
+
28
+ def scene_delimiter
29
+ center gray("* * *")
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,83 @@
1
+ # encoding: UTF-8
2
+ module Texas
3
+ module Template
4
+ module Helper
5
+ module TeX
6
+
7
+ # Converts all URLs in a text in \url TeX commands
8
+ #
9
+ def auto_link(text)
10
+ text.to_s.gsub(/(https*\:\/\/\S+)/, '\url{\1}')
11
+ end
12
+
13
+ def bold(text)
14
+ tex :textbf, text
15
+ end
16
+ alias b bold
17
+
18
+ def h1(*args); tex(:section, *args); end
19
+ def h2(*args); tex(:subsection, *args); end
20
+ def h3(*args); tex(:subsubsection, *args); end
21
+ def h4(text); '\paragraph{'+text+'} ~\\'; end
22
+
23
+ def italic(text)
24
+ tex :emph, text
25
+ end
26
+ alias i italic
27
+
28
+ def input(*path)
29
+ write_template_for_input(path)
30
+ tex :input, relative_template_basename(path)
31
+ end
32
+
33
+ def input!(*path)
34
+ write_template_for_input(path)
35
+ tex :include, relative_template_basename(path)
36
+ end
37
+
38
+ def linebreak
39
+ "\\\\"
40
+ end
41
+ alias br linebreak
42
+
43
+ def quote(string)
44
+ "\"`#{string}\"'"
45
+ end
46
+
47
+ def write_template_for_input(path)
48
+ filename = find_template_file!(path, template_extensions)
49
+ template = Template.create(filename, build)
50
+ template.write
51
+ end
52
+
53
+ private
54
+
55
+ # Returns a path relative to the build_path
56
+ #
57
+ # Example:
58
+ # input_path("/home/rene/github/sample_project/tmp/build/contents.tex.erb")
59
+ # # => "contents.tex.erb"
60
+ #
61
+ def relative_template_filename(path, possible_exts = Template.known_extensions)
62
+ filename = find_template_file!(path, possible_exts)
63
+ filename.gsub(build_path+'/', '')
64
+ end
65
+
66
+ # Returns a path relative to the build_path and strips the template extension
67
+ #
68
+ # Example:
69
+ # input_path("/home/rene/github/sample_project/tmp/build/contents.tex.erb")
70
+ # # => "contents"
71
+ #
72
+ def relative_template_basename(path)
73
+ Template.basename relative_template_filename(path)
74
+ end
75
+
76
+ def tex(command, text)
77
+ "\\#{command}{#{text}}"
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,6 @@
1
+ module Texas
2
+ module Template
3
+ module Helper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,70 @@
1
+ require 'texas/template/helper/base'
2
+ require 'texas/template/helper/info'
3
+ require 'erb'
4
+
5
+ module Texas
6
+ class Template::Runner::Base
7
+ include Texas::Template::Helper::Base
8
+ include Texas::Template::Helper::Info
9
+
10
+ attr_accessor :build, :content, :filename
11
+
12
+ def initialize(_filename, _build)
13
+ self.filename = _filename
14
+ self.build = _build
15
+ self.content = File.read(filename)
16
+ @output_filename = filename.gsub(/(\.erb)$/, '')
17
+ end
18
+
19
+ # TODO: Use Forwardable
20
+ def root; build.root; end
21
+
22
+ def build_path
23
+ build.__path__
24
+ end
25
+
26
+ def __path__
27
+ File.dirname filename
28
+ end
29
+
30
+ def document
31
+ build.document_struct
32
+ end
33
+
34
+ def store
35
+ build.store
36
+ end
37
+
38
+ def o
39
+ @locals
40
+ end
41
+
42
+ def append_to_output(str)
43
+ @erbout << str
44
+ end
45
+
46
+ def __render__(locals = {})
47
+ @locals = OpenStruct.new(locals)
48
+ ERB.new(@content, nil, nil, "@erbout").result(binding)
49
+ end
50
+
51
+ def __run__(locals = {})
52
+ verbose { "[T] #{filename.gsub(build_path, '')}".dark }
53
+
54
+ old_current_template = build.current_template
55
+ build.current_template = self
56
+ @output = after_render __render__(locals)
57
+ build.current_template = old_current_template
58
+ @output
59
+ end
60
+
61
+ def after_write; end
62
+ def after_render(str); str; end
63
+
64
+ def write
65
+ __run__
66
+ File.open(@output_filename, 'w') {|f| f.write(@output) }
67
+ after_write
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,16 @@
1
+ require 'texas/template/helper/md'
2
+
3
+ class Texas::Template::Runner::Markdown < Texas::Template::Runner::Base
4
+ include Texas::Template::Helper::Markdown
5
+
6
+ def after_write
7
+ if `which pandoc`.empty?
8
+ puts "\nAborting build: pandoc not found in PATH (required for Markdown rendering)"
9
+ exit
10
+ end
11
+ tex_filename = Texas::Template.basename(@output_filename) + ".tex"
12
+ `pandoc -S "#{@output_filename}" -o "#{tex_filename}"`
13
+ end
14
+ end
15
+
16
+ Texas::Template.register_handler %w(md md.erb), Texas::Template::Runner::Markdown
@@ -0,0 +1,11 @@
1
+ require 'texas/template/helper/tex'
2
+
3
+ class Texas::Template::Runner::TeX < Texas::Template::Runner::Base
4
+ include Texas::Template::Helper::TeX
5
+
6
+ def after_render(output)
7
+ output.gsub(/^%(.+)$/, '')
8
+ end
9
+ end
10
+
11
+ Texas::Template.register_handler %w(tex tex.erb), Texas::Template::Runner::TeX
@@ -0,0 +1,13 @@
1
+ module Texas
2
+ module Template
3
+ module Runner
4
+ end
5
+ end
6
+ end
7
+
8
+ require_relative 'runner/base'
9
+
10
+ all_rbs = Dir[ File.join( File.dirname(__FILE__), "runner", "*.rb" ) ]
11
+ all_rbs.each do |t|
12
+ require t
13
+ end