tilt 1.4.1 → 2.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +1 -1
  3. data/bin/tilt +18 -8
  4. data/lib/tilt/asciidoc.rb +1 -8
  5. data/lib/tilt/babel.rb +16 -0
  6. data/lib/tilt/bluecloth.rb +24 -0
  7. data/lib/tilt/builder.rb +12 -15
  8. data/lib/tilt/coffee.rb +10 -6
  9. data/lib/tilt/commonmarker.rb +88 -0
  10. data/lib/tilt/creole.rb +25 -0
  11. data/lib/tilt/csv.rb +12 -18
  12. data/lib/tilt/dummy.rb +3 -0
  13. data/lib/tilt/erb.rb +9 -56
  14. data/lib/tilt/erubi.rb +32 -0
  15. data/lib/tilt/erubis.rb +43 -0
  16. data/lib/tilt/haml.rb +66 -44
  17. data/lib/tilt/kramdown.rb +25 -0
  18. data/lib/tilt/less.rb +30 -0
  19. data/lib/tilt/liquid.rb +9 -10
  20. data/lib/tilt/livescript.rb +23 -0
  21. data/lib/tilt/mapping.rb +293 -0
  22. data/lib/tilt/markaby.rb +1 -8
  23. data/lib/tilt/maruku.rb +22 -0
  24. data/lib/tilt/nokogiri.rb +1 -8
  25. data/lib/tilt/pandoc.rb +57 -0
  26. data/lib/tilt/plain.rb +0 -4
  27. data/lib/tilt/prawn.rb +43 -0
  28. data/lib/tilt/radius.rb +1 -8
  29. data/lib/tilt/rdiscount.rb +39 -0
  30. data/lib/tilt/rdoc.rb +3 -10
  31. data/lib/tilt/redcarpet.rb +86 -0
  32. data/lib/tilt/{textile.rb → redcloth.rb} +1 -8
  33. data/lib/tilt/rst-pandoc.rb +23 -0
  34. data/lib/tilt/sass.rb +78 -0
  35. data/lib/tilt/sigil.rb +34 -0
  36. data/lib/tilt/string.rb +1 -1
  37. data/lib/tilt/template.rb +121 -105
  38. data/lib/tilt/typescript.rb +26 -0
  39. data/lib/tilt/wikicloth.rb +22 -0
  40. data/lib/tilt/yajl.rb +1 -8
  41. data/lib/tilt.rb +118 -155
  42. metadata +38 -469
  43. data/CHANGELOG.md +0 -44
  44. data/Gemfile +0 -32
  45. data/HACKING +0 -16
  46. data/README.md +0 -232
  47. data/Rakefile +0 -104
  48. data/TEMPLATES.md +0 -516
  49. data/lib/tilt/css.rb +0 -80
  50. data/lib/tilt/markdown.rb +0 -214
  51. data/lib/tilt/wiki.rb +0 -58
  52. data/test/contest.rb +0 -68
  53. data/test/markaby/locals.mab +0 -1
  54. data/test/markaby/markaby.mab +0 -1
  55. data/test/markaby/markaby_other_static.mab +0 -1
  56. data/test/markaby/render_twice.mab +0 -1
  57. data/test/markaby/scope.mab +0 -1
  58. data/test/markaby/yielding.mab +0 -2
  59. data/test/tilt_asciidoctor_test.rb +0 -44
  60. data/test/tilt_blueclothtemplate_test.rb +0 -45
  61. data/test/tilt_buildertemplate_test.rb +0 -59
  62. data/test/tilt_cache_test.rb +0 -32
  63. data/test/tilt_coffeescripttemplate_test.rb +0 -114
  64. data/test/tilt_compilesite_test.rb +0 -51
  65. data/test/tilt_creoletemplate_test.rb +0 -28
  66. data/test/tilt_csv_test.rb +0 -69
  67. data/test/tilt_erbtemplate_test.rb +0 -239
  68. data/test/tilt_erubistemplate_test.rb +0 -151
  69. data/test/tilt_etannitemplate_test.rb +0 -173
  70. data/test/tilt_fallback_test.rb +0 -122
  71. data/test/tilt_hamltemplate_test.rb +0 -144
  72. data/test/tilt_kramdown_test.rb +0 -42
  73. data/test/tilt_lesstemplate_test.less +0 -1
  74. data/test/tilt_lesstemplate_test.rb +0 -42
  75. data/test/tilt_liquidtemplate_test.rb +0 -78
  76. data/test/tilt_markaby_test.rb +0 -88
  77. data/test/tilt_markdown_test.rb +0 -172
  78. data/test/tilt_marukutemplate_test.rb +0 -48
  79. data/test/tilt_nokogiritemplate_test.rb +0 -87
  80. data/test/tilt_radiustemplate_test.rb +0 -75
  81. data/test/tilt_rdiscounttemplate_test.rb +0 -55
  82. data/test/tilt_rdoctemplate_test.rb +0 -31
  83. data/test/tilt_redcarpettemplate_test.rb +0 -71
  84. data/test/tilt_redclothtemplate_test.rb +0 -36
  85. data/test/tilt_sasstemplate_test.rb +0 -41
  86. data/test/tilt_stringtemplate_test.rb +0 -170
  87. data/test/tilt_template_test.rb +0 -323
  88. data/test/tilt_test.rb +0 -65
  89. data/test/tilt_wikiclothtemplate_test.rb +0 -32
  90. data/test/tilt_yajltemplate_test.rb +0 -101
  91. data/tilt.gemspec +0 -120
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a552c8551a7093b787234c00bac7ccaaef77e89b1d4835c31ddbaeb8388c74ae
4
+ data.tar.gz: 014cff88cd5ec4157d02127576eb788a6b0ae3795e69dc448781093f59153769
5
+ SHA512:
6
+ metadata.gz: 9d9da743f0359f10e8486b946132d39ba892482a99e7961c4a62258a680a214030824e92442db2421f35cac7c4378ff3e8e8e0af72bd8af35150aae2cc58555b
7
+ data.tar.gz: 2755a44a43e094eb95bffe6ab095f4d8a6cc1b58d1c96d6c20325d8d607ada32da7529758dfed8f8d8f09a3eafe2c7d96f381c314c7cc99f950a36c5eaff3454
data/COPYING CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Ryan Tomayko <http://tomayko.com/about>
1
+ Copyright (c) 2010-2016 Ryan Tomayko <http://tomayko.com/about>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to
data/bin/tilt CHANGED
@@ -10,14 +10,15 @@ when <file> is '-', read template from stdin and use the --type option
10
10
  to determine the template's type.
