tilt 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +17 -0
  3. data/Gemfile +33 -26
  4. data/README.md +23 -49
  5. data/Rakefile +21 -30
  6. data/{TEMPLATES.md → docs/TEMPLATES.md} +11 -4
  7. data/docs/common.css +14 -0
  8. data/lib/tilt/asciidoc.rb +1 -8
  9. data/lib/tilt/bluecloth.rb +24 -0
  10. data/lib/tilt/builder.rb +1 -8
  11. data/lib/tilt/coffee.rb +1 -8
  12. data/lib/tilt/creole.rb +25 -0
  13. data/lib/tilt/csv.rb +7 -13
  14. data/lib/tilt/erb.rb +2 -55
  15. data/lib/tilt/erubis.rb +43 -0
  16. data/lib/tilt/haml.rb +1 -8
  17. data/lib/tilt/kramdown.rb +33 -0
  18. data/lib/tilt/less.rb +38 -0
  19. data/lib/tilt/liquid.rb +1 -8
  20. data/lib/tilt/mapping.rb +265 -0
  21. data/lib/tilt/markaby.rb +1 -8
  22. data/lib/tilt/maruku.rb +22 -0
  23. data/lib/tilt/nokogiri.rb +1 -8
  24. data/lib/tilt/radius.rb +1 -8
  25. data/lib/tilt/rdiscount.rb +39 -0
  26. data/lib/tilt/rdoc.rb +3 -10
  27. data/lib/tilt/redcarpet.rb +104 -0
  28. data/lib/tilt/{textile.rb → redcloth.rb} +1 -8
  29. data/lib/tilt/sass.rb +41 -0
  30. data/lib/tilt/template.rb +88 -93
  31. data/lib/tilt/wikicloth.rb +22 -0
  32. data/lib/tilt/yajl.rb +1 -8
  33. data/lib/tilt.rb +87 -154
  34. data/test/{contest.rb → test_helper.rb} +7 -11
  35. data/test/tilt_asciidoctor_test.rb +6 -6
  36. data/test/tilt_blueclothtemplate_test.rb +3 -15
  37. data/test/tilt_buildertemplate_test.rb +3 -3
  38. data/test/tilt_cache_test.rb +2 -2
  39. data/test/tilt_coffeescripttemplate_test.rb +8 -18
  40. data/test/tilt_compilesite_test.rb +2 -2
  41. data/test/tilt_creoletemplate_test.rb +3 -7
  42. data/test/tilt_csv_test.rb +5 -9
  43. data/test/tilt_erbtemplate_test.rb +7 -7
  44. data/test/tilt_erubistemplate_test.rb +7 -7
  45. data/test/tilt_etannitemplate_test.rb +4 -3
  46. data/test/tilt_hamltemplate_test.rb +4 -4
  47. data/test/tilt_kramdown_test.rb +5 -27
  48. data/test/tilt_lesstemplate_test.rb +3 -3
  49. data/test/tilt_liquidtemplate_test.rb +3 -3
  50. data/test/tilt_mapping_test.rb +229 -0
  51. data/test/tilt_markaby_test.rb +4 -4
  52. data/test/tilt_markdown_test.rb +23 -21
  53. data/test/tilt_marukutemplate_test.rb +9 -21
  54. data/test/tilt_metadata_test.rb +42 -0
  55. data/test/tilt_nokogiritemplate_test.rb +3 -3
  56. data/test/tilt_radiustemplate_test.rb +3 -3
  57. data/test/tilt_rdiscounttemplate_test.rb +7 -19
  58. data/test/tilt_rdoctemplate_test.rb +3 -5
  59. data/test/tilt_redcarpettemplate_test.rb +11 -23
  60. data/test/tilt_redclothtemplate_test.rb +3 -3
  61. data/test/tilt_sasstemplate_test.rb +4 -4
  62. data/test/tilt_stringtemplate_test.rb +4 -3
  63. data/test/tilt_template_test.rb +42 -49
  64. data/test/tilt_test.rb +10 -15
  65. data/test/tilt_wikiclothtemplate_test.rb +3 -3
  66. data/test/tilt_yajltemplate_test.rb +3 -3
  67. data/tilt.gemspec +19 -32
  68. metadata +26 -385
  69. data/lib/tilt/css.rb +0 -80
  70. data/lib/tilt/markdown.rb +0 -214
  71. data/lib/tilt/wiki.rb +0 -58
  72. data/test/tilt_fallback_test.rb +0 -122
