tilt 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f43cb3f1357b1eeb55d129fed314692c5c053322
|
4
|
+
data.tar.gz: 63ba1cd6367f652f75c968a479530ae6830dc663
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a30fa65c04fe76bb58af64df4d1940272507d765b942eea1433ad070f0f924566f0c5b3569700dd50f947fc9c6bafe634a46c77279c42e4ac22ee8133e7adcf
|
7
|
+
data.tar.gz: eca0811f6a72525467c766996191feb3c0bc59b533dbe91831379e7ba3142b4010f37452b232d52145431e66391c3c0a858c0457a8dbe98bd857e1cbc7e0a015
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
## master
|
2
2
|
|
3
|
+
* Add Handlebars as external template engine (#204, judofyr, jimothyGator)
|
4
|
+
* Add org-ruby as external template engine (#207, judofyr, minad)
|
5
|
+
* Documentation typo (#208, elgalu)
|
6
|
+
|
7
|
+
## 2.0.0.beta1 (2013-07-16)
|
8
|
+
|
9
|
+
* Documentation typo (#202, chip)
|
10
|
+
* Use YARD for documentation (#189, judofyr)
|
11
|
+
* Add Slim as an external template engine (judofyr)
|
12
|
+
* Add Tilt.templates_for (#121, judofyr)
|
13
|
+
* Add Tilt.current_template (#151, judofyr)
|
14
|
+
* Avoid loading all files in tilt.rb (#160, #187, judofyr)
|
15
|
+
* Implement lazily required templates classes (#178, #187, judofyr)
|
16
|
+
* Move #allows_script and default_mime_type to metadata (#187, judofyr)
|
17
|
+
* Introduce Tilt::Mapping (#187, judofyr)
|
18
|
+
* Make template compilation thread-safe (#191, judofyr)
|
19
|
+
|
3
20
|
## 1.4.1 (2013-05-08)
|
4
21
|
|
5
22
|
* 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' if RUBY_VERSION > '1.9.2'
|
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' if RUBY_VERSION > '1.8.7'
|
30
|
+
gem 'rdiscount', '>= 2.1.6' if RUBY_VERSION != '1.9.2'
|
31
|
+
gem 'RedCloth'
|
32
|
+
end
|
33
|
+
|
34
|
+
platform :mri do
|
35
|
+
gem 'therubyracer'
|
36
|
+
gem 'bluecloth' if ENV['BLUECLOTH']
|
37
|
+
end
|
32
38
|
end
|
39
|
+
|
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
Tilt [![Build Status](https://secure.travis-ci.org/rtomayko/tilt.png)](http://travis-ci.org/rtomayko/tilt) [![Dependency Status](https://gemnasium.com/rtomayko/tilt.png)](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
|
-
an attempt to make their usage as generic possible. This is useful for web
|
8
|
+
an attempt to make their usage as generic as possible. This is useful for web
|
6
9
|
frameworks, static site generators, and other systems that support multiple
|
7
10
|
template engines but don't want to code for each of them individually.
|
8
11
|
|
@@ -58,11 +61,12 @@ These template engines ship with their own Tilt integration:
|
|
58
61
|
Embedded CoffeeScript sprockets
|
59
62
|
JST sprockets
|
60
63
|
Org-mode .org org-ruby (>= 0.6.2)
|
64
|
+
Handlebars .hbs, .handlebars tilt-handlebars
|
61
65
|
|
62
66
|
See [TEMPLATES.md][t] for detailed information on template engine
|
63
67
|
options and supported features.
|
64
68
|
|
65
|
-
[t]: http://github.com/rtomayko/tilt/blob/master/TEMPLATES.md
|
69
|
+
[t]: http://github.com/rtomayko/tilt/blob/master/docs/TEMPLATES.md
|
66
70
|
"Tilt Template Engine Documentation"
|
67
71
|
|
68
72
|
Basic Usage
|
@@ -82,12 +86,13 @@ libraries (like 'erb' above) at load time. Tilt attempts to lazy require the
|
|
82
86
|
template engine library the first time a template is created but this is
|
83
87
|
prone to error in threaded environments.
|
84
88
|
|
85
|
-
The
|
89
|
+
The {Tilt} module contains generic implementation classes for all supported
|
86
90
|
template engines. Each template class adheres to the same interface for
|
87
91
|
creation and rendering. In the instant gratification example, we let Tilt
|
88
92
|
determine the template implementation class based on the filename, but
|
89
|
-
|
93
|
+
{Tilt::Template} implementations can also be used directly:
|
90
94
|
|
95
|
+
require 'tilt/haml'
|
91
96
|
template = Tilt::HamlTemplate.new('templates/foo.haml')
|
92
97
|
output = template.render
|
93
98
|
|
@@ -95,6 +100,7 @@ The `render` method takes an optional evaluation scope and locals hash
|
|
95
100
|
arguments. Here, the template is evaluated within the context of the
|
96
101
|
`Person` object with locals `x` and `y`:
|
97
102
|
|
103
|
+
require 'tilt/erb'
|
98
104
|
template = Tilt::ERBTemplate.new('templates/foo.erb')
|
99
105
|
joe = Person.find('joe')
|
100
106
|
output = template.render(joe, :x => 35, :y => 42)
|
@@ -124,11 +130,14 @@ The block passed to `render` is called on `yield`:
|
|
124
130
|
Template Mappings
|
125
131
|
-----------------
|
126
132
|
|
127
|
-
The
|
128
|
-
classes with filename patterns and for locating/instantiating
|
129
|
-
classes based on those associations.
|
133
|
+
The {Tilt::Mapping} class includes methods for associating template
|
134
|
+
implementation classes with filename patterns and for locating/instantiating
|
135
|
+
template classes based on those associations.
|
136
|
+
|
137
|
+
The {Tilt} module has a global instance of `Mapping` that is populated with the
|
138
|
+
table of template engines above.
|
130
139
|
|
131
|
-
The
|
140
|
+
The {Tilt.register} method associates a filename pattern with a specific
|
132
141
|
template implementation. To use ERB for files ending in a `.bar` extension:
|
133
142
|
|
134
143
|
>> Tilt.register Tilt::ERBTemplate, 'bar'
|
@@ -142,15 +151,12 @@ Retrieving the template class for a file or file extension:
|
|
142
151
|
>> Tilt['haml']
|
143
152
|
=> Tilt::HamlTemplate
|
144
153
|
|
145
|
-
|
146
|
-
than a file extension. To use Erubis for `bar.erb` but ERB for all other `.erb`
|
147
|
-
files:
|
154
|
+
Retrieving a list of template classes for a file:
|
148
155
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
=> Tilt::ErubisTemplate
|
156
|
+
>> Tilt.templates_for('foo.bar')
|
157
|
+
=> [Tilt::ERBTemplate]
|
158
|
+
>> Tilt.templates_for('foo.haml.bar')
|
159
|
+
=> [Tilt::ERBTemplate, Tilt::HamlTemplate]
|
154
160
|
|
155
161
|
The template class is determined by searching for a series of decreasingly
|
156
162
|
specific name patterns. When creating a new template with
|
@@ -162,38 +168,6 @@ mappings:
|
|
162
168
|
3. `html.erb`
|
163
169
|
4. `erb`
|
164
170
|
|
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
171
|
Encodings
|
198
172
|
---------
|
199
173
|
|
@@ -213,7 +187,7 @@ tmpl = Tilt.new('hello.erb', :default_encoding => 'Big5')
|
|
213
187
|
|
214
188
|
Ultimately it's up to the template engine how to handle the encoding: It might
|
215
189
|
respect `:default_encoding`, it might always assume it's UTF-8 (like
|
216
|
-
|
190
|
+
CoffeeScript), or it can do its own encoding detection.
|
217
191
|
|
218
192
|
Template Compilation
|
219
193
|
--------------------
|
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/)
|
@@ -513,4 +519,5 @@ using this template engine within a threaded environment.
|
|
513
519
|
[discount]: http://www.pell.portland.or.us/~orc/Code/discount/ "Discount"
|
514
520
|
[rdiscount]: http://github.com/rtomayko/rdiscount/ "RDiscount"
|
515
521
|
[smartypants]: http://daringfireball.net/projects/smartypants/ "Smarty Pants"
|
522
|
+
[markdown]: http://en.wikipedia.org/wiki/Markdown "Markdown"
|
516
523
|
|
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)
|