11
11
 
12
12
  Options
13
- -l, --list List template engines + file patterns and exit
14
- -t, --type=<pattern> Use this template engine; required if no <file>
15
- -y, --layout=<file> Use <file> as a layout template
13
+ -l, --list List template engines + file patterns and exit
14
+ -t, --type=<pattern> Use this template engine; required if no <file>
15
+ -y, --layout=<file> Use <file> as a layout template
16
16
 
17
- -D<name>=<value> Define variable <name> as <value>
18
- --vars=<ruby> Evaluate <ruby> to Hash and use for variables
17
+ -D<name>=<value> Define variable <name> as <value>
18
+ -d, --define-file=<file> Load YAML from <file> and use for variables
19
+ --vars=<ruby> Evaluate <ruby> to Hash and use for variables
19
20
 
20
- -h, --help Show this help message
21
+ -h, --help Show this help message
21
22
 
22
23
  Convert markdown to HTML:
23
24
  $ tilt foo.markdown > foo.html
@@ -44,9 +45,9 @@ ARGV.options do |o|
44
45
  # list all available template engines
45
46
  o.on("-l", "--list") do
46
47
  groups = {}
47
- Tilt.mappings.each do |pattern,engines|
48
+ Tilt.lazy_map.each do |pattern,engines|
48
49
  engines.each do |engine|
49
- key = engine.name.split('::').last.sub(/Template$/, '')
50
+ key = engine[0].split('::').last.sub(/Template$/, '')
50
51
  (groups[key] ||= []) << pattern
51
52
  end
52
53
  end
@@ -77,6 +78,15 @@ ARGV.options do |o|
77
78
  locals[key.to_sym] = value
78
79
  end
79
80
 