data/lib/tilt/template.rb CHANGED
@@ -1,5 +1,11 @@
1
+ require 'tilt'
2
+ require 'thread'
3
+
1
4
  module Tilt
5
+ # @private
2
6
  TOPOBJECT = Object.superclass || Object
7
+ # @private
8
+ LOCK = Mutex.new
3
9
 
4
10
  # Base class for template implementations. Subclasses must implement
5
11
  # the #prepare method and one of the #evaluate or #precompiled_template
@@ -19,14 +25,22 @@ module Tilt
19
25
  # interface.
20
26
  attr_reader :options
21
27
 
22
- # Used to determine if this class's initialize_engine method has
23
- # been called yet.
24
- @engine_initialized = false
25
28
  class << self
26
- attr_accessor :engine_initialized
27
- alias engine_initialized? engine_initialized
29
+ # An empty Hash that the template engine can populate with various
30
+ # metadata.
31
+ def metadata
32
+ @metadata ||= {}
33
+ end
28
34
 
29
- attr_accessor :default_mime_type
35
+ # @deprecated Use `.metadata[:mime_type]` instead.
36
+ def default_mime_type
37
+ metadata[:mime_type]
38
+ end
39
+
40
+ # @deprecated Use `.metadata[:mime_type] = val` instead.
41
+ def default_mime_type=(value)
42
+ metadata[:mime_type] = value
43
+ end
30
44
  end
31
45
 
32
46
  # Create a new template with the file, line, and options specified. By
@@ -44,19 +58,14 @@ module Tilt
44
58
  when arg.respond_to?(:to_int) ; @line = arg.to_int
45
59
  when arg.respond_to?(:to_hash) ; @options = arg.to_hash.dup
46
60
  when arg.respond_to?(:path) ; @file = arg.path
47
- else raise TypeError
61
+ when arg.respond_to?(:to_path) ; @file = arg.to_path
62
+ else raise TypeError, "Can't load the template file. Pass a string with a path " +
63
+ "or an object that responds to 'to_str', 'path' or 'to_path'"
48
64
  end
49
65
  end
50
66
 
51
67
  raise ArgumentError, "file or block required" if (@file || block).nil?
52
68
 
53
- # call the initialize_engine method if this is the very first time
54
- # an instance of this class has been created.
55
- if !self.class.engine_initialized?
56
- initialize_engine
57
- self.class.engine_initialized = true
58
- end
59
-
60
69
  # used to hold compiled template methods
61
70
  @compiled_method = {}
62
71
 
@@ -79,28 +88,15 @@ module Tilt
79
88
  prepare
80
89
  end
81
90
 
82
- # The encoding of the source data. Defaults to the
83
- # default_encoding-option if present. You may override this method
84
- # in your template class if you have a better hint of the data's
85
- # encoding.
86
- def default_encoding
87
- @default_encoding
88
- end
89
-
90
- def read_template_file
91
- data = File.open(file, 'rb') { |io| io.read }
92
- if data.respond_to?(:force_encoding)
93
- # Set it to the default external (without verifying)
94
- data.force_encoding(Encoding.default_external) if Encoding.default_external
95
- end
96
- data
97
- end
98
-
99
91
  # Render the template in the given scope with the locals specified. If a
100
92
  # block is given, it is typically available within the template via
101
93
  # +yield+.
102
94
  def render(scope=Object.new, locals={}, &block)
103
- evaluate scope, locals || {}, &block
95
+ current_template = Thread.current[:tilt_current_template]
96
+ Thread.current[:tilt_current_template] = self
97
+ evaluate(scope, locals || {}, &block)
98
+ ensure
99
+ Thread.current[:tilt_current_template] = current_template
104
100
  end
105
101
 
106
102
  # The basename of the template file.
@@ -118,30 +114,26 @@ module Tilt
118
114
  file || '(__TEMPLATE__)'
119
115
  end
120
116
 
121
- # Whether or not this template engine allows executing Ruby script
122
- # within the template. If this is false, +scope+ and +locals+ will
123
- # generally not be used, nor will the provided block be avaiable
124
- # via +yield+.
125
- # This should be overridden by template subclasses.
126
- def allows_script?
127
- true
117
+ # An empty Hash that the template engine can populate with various
118
+ # metadata.
119
+ def metadata
120
+ if respond_to?(:allows_script?)
121
+ self.class.metadata.merge(:allows_script => allows_script?)
122
+ else
123
+ self.class.metadata
124
+ end
128
125
  end
