tilt 1.4.0 → 2.0.0.beta1

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 (72) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +33 -26
  4. data/README.md +21 -48
  5. data/Rakefile +21 -30
  6. data/{TEMPLATES.md → docs/TEMPLATES.md} +12 -6
  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 +247 -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 +84 -88
  31. data/lib/tilt/wikicloth.rb +22 -0
  32. data/lib/tilt/yajl.rb +1 -8
  33. data/lib/tilt.rb +85 -154
  34. data/test/{contest.rb → test_helper.rb} +5 -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.rb +215 -0
  51. data/test/tilt_markaby_test.rb +4 -4
  52. data/test/tilt_markdown_test.rb +13 -14
  53. data/test/tilt_marukutemplate_test.rb +6 -18
  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 +6 -18
  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 +58 -25
  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 +27 -386
  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
@@ -50,13 +64,6 @@ module Tilt
50
64
 
51
65
  raise ArgumentError, "file or block required" if (@file || block).nil?
52
66
 
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
67
  # used to hold compiled template methods
61
68
  @compiled_method = {}
62
69
 
@@ -79,28 +86,15 @@ module Tilt
79
86
  prepare
80
87
  end
81
88
 
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
89
  # Render the template in the given scope with the locals specified. If a
100
90
  # block is given, it is typically available within the template via
101
91
  # +yield+.
102
92
  def render(scope=Object.new, locals={}, &block)
103
- evaluate scope, locals || {}, &block
93
+ current_template = Thread.current[:tilt_current_template]
94
+ Thread.current[:tilt_current_template] = self
95
+ evaluate(scope, locals || {}, &block)
96
+ ensure
97
+ Thread.current[:tilt_current_template] = current_template
104
98
  end
105
99
 
106
100
  # The basename of the template file.
@@ -118,30 +112,26 @@ module Tilt
118
112
  file || '(__TEMPLATE__)'
119
113
  end
120
114
 
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
115
+ # An empty Hash that the template engine can populate with various
116
+ # metadata.
117
+ def metadata
118
+ if respond_to?(:allows_script?)
119
+ self.class.metadata.merge(:allows_script => allows_script?)
120
+ else
121
+ self.class.metadata
122
+ end
128
123
  end
129
124
 
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
125
+ protected
136
126
 
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
127
+ # @!group For template implementations
128
+
129
+ # The encoding of the source data. Defaults to the
130
+ # default_encoding-option if present. You may override this method
131
+ # in your template class if you have a better hint of the data's
132
+ # encoding.
133
+ def default_encoding
134
+ @default_encoding
145
135
  end
146
136
 
147
137
  # Do whatever preparation is necessary to setup the underlying template
@@ -150,13 +140,7 @@ module Tilt
150
140
  #
151
141
  # Subclasses must provide an implementation of this method.
152
142
  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
143
+ raise NotImplementedError
160
144
  end
161
145
 
162
146
  # Execute the compiled template and return the result string. Template
@@ -179,10 +163,10 @@ module Tilt
179
163
  # control over source generation or want to adjust the default line
180
164
  # offset. In most cases, overriding the #precompiled_template method is
181
165
  # easier and more appropriate.
182
- def precompiled(locals)
183
- preamble = precompiled_preamble(locals)
184
- template = precompiled_template(locals)
185
- postamble = precompiled_postamble(locals)
166
+ def precompiled(local_keys)
167
+ preamble = precompiled_preamble(local_keys)
168
+ template = precompiled_template(local_keys)
169
+ postamble = precompiled_postamble(local_keys)
186
170
  source = ''
187
171
 
188
172
  # Ensure that our generated source code has the same encoding as the
@@ -205,41 +189,52 @@ module Tilt
205
189
  # the base Template guarantees correct file/line handling, locals
206
190
  # support, custom scopes, proper encoding, and support for template
207
191
  # compilation.
208
- def precompiled_template(locals)
192
+ def precompiled_template(local_keys)
209
193
  raise NotImplementedError
210
194
  end
211
195
 
212
- # Generates preamble code for initializing template state, and performing
213
- # locals assignment. The default implementation performs locals
214
- # assignment only. Lines included in the preamble are subtracted from the
215
- # source line offset, so adding code to the preamble does not effect line
216
- # reporting in Kernel::caller and backtraces.
217
- def precompiled_preamble(locals)
218
- locals.map do |k,v|
219
- if k.to_s =~ /\A[a-z_][a-zA-Z_0-9]*\z/
220
- "#{k} = locals[#{k.inspect}]"
221
- else
222
- raise "invalid locals key: #{k.inspect} (keys must be variable names)"
223
- end
224
- end.join("\n")
196
+ def precompiled_preamble(local_keys)
197
+ ''
225
198
  end
226
199
 
227
- # Generates postamble code for the precompiled template source. The
228
- # string returned from this method is appended to the precompiled
229
- # template source.
230
- def precompiled_postamble(locals)
200
+ def precompiled_postamble(local_keys)
231
201
  ''
232
202
  end
233
203
 
