tilt 1.4.1 → 2.0.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +33 -26
- data/README.md +23 -49
- data/Rakefile +21 -30
- data/{TEMPLATES.md → docs/TEMPLATES.md} +11 -4
- data/docs/common.css +14 -0
- data/lib/tilt/asciidoc.rb +1 -8
- data/lib/tilt/bluecloth.rb +24 -0
- data/lib/tilt/builder.rb +1 -8
- data/lib/tilt/coffee.rb +1 -8
- data/lib/tilt/creole.rb +25 -0
- data/lib/tilt/csv.rb +7 -13
- data/lib/tilt/erb.rb +2 -55
- data/lib/tilt/erubis.rb +43 -0
- data/lib/tilt/haml.rb +1 -8
- data/lib/tilt/kramdown.rb +33 -0
- data/lib/tilt/less.rb +38 -0
- data/lib/tilt/liquid.rb +1 -8
- data/lib/tilt/mapping.rb +265 -0
- data/lib/tilt/markaby.rb +1 -8
- data/lib/tilt/maruku.rb +22 -0
- data/lib/tilt/nokogiri.rb +1 -8
- data/lib/tilt/radius.rb +1 -8
- data/lib/tilt/rdiscount.rb +39 -0
- data/lib/tilt/rdoc.rb +3 -10
- data/lib/tilt/redcarpet.rb +104 -0
- data/lib/tilt/{textile.rb → redcloth.rb} +1 -8
- data/lib/tilt/sass.rb +41 -0
- data/lib/tilt/template.rb +88 -93
- data/lib/tilt/wikicloth.rb +22 -0
- data/lib/tilt/yajl.rb +1 -8
- data/lib/tilt.rb +87 -154
- data/test/{contest.rb → test_helper.rb} +7 -11
- data/test/tilt_asciidoctor_test.rb +6 -6
- data/test/tilt_blueclothtemplate_test.rb +3 -15
- data/test/tilt_buildertemplate_test.rb +3 -3
- data/test/tilt_cache_test.rb +2 -2
- data/test/tilt_coffeescripttemplate_test.rb +8 -18
- data/test/tilt_compilesite_test.rb +2 -2
- data/test/tilt_creoletemplate_test.rb +3 -7
- data/test/tilt_csv_test.rb +5 -9
- data/test/tilt_erbtemplate_test.rb +7 -7
- data/test/tilt_erubistemplate_test.rb +7 -7
- data/test/tilt_etannitemplate_test.rb +4 -3
- data/test/tilt_hamltemplate_test.rb +4 -4
- data/test/tilt_kramdown_test.rb +5 -27
- data/test/tilt_lesstemplate_test.rb +3 -3
- data/test/tilt_liquidtemplate_test.rb +3 -3
- data/test/tilt_mapping_test.rb +229 -0
- data/test/tilt_markaby_test.rb +4 -4
- data/test/tilt_markdown_test.rb +23 -21
- data/test/tilt_marukutemplate_test.rb +9 -21
- data/test/tilt_metadata_test.rb +42 -0
- data/test/tilt_nokogiritemplate_test.rb +3 -3
- data/test/tilt_radiustemplate_test.rb +3 -3
- data/test/tilt_rdiscounttemplate_test.rb +7 -19
- data/test/tilt_rdoctemplate_test.rb +3 -5
- data/test/tilt_redcarpettemplate_test.rb +11 -23
- data/test/tilt_redclothtemplate_test.rb +3 -3
- data/test/tilt_sasstemplate_test.rb +4 -4
- data/test/tilt_stringtemplate_test.rb +4 -3
- data/test/tilt_template_test.rb +42 -49
- data/test/tilt_test.rb +10 -15
- data/test/tilt_wikiclothtemplate_test.rb +3 -3
- data/test/tilt_yajltemplate_test.rb +3 -3
- data/tilt.gemspec +19 -32
- metadata +26 -385
- data/lib/tilt/css.rb +0 -80
- data/lib/tilt/markdown.rb +0 -214
- data/lib/tilt/wiki.rb +0 -58
- 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
|
-
|
27
|
-
|
29
|
+
# An empty Hash that the template engine can populate with various
|
30
|
+
# metadata.
|
31
|
+
def metadata
|
32
|
+
@metadata ||= {}
|
33
|
+
end
|
28
34
|
|
29
|
-
|
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
|
-
|
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
|
-
|
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
|
-
#
|
122
|
-
#
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
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
|
-
#
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
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(
|
183
|
-
preamble = precompiled_preamble(
|
184
|
-
template = precompiled_template(
|
185
|
-
postamble = precompiled_postamble(
|
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
|
-
|
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(
|
194
|
+
def precompiled_template(local_keys)
|
212
195
|
raise NotImplementedError
|
213
196
|
end
|
214
197
|
|
215
|
-
|
216
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
244
|
-
|
245
|
-
|
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
|
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
|
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
|
-
|
6
|
+
# Current version.
|
7
|
+
VERSION = '2.0.0'
|
3
8
|
|
4
|
-
@
|
5
|
-
@template_mappings = Hash.new { |h, k| h[k] = [] }
|
9
|
+
@default_mapping = Mapping.new
|
6
10
|
|
7
|
-
#
|
8
|
-
def self.
|
9
|
-
@
|
11
|
+
# @return [Tilt::Mapping] the main mapping object
|
12
|
+
def self.default_mapping
|
13
|
+
@default_mapping
|
10
14
|
end
|
11
15
|
|
12
|
-
|
13
|
-
|
16
|
+
# @private
|
17
|
+
def self.lazy_map
|
18
|
+
default_mapping.lazy_map
|
14
19
|
end
|
15
20
|
|
16
|
-
#
|
21
|
+
# @see Tilt::Mapping#register
|
17
22
|
def self.register(template_class, *extensions)
|
18
|
-
|
19
|
-
|
20
|
-
extensions, template_class = [template_class], extensions[0]
|
21
|
-
end
|
23
|
+
default_mapping.register(template_class, *extensions)
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
#
|
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
|
-
|
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
|
-
#
|
36
|
+
# @see Tilt::Mapping#registered?
|
53
37
|
def self.registered?(ext)
|
54
|
-
|
38
|
+
default_mapping.registered?(ext)
|
55
39
|
end
|
56
40
|
|
57
|
-
#
|
58
|
-
# to determine the the template mapping.
|
41
|
+
# @see Tilt::Mapping#new
|
59
42
|
def self.new(file, line=nil, options={}, &block)
|
60
|
-
|
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
|
-
#
|
68
|
-
# extension. Return nil when no implementation is found.
|
46
|
+
# @see Tilt::Mapping#[]
|
69
47
|
def self.[](file)
|
70
|
-
|
71
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
56
|
+
# @see Tilt::Mapping#templates_for
|
57
|
+
def self.templates_for(file)
|
58
|
+
default_mapping.templates_for(file)
|
108
59
|
end
|
109
60
|
|
110
|
-
#
|
111
|
-
|
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
|
-
#
|
118
|
-
#
|
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
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
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
|
-
|
1
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
14
|
+
class Minitest::Test
|
19
15
|
def self.setup(&block)
|
20
16
|
define_method :setup do
|
21
17
|
super(&block)
|