129
126
 
130
- protected
131
- # Called once and only once for each template subclass the first time
132
- # the template class is initialized. This should be used to require the
133
- # underlying template library and perform any initial setup.
134
- def initialize_engine
135
- end
127
+ protected
136
128
 
137
- # Like Kernel#require but issues a warning urging a manual require when
138
- # running under a threaded environment.
139
- def require_template_library(name)
140
- if Thread.list.size > 1
141
- warn "WARN: tilt autoloading '#{name}' in a non thread-safe way; " +
142
- "explicit require '#{name}' suggested."
143
- end
144
- require name
129
+ # @!group For template implementations
130
+
131
+ # The encoding of the source data. Defaults to the
132
+ # default_encoding-option if present. You may override this method
133
+ # in your template class if you have a better hint of the data's
134
+ # encoding.
135
+ def default_encoding
136
+ @default_encoding
145
137
  end
146
138
 
147
139
  # Do whatever preparation is necessary to setup the underlying template
@@ -150,13 +142,7 @@ module Tilt
150
142
  #
151
143
  # Subclasses must provide an implementation of this method.
152
144
  def prepare
153
- if respond_to?(:compile!)
154
- # backward compat with tilt < 0.6; just in case
155
- warn 'Tilt::Template#compile! is deprecated; implement #prepare instead.'
156
- compile!
157
- else
158
- raise NotImplementedError
159
- end
145
+ raise NotImplementedError
160
146
  end
161
147
 
162
148
  # Execute the compiled template and return the result string. Template
@@ -179,10 +165,10 @@ module Tilt
179
165
  # control over source generation or want to adjust the default line
180
166
  # offset. In most cases, overriding the #precompiled_template method is
181
167
  # easier and more appropriate.
182
- def precompiled(locals)
183
- preamble = precompiled_preamble(locals)
184
- template = precompiled_template(locals)
185
- postamble = precompiled_postamble(locals)
168
+ def precompiled(local_keys)
169
+ preamble = precompiled_preamble(local_keys)
170
+ template = precompiled_template(local_keys)
171
+ postamble = precompiled_postamble(local_keys)
186
172
  source = ''
187
173
 
188
174
  # Ensure that our generated source code has the same encoding as the
@@ -194,10 +180,7 @@ module Tilt
194
180
  template.force_encoding(template_encoding)
195
181
  end
196
182
 
197
- # https://github.com/rtomayko/tilt/issues/193
198
- warn "precompiled_preamble should return String (not Array)" if preamble.is_a?(Array)
199
- warn "precompiled_postamble should return String (not Array)" if postamble.is_a?(Array)
200
- source << [preamble, template, postamble].join("\n")
183
+ source << preamble << "\n" << template << "\n" << postamble
201
184
 
202
185
  [source, preamble.count("\n")+1]
203
186
  end
@@ -208,41 +191,52 @@ module Tilt
208
191
  # the base Template guarantees correct file/line handling, locals
209
192
  # support, custom scopes, proper encoding, and support for template
210
193
  # compilation.
211
- def precompiled_template(locals)
194
+ def precompiled_template(local_keys)
212
195
  raise NotImplementedError
213
196
  end
214
197
 
215
- # Generates preamble code for initializing template state, and performing
216
- # locals assignment. The default implementation performs locals
217
- # assignment only. Lines included in the preamble are subtracted from the
218
- # source line offset, so adding code to the preamble does not effect line
219
- # reporting in Kernel::caller and backtraces.
220
- def precompiled_preamble(locals)
221
- locals.map do |k,v|
222
- if k.to_s =~ /\A[a-z_][a-zA-Z_0-9]*\z/
223
- "#{k} = locals[#{k.inspect}]"
224
- else
225
- raise "invalid locals key: #{k.inspect} (keys must be variable names)"
226
- end
227
- end.join("\n")
198
+ def precompiled_preamble(local_keys)
199
+ ''
228
200
  end
229
201
 
230
- # Generates postamble code for the precompiled template source. The
231
- # string returned from this method is appended to the precompiled
232
- # template source.
233
- def precompiled_postamble(locals)
202
+ def precompiled_postamble(local_keys)
234
203
  ''
