tilt 1.4.1 → 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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +33 -26
- data/README.md +21 -48
- data/Rakefile +21 -30
- data/{TEMPLATES.md → docs/TEMPLATES.md} +10 -4
- data/docs/common.css +14 -0
- data/lib/tilt.rb +85 -154
- 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 +247 -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 +85 -92
- data/lib/tilt/wikicloth.rb +22 -0
- data/lib/tilt/yajl.rb +1 -8
- data/test/{contest.rb → test_helper.rb} +5 -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.rb +215 -0
- data/test/tilt_markaby_test.rb +4 -4
- data/test/tilt_markdown_test.rb +13 -14
- data/test/tilt_marukutemplate_test.rb +6 -18
- 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 +6 -18
- 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 +35 -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 -386
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 61afe68e016ac0b7857c8dab1c753683f432cbc1
|
4
|
+
data.tar.gz: f530866bbe789257559be15b56224a0f568acc03
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aaa94daebb4a6407c68a1487ffdb51b575bf732d4971dcbcae5efdf38e6f906a86947af15059a6480ed9d06885248f30d3f5bcda061e48f8313b90e69c7a0df6
|
7
|
+
data.tar.gz: ae9c268c9c14dc3187714374f8008a8f8b982f5075dcf709aede679fef26de0702e9d48f242d196aa9d194b3a2513f439f1719503a76c4761c78d7e1e0f24df1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## master
|
2
2
|
|
3
|
+
* Add Tilt.templates_for (#121, judofyr)
|
4
|
+
* Add Tilt.current_template (#151, judofyr)
|
5
|
+
* Avoid loading all files in tilt.rb (#160, #187, judofyr)
|
6
|
+
* Implement lazily required templates classes (#178, #187, judofyr)
|
7
|
+
* Move #allows_script and default_mime_type to metadata (#187, judofyr)
|
8
|
+
* Introduce Tilt::Mapping (#187, judofyr)
|
9
|
+
* Make template compilation thread-safe (#191, judofyr)
|
10
|
+
|
3
11
|
## 1.4.1 (2013-05-08)
|
4
12
|
|
5
13
|
* Support Arrays in pre/postambles (#193, jbwiv)
|
data/Gemfile
CHANGED
@@ -1,32 +1,39 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
+
gem 'yard', '~> 0.8.6'
|
4
|
+
gem 'minitest', '~> 5.0'
|
5
|
+
|
3
6
|
gem 'rake'
|
4
|
-
gem 'asciidoctor', '>= 0.1.0'
|
5
|
-
gem 'builder'
|
6
|
-
gem 'coffee-script'
|
7
|
-
gem 'contest'
|
8
|
-
gem 'creole'
|
9
|
-
gem 'erubis'
|
10
|
-
gem 'haml', '>= 2.2.11', '< 4'
|
11
|
-
gem 'kramdown'
|
12
|
-
gem 'less'
|
13
|
-
gem 'liquid'
|
14
|
-
gem 'markaby'
|
15
|
-
gem 'maruku'
|
16
|
-
gem 'nokogiri'
|
17
|
-
gem 'radius'
|
18
|
-
gem 'sass'
|
19
|
-
gem 'wikicloth'
|
20
|
-
gem 'rdoc', (ENV['RDOC_VERSION'] || '> 0')
|
21
7
|
|
22
|
-
|
23
|
-
gem '
|
24
|
-
gem '
|
25
|
-
gem '
|
26
|
-
gem '
|
27
|
-
|
8
|
+
group :engines do
|
9
|
+
gem 'asciidoctor', '>= 0.1.0'
|
10
|
+
gem 'builder'
|
11
|
+
gem 'coffee-script'
|
12
|
+
gem 'contest'
|
13
|
+
gem 'creole'
|
14
|
+
gem 'erubis'
|
15
|
+
gem 'haml', '>= 2.2.11', '< 4'
|
16
|
+
gem 'kramdown'
|
17
|
+
gem 'less'
|
18
|
+
gem 'liquid'
|
19
|
+
gem 'markaby'
|
20
|
+
gem 'maruku'
|
21
|
+
gem 'nokogiri'
|
22
|
+
gem 'radius'
|
23
|
+
gem 'sass'
|
24
|
+
gem 'wikicloth'
|
25
|
+
gem 'rdoc', (ENV['RDOC_VERSION'] || '> 0')
|
28
26
|
|
29
|
-
platform :
|
30
|
-
|
31
|
-
|
27
|
+
platform :ruby do
|
28
|
+
gem 'yajl-ruby'
|
29
|
+
gem 'redcarpet'
|
30
|
+
gem 'rdiscount' if RUBY_VERSION != '1.9.2'
|
31
|
+
gem 'RedCloth'
|
32
|
+
end
|
33
|
+
|
34
|
+
platform :mri do
|
35
|
+
gem 'therubyracer'
|
36
|
+
gem 'bluecloth'
|
37
|
+
end
|
32
38
|
end
|
39
|
+
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
Tilt [](http://travis-ci.org/rtomayko/tilt) [](https://gemnasium.com/rtomayko/tilt)
|
2
2
|
====
|
3
3
|
|
4
|
+
**NOTE** The follow file documents the upcoming release of Tilt (2.0). See
|
5
|
+
https://github.com/rtomayko/tilt/tree/tilt-1 for the current version.
|
6
|
+
|
4
7
|
Tilt is a thin interface over a bunch of different Ruby template engines in
|
5
8
|
an attempt to make their usage as generic possible. This is useful for web
|
6
9
|
frameworks, static site generators, and other systems that support multiple
|
@@ -62,7 +65,7 @@ These template engines ship with their own Tilt integration:
|
|
62
65
|
See [TEMPLATES.md][t] for detailed information on template engine
|
63
66
|
options and supported features.
|
64
67
|
|
65
|
-
[t]: http://github.com/rtomayko/tilt/blob/master/TEMPLATES.md
|
68
|
+
[t]: http://github.com/rtomayko/tilt/blob/master/docs/TEMPLATES.md
|
66
69
|
"Tilt Template Engine Documentation"
|
67
70
|
|
68
71
|
Basic Usage
|
@@ -82,12 +85,13 @@ libraries (like 'erb' above) at load time. Tilt attempts to lazy require the
|
|
82
85
|
template engine library the first time a template is created but this is
|
83
86
|
prone to error in threaded environments.
|
84
87
|
|
85
|
-
The
|
88
|
+
The {Tilt} module contains generic implementation classes for all supported
|
86
89
|
template engines. Each template class adheres to the same interface for
|
87
90
|
creation and rendering. In the instant gratification example, we let Tilt
|
88
91
|
determine the template implementation class based on the filename, but
|
89
|
-
|
92
|
+
{Tilt::Template} implementations can also be used directly:
|
90
93
|
|
94
|
+
require 'tilt/haml'
|
91
95
|
template = Tilt::HamlTemplate.new('templates/foo.haml')
|
92
96
|
output = template.render
|
93
97
|
|
@@ -95,6 +99,7 @@ The `render` method takes an optional evaluation scope and locals hash
|
|
95
99
|
arguments. Here, the template is evaluated within the context of the
|
96
100
|
`Person` object with locals `x` and `y`:
|
97
101
|
|
102
|
+
require 'tilt/erb'
|
98
103
|
template = Tilt::ERBTemplate.new('templates/foo.erb')
|
99
104
|
joe = Person.find('joe')
|
100
105
|
output = template.render(joe, :x => 35, :y => 42)
|
@@ -124,11 +129,14 @@ The block passed to `render` is called on `yield`:
|
|
124
129
|
Template Mappings
|
125
130
|
-----------------
|
126
131
|
|
127
|
-
The
|
128
|
-
classes with filename patterns and for locating/instantiating
|
129
|
-
classes based on those associations.
|
132
|
+
The {Tilt::Mapping} class includes methods for associating template
|
133
|
+
implementation classes with filename patterns and for locating/instantiating
|
134
|
+
template classes based on those associations.
|
135
|
+
|
136
|
+
The {Tilt} module has a global instance of `Mapping` that is populated with the
|
137
|
+
table of template engines above.
|
130
138
|
|
131
|
-
The
|
139
|
+
The {Tilt.register} method associates a filename pattern with a specific
|
132
140
|
template implementation. To use ERB for files ending in a `.bar` extension:
|
133
141
|
|
134
142
|
>> Tilt.register Tilt::ERBTemplate, 'bar'
|
@@ -142,15 +150,12 @@ Retrieving the template class for a file or file extension:
|
|
142
150
|
>> Tilt['haml']
|
143
151
|
=> Tilt::HamlTemplate
|
144
152
|
|
145
|
-
|
146
|
-
than a file extension. To use Erubis for `bar.erb` but ERB for all other `.erb`
|
147
|
-
files:
|
153
|
+
Retrieving a list of template classes for a file:
|
148
154
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
=> Tilt::ErubisTemplate
|
155
|
+
>> Tilt.templates_for('foo.bar')
|
156
|
+
=> [Tilt::ERBTemplate]
|
157
|
+
>> Tilt.templates_for('foo.haml.bar')
|
158
|
+
=> [Tilt::ERBTemplate, Tilt::HamlTemplate]
|
154
159
|
|
155
160
|
The template class is determined by searching for a series of decreasingly
|
156
161
|
specific name patterns. When creating a new template with
|
@@ -162,38 +167,6 @@ mappings:
|
|
162
167
|
3. `html.erb`
|
163
168
|
4. `erb`
|
164
169
|
|
165
|
-
### Fallback mode
|
166
|
-
|
167
|
-
If there are more than one template class registered for a file extension, Tilt
|
168
|
-
will automatically try to load the version that works on your machine:
|
169
|
-
|
170
|
-
1. If any of the template engines has been loaded already: Use that one.
|
171
|
-
2. If not, it will try to initialize each of the classes with an empty template.
|
172
|
-
3. Tilt will use the first that doesn't raise an exception.
|
173
|
-
4. If however *all* of them failed, Tilt will raise the exception of the first
|
174
|
-
template engine, since that was the most preferred one.
|
175
|
-
|
176
|
-
Template classes that were registered *last* would be tried first. Because the
|
177
|
-
Markdown extensions are registered like this:
|
178
|
-
|
179
|
-
Tilt.register Tilt::BlueClothTemplate, 'md'
|
180
|
-
Tilt.register Tilt::RDiscountTemplate, 'md'
|
181
|
-
|
182
|
-
Tilt will first try RDiscount and then BlueCloth. You could say that RDiscount
|
183
|
-
has a *higher priority* than BlueCloth.
|
184
|
-
|
185
|
-
The fallback mode works nicely when you just need to render an ERB or Markdown
|
186
|
-
template, but if you depend on a specific implementation, you should use #prefer:
|
187
|
-
|
188
|
-
# Prefer BlueCloth for all its registered extensions (markdown, mkd, md)
|
189
|
-
Tilt.prefer Tilt::BlueClothTemplate
|
190
|
-
|
191
|
-
# Prefer Erubis for .erb only:
|
192
|
-
Tilt.prefer Tilt::ErubisTemplate, 'erb'
|
193
|
-
|
194
|
-
When a file extension has a preferred template class, Tilt will *always* use
|
195
|
-
that class, even if it raises an exception.
|
196
|
-
|
197
170
|
Encodings
|
198
171
|
---------
|
199
172
|
|
@@ -213,7 +186,7 @@ tmpl = Tilt.new('hello.erb', :default_encoding => 'Big5')
|
|
213
186
|
|
214
187
|
Ultimately it's up to the template engine how to handle the encoding: It might
|
215
188
|
respect `:default_encoding`, it might always assume it's UTF-8 (like
|
216
|
-
|
189
|
+
CoffeeScript), or it can do its own encoding detection.
|
217
190
|
|
218
191
|
Template Compilation
|
219
192
|
--------------------
|
data/Rakefile
CHANGED
@@ -1,43 +1,34 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
task :default => [:setup, :test]
|
4
|
-
|
5
|
-
# set GEM_HOME to use local ./vendor dir for tests
|
6
|
-
vendor_dir = './vendor'
|
7
|
-
ruby_version = RbConfig::CONFIG['ruby_version']
|
8
|
-
ruby_engine = (defined?(RUBY_ENGINE) && RUBY_ENGINE) || 'ruby'
|
9
|
-
gem_home = ENV['GEM_HOME'] = "#{vendor_dir}/#{ruby_engine}/#{ruby_version}"
|
10
|
-
|
11
|
-
# Write the current version.
|
12
|
-
task :version do
|
13
|
-
puts "#{ruby_engine} #{RUBY_VERSION} (#{gem_home})"
|
14
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
15
3
|
|
16
|
-
|
17
|
-
task :
|
18
|
-
verbose false do
|
19
|
-
sh "
|
20
|
-
bundle check >/dev/null || {
|
21
|
-
echo 'Updating #{gem_home}' &&
|
22
|
-
bundle install --path='#{vendor_dir}'; }
|
23
|
-
"
|
24
|
-
end
|
25
|
-
end
|
4
|
+
require 'rake/testtask'
|
5
|
+
task :default => [:test]
|
26
6
|
|
27
7
|
# SPECS =====================================================================
|
28
8
|
|
29
|
-
desc 'Generate test coverage report'
|
30
|
-
task :rcov do
|
31
|
-
sh "rcov -Ilib:test test/*_test.rb"
|
32
|
-
end
|
33
|
-
|
34
9
|
desc 'Run tests (default)'
|
35
10
|
Rake::TestTask.new(:test) do |t|
|
36
11
|
t.test_files = FileList['test/*_test.rb']
|
37
12
|
t.ruby_opts = ['-Itest']
|
38
13
|
t.ruby_opts << '-rubygems' if defined? Gem
|
39
14
|
end
|
40
|
-
|
15
|
+
|
16
|
+
# DOCUMENTATION =============================================================
|
17
|
+
|
18
|
+
require 'yard'
|
19
|
+
YARD::Rake::YardocTask.new do |t|
|
20
|
+
t.files = [
|
21
|
+
'lib/tilt.rb', 'lib/tilt/mapping.rb', 'lib/tilt/template.rb',
|
22
|
+
'-',
|
23
|
+
'*.md', 'docs/*.md',
|
24
|
+
]
|
25
|
+
|
26
|
+
t.options <<
|
27
|
+
'--no-private' <<
|
28
|
+
'--protected' <<
|
29
|
+
'-m' << 'markdown' <<
|
30
|
+
'--asset' << 'docs/common.css:css/common.css'
|
31
|
+
end
|
41
32
|
|
42
33
|
# PACKAGING =================================================================
|
43
34
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Tilt Templates
|
2
2
|
==============
|
3
3
|
|
4
|
-
(See <https://github.com/rtomayko/tilt/blob/master/TEMPLATES.md> for a rendered,
|
4
|
+
(See <https://github.com/rtomayko/tilt/blob/master/docs/TEMPLATES.md> for a rendered,
|
5
5
|
HTML-version of this file).
|
6
6
|
|
7
7
|
While all Tilt templates use the same basic interface for template loading and
|
@@ -457,18 +457,24 @@ To wrap a Markdown formatted document with a layout:
|
|
457
457
|
### Options
|
458
458
|
|
459
459
|
Every implementation of Markdown *should* support these options, but there are
|
460
|
-
some known problems with the Kramdown and Maruku engines.
|
460
|
+
some known problems with the Kramdown and Maruku engines.
|
461
461
|
|
462
462
|
#### `:smartypants => true|false`
|
463
463
|
|
464
|
-
Set `true` to enable [Smarty Pants][smartypants]
|
465
|
-
|
464
|
+
Set `true` to enable [Smarty Pants][smartypants] style punctuation replacement.
|
465
|
+
|
466
|
+
In Kramdown this option only applies to smart quotes. It will apply a
|
467
|
+
subset of Smarty Pants (e.g. `...` to `…`) regardless of any option.
|
468
|
+
|
469
|
+
Maruku ignores this option and always applies smart quotes (and nothing else).
|
466
470
|
|
467
471
|
#### `:escape_html => true|false`
|
468
472
|
|
469
473
|
Set `true` disallow raw HTML in Markdown contents. HTML is converted to
|
470
474
|
literal text by escaping `<` characters.
|
471
475
|
|
476
|
+
Kramdown and Maruku doesn't support this option.
|
477
|
+
|
472
478
|
### See also
|
473
479
|
|
474
480
|
* [Markdown Syntax Documentation](http://daringfireball.net/projects/markdown/syntax/)
|
data/docs/common.css
ADDED
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.beta1'
|
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,39 @@ 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
|
-
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
|