81
+ # define local variables from YAML or JSON
82
+ o.on("-d", "--define-file=FILE", String) do |file|
83
+ require 'yaml'
84
+ abort "no such define file: #{file}" unless File.exist? file
85
+ hash = File.open(file, 'r:bom|utf-8') { |f| YAML.load f, file }
86
+ abort "vars must be a Hash, not #{hash.inspect}" if !hash.is_a?(Hash)
87
+ hash.each { |key, value| locals[key.to_sym] = value }
88
+ end
89
+
80
90
  # define local variables using a Ruby hash
81
91
  o.on("--vars=RUBY") do |ruby|
82
92
  hash = eval(ruby)
data/lib/tilt/asciidoc.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'tilt/template'
2
+ require 'asciidoctor'
2
3
 
3
4
  # AsciiDoc see: http://asciidoc.org/
4
5
  module Tilt
@@ -11,14 +12,6 @@ module Tilt
11
12
  class AsciidoctorTemplate < Template
12
13
  self.default_mime_type = 'text/html'
13
14
 
14
- def self.engine_initialized?
15
- defined? ::Asciidoctor::Document
16
- end
17
-
18
- def initialize_engine
19
- require_template_library 'asciidoctor'
20
- end
21
-
22
15
  def prepare
23
16
  options[:header_footer] = false if options[:header_footer].nil?
24
17
  end
data/lib/tilt/babel.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'tilt/template'
2
+ require 'babel/transpiler'
3
+
4
+ module Tilt
5
+ class BabelTemplate < Template
6
+ self.default_mime_type = 'application/javascript'
7
+
8
+ def prepare
9
+ options[:filename] ||= file
10
+ end
11
+
12
+ def evaluate(scope, locals, &block)
13
+ @output ||= Babel::Transpiler.transform(data)["code"]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ require 'tilt/template'
2
+ require 'bluecloth'
3
+
4
+ module Tilt
5
+ # BlueCloth Markdown implementation. See:
6
+ # http://deveiate.org/projects/BlueCloth/
7
+ class BlueClothTemplate < Template
8
+ self.default_mime_type = 'text/html'
9
+
10
+ def prepare
11
+ @engine = BlueCloth.new(data, options)
12
+ @output = nil
13
+ end
14
+
15
+ def evaluate(scope, locals, &block)
16
+ @output ||= @engine.to_html
17
+ end
18
+
19
+ def allows_script?
20
+ false
21
+ end
22
+ end
23
+ end
24
+
data/lib/tilt/builder.rb CHANGED
@@ -1,33 +1,30 @@
1
1
  require 'tilt/template'
2
+ require 'builder'
2
3
 
3
4
  module Tilt
4
- # Builder template implementation. See:
5
+ # Builder template implementation. See:
5
6
  # http://builder.rubyforge.org/
6
7
  class BuilderTemplate < Template
7
8
  self.default_mime_type = 'text/xml'
8
9
 
9
- def self.engine_initialized?
10
- defined? ::Builder
10
+ def prepare
11
+ options[:indent] ||= 2
11
12
  end
12
13
 
13
- def initialize_engine
14
- require_template_library 'builder'
15
- end
14
+ def evaluate(scope, locals, &block)
15
+ xml = (locals[:xml] || ::Builder::XmlMarkup.new(options))
16
16
 
17
- def prepare; end
17
+ if data.respond_to?(:to_str)
18
+ if !locals[:xml]
19
+ locals = locals.merge(:xml => xml)
20
+ end
21
+ return super(scope, locals, &block)
22
+ end
18
23
 
19
- def evaluate(scope, locals, &block)
20
- return super(scope, locals, &block) if data.respond_to?(:to_str)
21
- xml = ::Builder::XmlMarkup.new(:indent => 2)
22
24
  data.call(xml)
23
25
  xml.target!
24
26
  end
25
27
 
26
- def precompiled_preamble(locals)
27
- return super if locals.include? :xml
28
- "xml = ::Builder::XmlMarkup.new(:indent => 2)\n#{super}"
29
- end
30
-
31
28
  def precompiled_postamble(locals)
32
29
  "xml.target!"
33
30
  end
data/lib/tilt/coffee.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'tilt/template'
2
+ require 'coffee_script'
2
3
 
3
4
  module Tilt
4
5
  # CoffeeScript template implementation. See:
@@ -28,18 +29,15 @@ module Tilt
28
29
  @@default_bare = value
29
30
  end
30
31
 
31
- def self.engine_initialized?
32
- defined? ::CoffeeScript
33
- end
34
-
35
- def initialize_engine
36
- require_template_library 'coffee_script'
32
+ def self.literate?
33
+ false
37
34
  end
38
35
 
39
36
  def prepare
40
37
  if !options.key?(:bare) and !options.key?(:no_wrap)
41
38
  options[:bare] = self.class.default_bare
42
39
  end
40
+ options[:literate] ||= self.class.literate?
43
41
  end
44
42
 
45
43
  def evaluate(scope, locals, &block)
@@ -50,5 +48,11 @@ module Tilt
50
48
  false
51
49
  end
52
50
  end
51
+
52
+ class CoffeeScriptLiterateTemplate < CoffeeScriptTemplate
53
+ def self.literate?
54
+ true
55
+ end
56
+ end
53
57
  end
54
58
 
@@ -0,0 +1,88 @@
1
+ require 'tilt/template'
2
+ require 'commonmarker'
3
+
4
+ module Tilt
5
+ class CommonMarkerTemplate < Template
6
+ self.default_mime_type = 'text/html'
7
+
8
+ OPTION_ALIAS = {
9
+ :smartypants => :SMART
10
+ }
11
+ PARSE_OPTIONS = [
12
+ :FOOTNOTES,
13
+ :LIBERAL_HTML_TAG,
14
+ :SMART,
15
+ :smartypants,
16
+ :STRIKETHROUGH_DOUBLE_TILDE,
17
+ :UNSAFE,
18
+ :VALIDATE_UTF8,
19
+ ].freeze
20
+ RENDER_OPTIONS = [
21
+ :FOOTNOTES,
22
+ :FULL_INFO_STRING,
23
+ :GITHUB_PRE_LANG,
24
+ :HARDBREAKS,
25
+ :NOBREAKS,
26
+ :SAFE, # Removed in v0.18.0 (2018-10-17)
27
+ :SOURCEPOS,
28
+ :TABLE_PREFER_STYLE_ATTRIBUTES,
29
+ :UNSAFE,
30
+ ].freeze
31
+ EXTENSIONS = [
32
+ :autolink,
33
+ :strikethrough,
34
+ :table,
35
+ :tagfilter,
36
+ :tasklist,
37
+ ].freeze
38
+
39
+ def extensions
40
+ EXTENSIONS.select do |extension|
41
+ options[extension]
42
+ end
43
+ end
44
+
45
+ def parse_options
46
+ raw_options = PARSE_OPTIONS.select do |option|
47
+ options[option]
48
+ end
49
+ actual_options = raw_options.map do |option|
50
+ OPTION_ALIAS[option] || option
51
+ end
52
+
53
+ if actual_options.any?
54
+ actual_options
55
+ else
56
+ :DEFAULT
57
+ end
58
+ end
59
+
60
+ def render_options
61
+ raw_options = RENDER_OPTIONS.select do |option|
62
+ options[option]
63
+ end
64
+ actual_options = raw_options.map do |option|
65
+ OPTION_ALIAS[option] || option
66
+ end
67
+ if actual_options.any?
68
+ actual_options
69
+ else
70
+ :DEFAULT
71
+ end
72
+ end
73
+
74
+ def prepare
75
+ @engine = nil
76
+ @output = nil
77
+ end
78
+
79
+ def evaluate(scope, locals, &block)
80
+ doc = CommonMarker.render_doc(data, parse_options, extensions)
81
+ doc.to_html(render_options, extensions)
82
+ end
83
+
84
+ def allows_script?
85
+ false
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,25 @@
1
+ require 'tilt/template'
2
+ require 'creole'
3
+
4
+ module Tilt
5
+ # Creole implementation. See:
6
+ # http://www.wikicreole.org/
7
+ class CreoleTemplate < Template
8
+ def prepare
9
+ opts = {}
10
+ [:allowed_schemes, :extensions, :no_escape].each do |k|
11
+ opts[k] = options[k] if options[k]
12
+ end
13
+ @engine = Creole::Parser.new(data, opts)
14
+ @output = nil
15
+ end
16
+
17
+ def evaluate(scope, locals, &block)
18
+ @output ||= @engine.to_html
19
+ end
20
+
21
+ def allows_script?
22
+ false
23
+ end
24
+ end
25
+ end
data/lib/tilt/csv.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  require 'tilt/template'
2
2
 