204
+ # !@endgroup
205
+
206
+ private
207
+
208
+ def read_template_file
209
+ data = File.open(file, 'rb') { |io| io.read }
210
+ if data.respond_to?(:force_encoding)
211
+ # Set it to the default external (without verifying)
212
+ data.force_encoding(Encoding.default_external) if Encoding.default_external
213
+ end
214
+ data
215
+ end
216
+
234
217
  # The compiled method for the locals keys provided.
235
218
  def compiled_method(locals_keys)
236
- @compiled_method[locals_keys] ||=
237
- compile_template_method(locals_keys)
219
+ LOCK.synchronize do
220
+ @compiled_method[locals_keys] ||= compile_template_method(locals_keys)
221
+ end
222
+ end
223
+
224
+ def local_extraction(local_keys)
225
+ local_keys.map do |k|
226
+ if k.to_s =~ /\A[a-z_][a-zA-Z_0-9]*\z/
227
+ "#{k} = locals[#{k.inspect}]"
228
+ else
229
+ raise "invalid locals key: #{k.inspect} (keys must be variable names)"
230
+ end
231
+ end.join("\n")
238
232
  end
239
233
 
240
- private
241
- def compile_template_method(locals)
242
- source, offset = precompiled(locals)
234
+ def compile_template_method(local_keys)
235
+ source, offset = precompiled(local_keys)
236
+ local_code = local_extraction(local_keys)
237
+
243
238
  method_name = "__tilt_#{Thread.current.object_id.abs}"
244
239
  method_source = ""
245
240
 
@@ -254,11 +249,12 @@ module Tilt
254
249
  class << self
255
250
  this, locals = Thread.current[:tilt_vars]
256
251
  this.instance_eval do
252
+ #{local_code}
257
253
  RUBY
258
254
  offset += method_source.count("\n")
259
255
  method_source << source
260
256
  method_source << "\nend;end;end;end"
261
- Object.class_eval method_source, eval_file, line - offset
257
+ Object.class_eval(method_source, eval_file, line - offset)
262
258
  unbind_compiled_method(method_name)
263
259
  end
264
260
 
@@ -273,7 +269,7 @@ module Tilt
273
269
  end
274
270
 
275
271
  def extract_magic_comment(script)
276
- binary script do
272
+ binary(script) do
277
273
  script[/\A[ \t]*\#.*coding\s*[=:]\s*([[:alnum:]\-_]+).*$/n, 1]
278
274
  end
279
275
  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.0'
6
+ # Current version.
7
+ VERSION = '2.0.0.beta1'
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,39 @@ 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'
204
135
  end
@@ -1,21 +1,15 @@
1
- require "test/unit"
1
+ require 'bundler'
2
+ Bundler.setup
2
3
 
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
4
+ require 'minitest/autorun'
5
+ require 'minitest/mock'
12
6
 
13
7
  # Contest adds +teardown+, +test+ and +context+ as class methods, and the
14
8
  # instance methods +setup+ and +teardown+ now iterate on the corresponding
15
9
  # blocks. Note that all setup and teardown blocks must be defined with the
16
10
  # block syntax. Adding setup or teardown instance methods defeats the purpose
17
11
  # of this library.
18
- class Test::Unit::TestCase
12
+ class Minitest::Test
19
13
  def self.setup(&block)
20
14
  define_method :setup do
21
15
  super(&block)
@@ -1,10 +1,10 @@
1
- require 'contest'
1
+ require 'test_helper'
2
2
  require 'tilt'
3
3
 
4
4
  begin
5
- require 'asciidoctor'
5
+ require 'tilt/asciidoc'
6
6
 
7
- class AsciidoctorTemplateTest < Test::Unit::TestCase
7
+ class AsciidoctorTemplateTest < Minitest::Test
8
8
  HTML5_OUTPUT = "<div class=\"sect1\"><h2 id=\"_hello_world\">Hello World!</h2><div class=\"sectionbody\"></div></div>"
9
9
  DOCBOOK_OUTPUT = "<section id=\"_hello_world\"><title>Hello World!</title></section>"
10
10
 
@@ -13,15 +13,15 @@ begin
13
13
  end
14
14
 
15
15
  test "registered for '.ad' files" do
16
- assert Tilt.mappings['ad'].include?(Tilt::AsciidoctorTemplate)
16
+ assert_equal Tilt::AsciidoctorTemplate, Tilt['ad']
17
17
  end
18
18
 
19
19
  test "registered for '.adoc' files" do
20
- assert Tilt.mappings['adoc'].include?(Tilt::AsciidoctorTemplate)
20
+ assert_equal Tilt::AsciidoctorTemplate, Tilt['adoc']
21
21
  end
22
22
 
23
23
  test "registered for '.asciidoc' files" do
24
- assert Tilt.mappings['asciidoc'].include?(Tilt::AsciidoctorTemplate)
24
+ assert_equal Tilt::AsciidoctorTemplate, Tilt['asciidoc']
25
25
  end
26
26
 
27
27
  test "preparing and evaluating html5 templates on #render" do