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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +33 -26
- data/README.md +21 -48
- data/Rakefile +21 -30
- data/{TEMPLATES.md → docs/TEMPLATES.md} +12 -6
- 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 +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 +84 -88
- data/lib/tilt/wikicloth.rb +22 -0
- data/lib/tilt/yajl.rb +1 -8
- data/lib/tilt.rb +85 -154
- 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 +58 -25
- 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 +27 -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,17 @@
|
|
|
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
|
+
|
|
11
|
+
## 1.4.1 (2013-05-08)
|
|
12
|
+
|
|
13
|
+
* Support Arrays in pre/postambles (#193, jbwiv)
|
|
14
|
+
|
|
3
15
|
## 1.4.0 (2013-05-01)
|
|
4
16
|
|
|
5
17
|
* Better encoding support
|
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
|
|
@@ -305,9 +305,9 @@ time when using this template engine within a threaded environment.
|
|
|
305
305
|
|
|
306
306
|
### See also
|
|
307
307
|
|
|
308
|
-
* [Liquid for Programmers](
|
|
308
|
+
* [Liquid for Programmers](https://wiki.github.com/Shopify/liquid/liquid-for-programmers)
|
|
309
309
|
* [Liquid Docs](http://liquid.rubyforge.org/)
|
|
310
|
-
* GitHub: [
|
|
310
|
+
* GitHub: [Shopify/liquid](https://github.com/Shopify/liquid/)
|
|
311
311
|
|
|
312
312
|
|
|
313
313
|
<a name='radius'></a>
|
|
@@ -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/asciidoc.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'tilt/template'
|
|
2
|
+
require 'asciidoctor'
|
|
2
3
|
|
|
3
4
|
# AsciiDoc see: http://asciidoc.org/
|
|
4
5
|
module Tilt
|
|
@@ -11,14 +12,6 @@ module Tilt
|
|
|
11
12
|
class AsciidoctorTemplate < Template
|
|
12
13
|
self.default_mime_type = 'text/html'
|
|
13
14
|
|
|
14
|
-
def self.engine_initialized?
|
|
15
|
-
defined? ::Asciidoctor::Document
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def initialize_engine
|
|
19
|
-
require_template_library 'asciidoctor'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
15
|
def prepare
|
|
23
16
|
options[:header_footer] = false if options[:header_footer].nil?
|
|
24
17
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'tilt/template'
|
|
2
|
+
require 'bluecloth'
|
|
3
|
+
|
|
4
|
+
module Tilt
|
|
5
|
+
# BlueCloth Markdown implementation. See:
|
|
6
|
+
# http://deveiate.org/projects/BlueCloth/
|
|
7
|
+
class BlueClothTemplate < Template
|
|
8
|
+
self.default_mime_type = 'text/html'
|
|
9
|
+
|
|
10
|
+
def prepare
|
|
11
|
+
@engine = BlueCloth.new(data, options)
|
|
12
|
+
@output = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def evaluate(scope, locals, &block)
|
|
16
|
+
@output ||= @engine.to_html
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def allows_script?
|
|
20
|
+
false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
data/lib/tilt/builder.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'tilt/template'
|
|
2
|
+
require 'builder'
|
|
2
3
|
|
|
3
4
|
module Tilt
|
|
4
5
|
# Builder template implementation. See:
|
|
@@ -6,14 +7,6 @@ module Tilt
|
|
|
6
7
|
class BuilderTemplate < Template
|
|
7
8
|
self.default_mime_type = 'text/xml'
|
|
8
9
|
|
|
9
|
-
def self.engine_initialized?
|
|
10
|
-
defined? ::Builder
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def initialize_engine
|
|
14
|
-
require_template_library 'builder'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
10
|
def prepare; end
|
|
18
11
|
|
|
19
12
|
def evaluate(scope, locals, &block)
|
data/lib/tilt/coffee.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'tilt/template'
|
|
2
|
+
require 'coffee_script'
|
|
2
3
|
|
|
3
4
|
module Tilt
|
|
4
5
|
# CoffeeScript template implementation. See:
|
|
@@ -28,14 +29,6 @@ module Tilt
|
|
|
28
29
|
@@default_bare = value
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
def self.engine_initialized?
|
|
32
|
-
defined? ::CoffeeScript
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def initialize_engine
|
|
36
|
-
require_template_library 'coffee_script'
|
|
37
|
-
end
|
|
38
|
-
|
|
39
32
|
def prepare
|
|
40
33
|
if !options.key?(:bare) and !options.key?(:no_wrap)
|
|
41
34
|
options[:bare] = self.class.default_bare
|
data/lib/tilt/creole.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'tilt/template'
|
|
2
|
+
require 'creole'
|
|
3
|
+
|
|
4
|
+
module Tilt
|
|
5
|
+
# Creole implementation. See:
|
|
6
|
+
# http://www.wikicreole.org/
|
|
7
|
+
class CreoleTemplate < Template
|
|
8
|
+
def prepare
|
|
9
|
+
opts = {}
|
|
10
|
+
[:allowed_schemes, :extensions, :no_escape].each do |k|
|
|
11
|
+
opts[k] = options[k] if options[k]
|
|
12
|
+
end
|
|
13
|
+
@engine = Creole::Parser.new(data, opts)
|
|
14
|
+
@output = nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def evaluate(scope, locals, &block)
|
|
18
|
+
@output ||= @engine.to_html
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def allows_script?
|
|
22
|
+
false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/tilt/csv.rb
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
require 'tilt/template'
|
|
2
2
|
|
|
3
|
+
if RUBY_VERSION >= '1.9.0'
|
|
4
|
+
require 'csv'
|
|
5
|
+
else
|
|
6
|
+
require 'fastercsv'
|
|
7
|
+
end
|
|
8
|
+
|
|
3
9
|
module Tilt
|
|
4
10
|
|
|
5
11
|
# CSV Template implementation. See:
|
|
@@ -30,10 +36,6 @@ module Tilt
|
|
|
30
36
|
class CSVTemplate < Template
|
|
31
37
|
self.default_mime_type = 'text/csv'
|
|
32
38
|
|
|
33
|
-
def self.engine_initialized?
|
|
34
|
-
engine
|
|
35
|
-
end
|
|
36
|
-
|
|
37
39
|
def self.engine
|
|
38
40
|
if RUBY_VERSION >= '1.9.0' && defined? ::CSV
|
|
39
41
|
::CSV
|
|
@@ -42,14 +44,6 @@ module Tilt
|
|
|
42
44
|
end
|
|
43
45
|
end
|
|
44
46
|
|
|
45
|
-
def initialize_engine
|
|
46
|
-
if RUBY_VERSION >= '1.9.0'
|
|
47
|
-
require_template_library 'csv'
|
|
48
|
-
else
|
|
49
|
-
require_template_library 'fastercsv'
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
47
|
def prepare
|
|
54
48
|
@code =<<-RUBY
|
|
55
49
|
#{self.class.engine}.generate do |csv|
|
|
@@ -68,4 +62,4 @@ module Tilt
|
|
|
68
62
|
end
|
|
69
63
|
|
|
70
64
|
end
|
|
71
|
-
end
|
|
65
|
+
end
|
data/lib/tilt/erb.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'tilt/template'
|
|
2
|
+
require 'erb'
|
|
2
3
|
|
|
3
4
|
module Tilt
|
|
4
5
|
# ERB template implementation. See:
|
|
@@ -11,17 +12,10 @@ module Tilt
|
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
def self.default_output_variable=(name)
|
|
15
|
+
warn "#{self}.default_output_variable= has been replaced with the :outvar-option"
|
|
14
16
|
@@default_output_variable = name
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
def self.engine_initialized?
|
|
18
|
-
defined? ::ERB
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def initialize_engine
|
|
22
|
-
require_template_library 'erb'
|
|
23
|
-
end
|
|
24
|
-
|
|
25
19
|
def prepare
|
|
26
20
|
@outvar = options[:outvar] || self.class.default_output_variable
|
|
27
21
|
options[:trim] = '<>' if !(options[:trim] == false) && (options[:trim].nil? || options[:trim] == true)
|
|
@@ -59,52 +53,5 @@ module Tilt
|
|
|
59
53
|
end
|
|
60
54
|
end
|
|
61
55
|
end
|
|
62
|
-
|
|
63
|
-
# Erubis template implementation. See:
|
|
64
|
-
# http://www.kuwata-lab.com/erubis/
|
|
65
|
-
#
|
|
66
|
-
# ErubisTemplate supports the following additional options, which are not
|
|
67
|
-
# passed down to the Erubis engine:
|
|
68
|
-
#
|
|
69
|
-
# :engine_class allows you to specify a custom engine class to use
|
|
70
|
-
# instead of the default (which is ::Erubis::Eruby).
|
|
71
|
-
#
|
|
72
|
-
# :escape_html when true, ::Erubis::EscapedEruby will be used as
|
|
73
|
-
# the engine class instead of the default. All content
|
|
74
|
-
# within <%= %> blocks will be automatically html escaped.
|
|
75
|
-
class ErubisTemplate < ERBTemplate
|
|
76
|
-
def self.engine_initialized?
|
|
77
|
-
defined? ::Erubis::Eruby
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def initialize_engine
|
|
81
|
-
require_template_library 'erubis'
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def prepare
|
|
85
|
-
@outvar = options.delete(:outvar) || self.class.default_output_variable
|
|
86
|
-
@options.merge!(:preamble => false, :postamble => false, :bufvar => @outvar)
|
|
87
|
-
engine_class = options.delete(:engine_class)
|
|
88
|
-
engine_class = ::Erubis::EscapedEruby if options.delete(:escape_html)
|
|
89
|
-
@engine = (engine_class || ::Erubis::Eruby).new(data, options)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def precompiled_preamble(locals)
|
|
93
|
-
[super, "#{@outvar} = _buf = ''"].join("\n")
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def precompiled_postamble(locals)
|
|
97
|
-
[@outvar, super].join("\n")
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
# Erubis doesn't have ERB's line-off-by-one under 1.9 problem.
|
|
101
|
-
# Override and adjust back.
|
|
102
|
-
if RUBY_VERSION >= '1.9.0'
|
|
103
|
-
def precompiled(locals)
|
|
104
|
-
source, offset = super
|
|
105
|
-
[source, offset - 1]
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
56
|
end
|
|
110
57
|
|
data/lib/tilt/erubis.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'tilt/erb'
|
|
2
|
+
require 'erubis'
|
|
3
|
+
|
|
4
|
+
module Tilt
|
|
5
|
+
# Erubis template implementation. See:
|
|
6
|
+
# http://www.kuwata-lab.com/erubis/
|
|
7
|
+
#
|
|
8
|
+
# ErubisTemplate supports the following additional options, which are not
|
|
9
|
+
# passed down to the Erubis engine:
|
|
10
|
+
#
|
|
11
|
+
# :engine_class allows you to specify a custom engine class to use
|
|
12
|
+
# instead of the default (which is ::Erubis::Eruby).
|
|
13
|
+
#
|
|
14
|
+
# :escape_html when true, ::Erubis::EscapedEruby will be used as
|
|
15
|
+
# the engine class instead of the default. All content
|
|
16
|
+
# within <%= %> blocks will be automatically html escaped.
|
|
17
|
+
class ErubisTemplate < ERBTemplate
|
|
18
|
+
def prepare
|
|
19
|
+
@outvar = options.delete(:outvar) || self.class.default_output_variable
|
|
20
|
+
@options.merge!(:preamble => false, :postamble => false, :bufvar => @outvar)
|
|
21
|
+
engine_class = options.delete(:engine_class)
|
|
22
|
+
engine_class = ::Erubis::EscapedEruby if options.delete(:escape_html)
|
|
23
|
+
@engine = (engine_class || ::Erubis::Eruby).new(data, options)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def precompiled_preamble(locals)
|
|
27
|
+
[super, "#{@outvar} = _buf = ''"].join("\n")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def precompiled_postamble(locals)
|
|
31
|
+
[@outvar, super].join("\n")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Erubis doesn't have ERB's line-off-by-one under 1.9 problem.
|
|
35
|
+
# Override and adjust back.
|
|
36
|
+
if RUBY_VERSION >= '1.9.0'
|
|
37
|
+
def precompiled(locals)
|
|
38
|
+
source, offset = super
|
|
39
|
+
[source, offset - 1]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/tilt/haml.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'tilt/template'
|
|
2
|
+
require 'haml'
|
|
2
3
|
|
|
3
4
|
module Tilt
|
|
4
5
|
# Haml template implementation. See:
|
|
@@ -6,14 +7,6 @@ module Tilt
|
|
|
6
7
|
class HamlTemplate < Template
|
|
7
8
|
self.default_mime_type = 'text/html'
|
|
8
9
|
|
|
9
|
-
def self.engine_initialized?
|
|
10
|
-
defined? ::Haml::Engine
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def initialize_engine
|
|
14
|
-
require_template_library 'haml'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
10
|
def prepare
|
|
18
11
|
options = @options.merge(:filename => eval_file, :line => line)
|
|
19
12
|
@engine = ::Haml::Engine.new(data, options)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'tilt/template'
|
|
2
|
+
require 'kramdown'
|
|
3
|
+
|
|
4
|
+
module Tilt
|
|
5
|
+
# Kramdown Markdown implementation. See:
|
|
6
|
+
# http://kramdown.rubyforge.org/
|
|
7
|
+
class KramdownTemplate < Template
|
|
8
|
+
DUMB_QUOTES = [39, 39, 34, 34]
|
|
9
|
+
|
|
10
|
+
def self.engine_initialized?
|
|
11
|
+
defined? ::Kramdown
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize_engine
|
|
15
|
+
require_template_library 'kramdown'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def prepare
|
|
19
|
+
options[:smart_quotes] = DUMB_QUOTES unless options[:smartypants]
|
|
20
|
+
@engine = Kramdown::Document.new(data, options)
|
|
21
|
+
@output = nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def evaluate(scope, locals, &block)
|
|
25
|
+
@output ||= @engine.to_html
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def allows_script?
|
|
29
|
+
false
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|