235
204
  end
236
205
 
206
+ # !@endgroup
207
+
208
+ private
209
+
210
+ def read_template_file
211
+ data = File.open(file, 'rb') { |io| io.read }
212
+ if data.respond_to?(:force_encoding)
213
+ # Set it to the default external (without verifying)
214
+ data.force_encoding(Encoding.default_external) if Encoding.default_external
215
+ end
216
+ data
217
+ end
218
+
237
219
  # The compiled method for the locals keys provided.
238
220
  def compiled_method(locals_keys)
239
- @compiled_method[locals_keys] ||=
240
- compile_template_method(locals_keys)
221
+ LOCK.synchronize do
222
+ @compiled_method[locals_keys] ||= compile_template_method(locals_keys)
223
+ end
224
+ end
225
+
226
+ def local_extraction(local_keys)
227
+ local_keys.map do |k|
228
+ if k.to_s =~ /\A[a-z_][a-zA-Z_0-9]*\z/
229
+ "#{k} = locals[#{k.inspect}]"
230
+ else
231
+ raise "invalid locals key: #{k.inspect} (keys must be variable names)"
232
+ end
233
+ end.join("\n")
241
234
  end
242
235
 
243
- private
244
- def compile_template_method(locals)
245
- source, offset = precompiled(locals)
236
+ def compile_template_method(local_keys)
237
+ source, offset = precompiled(local_keys)
238
+ local_code = local_extraction(local_keys)
239
+
246
240
  method_name = "__tilt_#{Thread.current.object_id.abs}"
247
241
  method_source = ""
248
242
 
@@ -257,11 +251,12 @@ module Tilt
257
251
  class << self
258
252
  this, locals = Thread.current[:tilt_vars]
259
253
  this.instance_eval do
254
+ #{local_code}
260
255
  RUBY
261
256
  offset += method_source.count("\n")
262
257
  method_source << source
263
258
  method_source << "\nend;end;end;end"
264
- Object.class_eval method_source, eval_file, line - offset
259
+ Object.class_eval(method_source, eval_file, line - offset)
265
260
  unbind_compiled_method(method_name)
266
261
  end
267
262
 
@@ -276,7 +271,7 @@ module Tilt
276
271
  end
277
272
 
278
273
  def extract_magic_comment(script)