3
+ if RUBY_VERSION >= '1.9.0'
4
+ require 'csv'
5
+ else
6
+ require 'fastercsv'
7
+ end
8
+
3
9
  module Tilt
4
10
 
5
11
  # CSV Template implementation. See:
@@ -30,10 +36,6 @@ module Tilt
30
36
  class CSVTemplate < Template
31
37
  self.default_mime_type = 'text/csv'
32
38
 
33
- def self.engine_initialized?
34
- engine
35
- end
36
-
37
39
  def self.engine
38
40
  if RUBY_VERSION >= '1.9.0' && defined? ::CSV
39
41
  ::CSV
@@ -42,30 +44,22 @@ module Tilt
42
44
  end
43
45
  end
44
46
 
45
- def initialize_engine
46
- if RUBY_VERSION >= '1.9.0'
47
- require_template_library 'csv'
48
- else
49
- require_template_library 'fastercsv'
50
- end
47
+ def prepare
48
+ @outvar = options.delete(:outvar) || '_csvout'
51
49
  end
52
50
 
53
- def prepare
54
- @code =<<-RUBY
55
- #{self.class.engine}.generate do |csv|
51
+ def precompiled_template(locals)
52
+ <<-RUBY
53
+ #{@outvar} = #{self.class.engine}.generate(**#{options}) do |csv|
56
54
  #{data}
57
55
  end
58
56
  RUBY
59
57
  end
60
58
 
61
- def precompiled_template(locals)
62
- @code
63
- end
64
-
65
59
  def precompiled(locals)
66
60
  source, offset = super
67
61
  [source, offset + 1]
68
62
  end
69
63
 
70
64
  end
71
- end
65
+ end
data/lib/tilt/dummy.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Used for detecting autoloading bug in JRuby
2
+ class Tilt::Dummy; end
3
+
data/lib/tilt/erb.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'tilt/template'
2
+ require 'erb'
2
3
 
3
4
  module Tilt
4
5
  # ERB template implementation. See:
@@ -6,26 +7,25 @@ module Tilt
6
7
  class ERBTemplate < Template
7
8
  @@default_output_variable = '_erbout'
8
9
 
10
+ SUPPORTS_KVARGS = ::ERB.instance_method(:initialize).parameters.assoc(:key) rescue false
11
+
9
12
  def self.default_output_variable
10
13
  @@default_output_variable
11
14
  end
12
15
 
13
16
  def self.default_output_variable=(name)
17
+ warn "#{self}.default_output_variable= has been replaced with the :outvar-option"
14
18
  @@default_output_variable = name
15
19
  end
16
20
 
17
- def self.engine_initialized?
18
- defined? ::ERB
19
- end
20
-
21
- def initialize_engine
22
- require_template_library 'erb'
23
- end
24
-
25
21
  def prepare
26
22
  @outvar = options[:outvar] || self.class.default_output_variable
27
23
  options[:trim] = '<>' if !(options[:trim] == false) && (options[:trim].nil? || options[:trim] == true)
28
- @engine = ::ERB.new(data, options[:safe], options[:trim], @outvar)
24
+ @engine = if SUPPORTS_KVARGS
25
+ ::ERB.new(data, trim_mode: options[:trim], eoutvar: @outvar)
26
+ else
27
+ ::ERB.new(data, options[:safe], options[:trim], @outvar)
28
+ end
29
29
  end
30
30
 
31
31
  def precompiled_template(locals)
@@ -59,52 +59,5 @@ module Tilt
59
59
  end
60
60
  end
61
61
  end