279
- binary script do
274
+ binary(script) do
280
275
  script[/\A[ \t]*\#.*coding\s*[=:]\s*([[:alnum:]\-_]+).*$/n, 1]
281
276
  end
282
277
  end
@@ -0,0 +1,22 @@
1
+ require 'tilt/template'
2
+ require 'wikicloth'
3
+
4
+ module Tilt
5
+ # WikiCloth implementation. See:
6
+ # http://redcloth.org/
7
+ class WikiClothTemplate < Template
8
+ def prepare
9
+ @parser = options.delete(:parser) || WikiCloth::Parser
10
+ @engine = @parser.new options.merge(:data => data)
11
+ @output = nil
12
+ end
13
+
14
+ def evaluate(scope, locals, &block)
15
+ @output ||= @engine.to_html
16
+ end
17
+
18
+ def allows_script?
19
+ false
20
+ end
21
+ end
22
+ end
data/lib/tilt/yajl.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'tilt/template'
2
+ require 'yajl'
2
3
 
3
4
  module Tilt
4
5
 
@@ -42,14 +43,6 @@ module Tilt
42
43
 
43
44
  self.default_mime_type = 'application/json'
44
45
 
45
- def self.engine_initialized?
46
- defined? ::Yajl
47
- end
48
-
49
- def initialize_engine
50
- require_template_library 'yajl'
51
- end
52
-
53
46
  def prepare
54
47
  end
55
48
 
data/lib/tilt.rb CHANGED
@@ -1,121 +1,81 @@
1
+ require 'tilt/mapping'
2
+ require 'tilt/template'
3
+
4
+ # Namespace for Tilt. This module is not intended to be included anywhere.
1
5
  module Tilt
2
- VERSION = '1.4.1'
6
+ # Current version.
7
+ VERSION = '2.0.0'
3
8
 
4
- @preferred_mappings = Hash.new
5
- @template_mappings = Hash.new { |h, k| h[k] = [] }
9
+ @default_mapping = Mapping.new
6
10
 
7
- # Hash of template path pattern => template implementation class mappings.
8
- def self.mappings
9
- @template_mappings
11
+ # @return [Tilt::Mapping] the main mapping object
12
+ def self.default_mapping
13
+ @default_mapping
10
14
  end
11
15
 
12
- def self.normalize(ext)
13
- ext.to_s.downcase.sub(/^\./, '')
16
+ # @private
17
+ def self.lazy_map
18
+ default_mapping.lazy_map
14
19
  end
15
20
 
16
- # Register a template implementation by file extension.
21
+ # @see Tilt::Mapping#register
17
22
  def self.register(template_class, *extensions)
18
- if template_class.respond_to?(:to_str)
19
- # Support register(ext, template_class) too
20
- extensions, template_class = [template_class], extensions[0]
21
- end
23
+ default_mapping.register(template_class, *extensions)
24
+ end
22
25
 
23
- extensions.each do |ext|
24
- ext = normalize(ext)
25
- mappings[ext].unshift(template_class).uniq!
26
- end
26
+ # @see Tilt::Mapping#register_lazy
27
+ def self.register_lazy(class_name, file, *extensions)
28
+ default_mapping.register_lazy(class_name, file, *extensions)
27
29
  end
28
30
 
29
- # Makes a template class preferred for the given file extensions. If you
30
- # don't provide any extensions, it will be preferred for all its already
31
- # registered extensions:
32
- #
33
- # # Prefer RDiscount for its registered file extensions:
34
- # Tilt.prefer(Tilt::RDiscountTemplate)
35
- #
36
- # # Prefer RDiscount only for the .md extensions:
37
- # Tilt.prefer(Tilt::RDiscountTemplate, '.md')
31
+ # @deprecated Use {register} instead.
38
32
  def self.prefer(template_class, *extensions)
39
- if extensions.empty?
40
- mappings.each do |ext, klasses|
41
- @preferred_mappings[ext] = template_class if klasses.include? template_class
42
- end
43
- else
44
- extensions.each do |ext|
45
- ext = normalize(ext)
46
- register(template_class, ext)
47
- @preferred_mappings[ext] = template_class
48
- end
49
- end
33
+ register(template_class, *extensions)
50
34
  end
51
35
 
52
- # Returns true when a template exists on an exact match of the provided file extension
36
+ # @see Tilt::Mapping#registered?
53
37
  def self.registered?(ext)
54
- mappings.key?(ext.downcase) && !mappings[ext.downcase].empty?
38
+ default_mapping.registered?(ext)
55
39
  end
56
40
 
57
- # Create a new template for the given file using the file's extension
58
- # to determine the the template mapping.
41
+ # @see Tilt::Mapping#new
59
42
  def self.new(file, line=nil, options={}, &block)
60
- if template_class = self[file]
61
- template_class.new(file, line, options, &block)
62
- else
63
- fail "No template engine registered for #{File.basename(file)}"
64
- end
43
+ default_mapping.new(file, line, options, &block)
65
44
  end
66
45
 
67
- # Lookup a template class for the given filename or file
68
- # extension. Return nil when no implementation is found.
46
+ # @see Tilt::Mapping#[]
69
47
  def self.[](file)
70
- pattern = file.to_s.downcase
71
- until pattern.empty? || registered?(pattern)
72
- pattern = File.basename(pattern)
73
- pattern.sub!(/^[^.]*\.?/, '')
74
- end
75
-
76
- # Try to find a preferred engine.
77
- preferred_klass = @preferred_mappings[pattern]
78
- return preferred_klass if preferred_klass
79
-
80
- # Fall back to the general list of mappings.
81
- klasses = @template_mappings[pattern]
82
-
83
- # Try to find an engine which is already loaded.
84
- template = klasses.detect do |klass|
85
- if klass.respond_to?(:engine_initialized?)
86
- klass.engine_initialized?
87
- end
88
- end
48
+ default_mapping[file]
49
+ end
89
50
 
90
- return template if template
91
-
92
- # Try each of the classes until one succeeds. If all of them fails,
93
- # we'll raise the error of the first class.
94
- first_failure = nil
95
-
96
- klasses.each do |klass|
97
- begin
98
- klass.new { '' }
99
- rescue Exception => ex
100
- first_failure ||= ex
101
- next
102
- else
103
- return klass
104
- end
105
- end
51
+ # @see Tilt::Mapping#template_for
52
+ def self.template_for(file)
53
+ default_mapping.template_for(file)
54
+ end
106
55
 
107
- raise first_failure if first_failure
56
+ # @see Tilt::Mapping#templates_for
57
+ def self.templates_for(file)
58
+ default_mapping.templates_for(file)
108
59
  end
109
60
 
110
- # Deprecated module.
111
- module CompileSite
61
+ # @return the template object that is currently rendering.
62
+ #
63
+ # @example
64
+ # tmpl = Tilt['index.erb'].new { '<%= Tilt.current_template %>' }
65
+ # tmpl.render == tmpl.to_s
66
+ #
67
+ # @note This is currently an experimental feature and might return nil
68
+ # in the future.
69
+ def self.current_template
70
+ Thread.current[:tilt_current_template]
112
71
  end
113
72
 
114
73
  # Extremely simple template cache implementation. Calling applications
115
74
  # create a Tilt::Cache instance and use #fetch with any set of hashable
116
75
  # arguments (such as those to Tilt.new):
117
- # cache = Tilt::Cache.new
118
- # cache.fetch(path, line, options) { Tilt.new(path, line, options) }
76
+ #
77
+ # cache = Tilt::Cache.new
78
+ # cache.fetch(path, line, options) { Tilt.new(path, line, options) }
119
79
  #
120
80
  # Subsequent invocations return the already loaded template object.
121
81
  class Cache
@@ -123,10 +83,12 @@ module Tilt
123
83
  @cache = {}
124
84
  end
125
85
 
86
+ # @see Cache
126
87
  def fetch(*key)
127
88
  @cache[key] ||= yield
128
89
  end
129
90
 
91
+ # Clears the cache.
130
92
  def clear
131
93
  @cache = {}
132
94
  end
@@ -135,70 +97,41 @@ module Tilt
135
97
 
136
98
  # Template Implementations ================================================
137
99
 
138
- require 'tilt/string'
139
- register StringTemplate, 'str'
140
-
141
- require 'tilt/erb'
142
- register ERBTemplate, 'erb', 'rhtml'
143
- register ErubisTemplate, 'erb', 'rhtml', 'erubis'
144
-
145
- require 'tilt/etanni'
146
- register EtanniTemplate, 'etn', 'etanni'
147
-
148
- require 'tilt/haml'
149
- register HamlTemplate, 'haml'
150
-
151
- require 'tilt/css'
152
- register SassTemplate, 'sass'
153
- register ScssTemplate, 'scss'
154
- register LessTemplate, 'less'
155
-
156
- require 'tilt/csv'
157
- register CSVTemplate, 'rcsv'
158
-
159
- require 'tilt/coffee'
160
- register CoffeeScriptTemplate, 'coffee'
161
-
162
- require 'tilt/nokogiri'
163
- register NokogiriTemplate, 'nokogiri'
164
-
165
- require 'tilt/builder'
166
- register BuilderTemplate, 'builder'
167
-
168
- require 'tilt/markaby'
169
- register MarkabyTemplate, 'mab'
170
-
171
- require 'tilt/liquid'
172
- register LiquidTemplate, 'liquid'
173
-
174
- require 'tilt/radius'
175
- register RadiusTemplate, 'radius'
176
-
177
- require 'tilt/markdown'
178
- register MarukuTemplate, 'markdown', 'mkd', 'md'
179
- register KramdownTemplate, 'markdown', 'mkd', 'md'
180
- register BlueClothTemplate, 'markdown', 'mkd', 'md'
181
- register RDiscountTemplate, 'markdown', 'mkd', 'md'
182
- register RedcarpetTemplate::Redcarpet1, 'markdown', 'mkd', 'md'
183
- register RedcarpetTemplate::Redcarpet2, 'markdown', 'mkd', 'md'
184
- register RedcarpetTemplate, 'markdown', 'mkd', 'md'
185
-
186
- require 'tilt/textile'
187
- register RedClothTemplate, 'textile'
188
-
189
- require 'tilt/rdoc'
190
- register RDocTemplate, 'rdoc'
191
-
192
- require 'tilt/wiki'
193
- register CreoleTemplate, 'wiki', 'creole'
194
- register WikiClothTemplate, 'wiki', 'mediawiki', 'mw'
195
-
196
- require 'tilt/yajl'
197
- register YajlTemplate, 'yajl'
198
-
199
- require 'tilt/asciidoc'
200
- register AsciidoctorTemplate, 'ad', 'adoc', 'asciidoc'
201
-
202
- require 'tilt/plain'
203
- register PlainTemplate, 'html'
100
+ # ERB
101
+ register_lazy :ERBTemplate, 'tilt/erb', 'erb', 'rhtml'
102
+ register_lazy :ErubisTemplate, 'tilt/erubis', 'erb', 'rhtml', 'erubis'
103
+
104
+ # Markdown
105
+ register_lazy :BlueClothTemplate, 'tilt/bluecloth', 'markdown', 'mkd', 'md'
106
+ register_lazy :MarukuTemplate, 'tilt/maruku', 'markdown', 'mkd', 'md'
107
+ register_lazy :KramdownTemplate, 'tilt/kramdown', 'markdown', 'mkd', 'md'
108
+ register_lazy :RDiscountTemplate, 'tilt/rdiscount', 'markdown', 'mkd', 'md'
109
+ register_lazy :RedcarpetTemplate, 'tilt/redcarpet', 'markdown', 'mkd', 'md'
110
+
111
+ # Rest (sorted by name)
112
+ register_lazy :AsciidoctorTemplate, 'tilt/asciidoc', 'ad', 'adoc', 'asciidoc'
113
+ register_lazy :BuilderTemplate, 'tilt/builder', 'builder'
114
+ register_lazy :CSVTemplate, 'tilt/csv', 'rcsv'
115
+ register_lazy :CoffeeScriptTemplate, 'tilt/coffee', 'coffee'
116
+ register_lazy :CreoleTemplate, 'tilt/creole', 'wiki', 'creole'
117
+ register_lazy :EtanniTemplate, 'tilt/etanni', 'etn', 'etanni'
118
+ register_lazy :HamlTemplate, 'tilt/haml', 'haml'
119
+ register_lazy :LessTemplate, 'tilt/less', 'less'
120
+ register_lazy :LiquidTemplate, 'tilt/liquid', 'liquid'
121
+ register_lazy :MarkabyTemplate, 'tilt/markaby', 'mab'
122
+ register_lazy :NokogiriTemplate, 'tilt/nokogiri', 'nokogiri'
123
+ register_lazy :PlainTemplate, 'tilt/plain', 'html'
124
+ register_lazy :RDocTemplate, 'tilt/rdoc', 'rdoc'
125
+ register_lazy :RadiusTemplate, 'tilt/radius', 'radius'
126
+ register_lazy :RedClothTemplate, 'tilt/redcloth', 'textile'
127
+ register_lazy :SassTemplate, 'tilt/sass', 'sass'
128
+ register_lazy :ScssTemplate, 'tilt/sass', 'scss'
129
+ register_lazy :StringTemplate, 'tilt/string', 'str'
130
+ register_lazy :WikiClothTemplate, 'tilt/wikicloth', 'wiki', 'mediawiki', 'mw'
131
+ register_lazy :YajlTemplate, 'tilt/yajl', 'yajl'
132
+
133
+ # External template engines
134
+ register_lazy 'Slim::Template', 'slim', 'slim'
135
+ register_lazy 'Tilt::HandlebarsTemplate', 'tilt/handlebars', 'handlebars', 'hbs'
136
+ register_lazy 'Tilt::OrgTemplate', 'org-ruby', 'org'
204
137
  end
@@ -1,21 +1,17 @@
1
- require "test/unit"
1
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
2
 
3
- # Test::Unit loads a default test if the suite is empty, whose purpose is to
4
- # fail. Since having empty contexts is a common practice, we decided to
5
- # overwrite TestSuite#empty? in order to allow them. Having a failure when no
6
- # tests have been defined seems counter-intuitive.
7
- class Test::Unit::TestSuite
8
- def empty?
9
- false
10
- end
11
- end
3
+ require 'bundler'
4
+ Bundler.setup
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest/mock'
12
8
 
13
9
  # Contest adds +teardown+, +test+ and +context+ as class methods, and the
14
10
  # instance methods +setup+ and +teardown+ now iterate on the corresponding
15
11
  # blocks. Note that all setup and teardown blocks must be defined with the
16
12
  # block syntax. Adding setup or teardown instance methods defeats the purpose
17
13
  # of this library.
18
- class Test::Unit::TestCase
14
+ class Minitest::Test
19
15
  def self.setup(&block)
20
16
  define_method :setup do
21
17
  super(&block)