62
-
63
- # Erubis template implementation. See:
64
- # http://www.kuwata-lab.com/erubis/
65
- #
66
- # ErubisTemplate supports the following additional options, which are not
67
- # passed down to the Erubis engine:
68
- #
69
- # :engine_class allows you to specify a custom engine class to use
70
- # instead of the default (which is ::Erubis::Eruby).
71
- #
72
- # :escape_html when true, ::Erubis::EscapedEruby will be used as
73
- # the engine class instead of the default. All content
74
- # within <%= %> blocks will be automatically html escaped.
75
- class ErubisTemplate < ERBTemplate
76
- def self.engine_initialized?
77
- defined? ::Erubis::Eruby
78
- end
79
-
80
- def initialize_engine
81
- require_template_library 'erubis'
82
- end
83
-
84
- def prepare
85
- @outvar = options.delete(:outvar) || self.class.default_output_variable
86
- @options.merge!(:preamble => false, :postamble => false, :bufvar => @outvar)
87
- engine_class = options.delete(:engine_class)
88
- engine_class = ::Erubis::EscapedEruby if options.delete(:escape_html)
89
- @engine = (engine_class || ::Erubis::Eruby).new(data, options)
90
- end
91
-
92
- def precompiled_preamble(locals)
93
- [super, "#{@outvar} = _buf = ''"].join("\n")
94
- end
95
-
96
- def precompiled_postamble(locals)
97
- [@outvar, super].join("\n")
98
- end
99
-
100
- # Erubis doesn't have ERB's line-off-by-one under 1.9 problem.
101
- # Override and adjust back.
102
- if RUBY_VERSION >= '1.9.0'
103
- def precompiled(locals)
104
- source, offset = super
105
- [source, offset - 1]
106
- end
107
- end
108
- end
109
62
  end
110
63
 
data/lib/tilt/erubi.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'tilt/template'
2
+ require 'erubi'
3
+
4
+ module Tilt
5
+ # Erubi (a simplified version of Erubis) template implementation.
6
+ # See https://github.com/jeremyevans/erubi
7
+ #
8
+ # ErubiTemplate supports the following additional options, in addition
9
+ # to the options supported by the Erubi engine:
10
+ #
11
+ # :engine_class :: allows you to specify a custom engine class to use
12
+ # instead of the default (which is ::Erubi::Engine).
13
+ class ErubiTemplate < Template
14
+ def prepare
15
+ @options.merge!(:preamble => false, :postamble => false, :ensure=>true)
16
+
17
+ engine_class = @options[:engine_class] || Erubi::Engine
18
+
19
+ @engine = engine_class.new(data, @options)
20
+ @outvar = @engine.bufvar
21
+
22
+ # Remove dup after tilt supports frozen source.
23
+ @src = @engine.src.dup
24
+
25
+ @engine
26
+ end
27
+
28
+ def precompiled_template(locals)
29
+ @src
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require 'tilt/erb'
2
+ require 'erubis'
3
+
4
+ module Tilt
5
+ # Erubis template implementation. See:
6
+ # http://www.kuwata-lab.com/erubis/
7
+ #
8
+ # ErubisTemplate supports the following additional options, which are not
9
+ # passed down to the Erubis engine:
10
+ #
11
+ # :engine_class allows you to specify a custom engine class to use
12
+ # instead of the default (which is ::Erubis::Eruby).
13
+ #
14
+ # :escape_html when true, ::Erubis::EscapedEruby will be used as
15
+ # the engine class instead of the default. All content
16
+ # within <%= %> blocks will be automatically html escaped.
17
+ class ErubisTemplate < ERBTemplate
18
+ def prepare
19
+ @outvar = options.delete(:outvar) || self.class.default_output_variable
20
+ @options.merge!(:preamble => false, :postamble => false, :bufvar => @outvar)
21
+ engine_class = options.delete(:engine_class)
22
+ engine_class = ::Erubis::EscapedEruby if options.delete(:escape_html)
23
+ @engine = (engine_class || ::Erubis::Eruby).new(data, options)
24
+ end
25
+
26
+ def precompiled_preamble(locals)
27
+ [super, "#{@outvar} = _buf = String.new"].join("\n")
28
+ end
29
+
30
+ def precompiled_postamble(locals)
31
+ [@outvar, super].join("\n")
32
+ end
33
+
34
+ # Erubis doesn't have ERB's line-off-by-one under 1.9 problem.
35
+ # Override and adjust back.
36
+ if RUBY_VERSION >= '1.9.0'
37
+ def precompiled(locals)
38
+ source, offset = super
39
+ [source, offset - 1]
40
+ end
41
+ end
42
+ end
43
+ end