tilt 1.2.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +54 -24
- data/TEMPLATES.md +250 -175
- data/lib/tilt.rb +104 -817
- data/lib/tilt/builder.rb +40 -0
- data/lib/tilt/coffee.rb +50 -0
- data/lib/tilt/creole.rb +28 -0
- data/lib/tilt/css.rb +67 -0
- data/lib/tilt/erb.rb +110 -0
- data/lib/tilt/haml.rb +64 -0
- data/lib/tilt/liquid.rb +41 -0
- data/lib/tilt/markaby.rb +52 -0
- data/lib/tilt/markdown.rb +131 -0
- data/lib/tilt/nokogiri.rb +43 -0
- data/lib/tilt/radius.rb +51 -0
- data/lib/tilt/rdoc.rb +32 -0
- data/lib/tilt/string.rb +21 -0
- data/lib/tilt/template.rb +285 -0
- data/lib/tilt/textile.rb +25 -0
- data/test/tilt_blueclothtemplate_test.rb +6 -25
- data/test/tilt_coffeescripttemplate_test.rb +31 -1
- data/test/tilt_creoletemplate_test.rb +24 -0
- data/test/tilt_erbtemplate_test.rb +18 -19
- data/test/tilt_erubistemplate_test.rb +12 -2
- data/test/tilt_fallback_test.rb +122 -0
- data/test/tilt_hamltemplate_test.rb +4 -4
- data/test/tilt_kramdown_test.rb +42 -0
- data/test/tilt_markdown_test.rb +149 -0
- data/test/tilt_marukutemplate_test.rb +48 -0
- data/test/tilt_rdiscounttemplate_test.rb +16 -6
- data/test/tilt_redcarpettemplate_test.rb +55 -0
- data/test/tilt_stringtemplate_test.rb +10 -3
- data/test/tilt_template_test.rb +6 -0
- data/tilt.gemspec +28 -2
- metadata +86 -36
data/README.md
CHANGED
@@ -21,22 +21,29 @@ template engines included in the distribution.
|
|
21
21
|
|
22
22
|
Support for these template engines is included with the package:
|
23
23
|
|
24
|
-
ENGINE FILE EXTENSIONS
|
25
|
-
--------------------------
|
26
|
-
ERB .erb
|
27
|
-
Interpolated String .str
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
|
25
|
+
-------------------------- ---------------------- ----------------------------
|
26
|
+
ERB .erb, .rhtml none (included ruby stdlib)
|
27
|
+
Interpolated String .str none (included ruby core)
|
28
|
+
Erubis .erb, .rhtml, .erubis erubis
|
29
|
+
Haml .haml haml
|
30
|
+
Sass .sass haml (< 3.1) or sass (>= 3.1)
|
31
|
+
Scss .scss haml (< 3.1) or sass (>= 3.1)
|
32
|
+
Less CSS .less less
|
33
|
+
Builder .builder builder
|
34
|
+
Liquid .liquid liquid
|
35
|
+
RDiscount .markdown, .mkd, .md rdiscount
|
36
|
+
Redcarpet .markdown, .mkd, .md redcarpet
|
37
|
+
BlueCloth .markdown, .mkd, .md bluecloth
|
38
|
+
Kramdown .markdown, .mkd, .md kramdown
|
39
|
+
Maruku .markdown, .mkd, .md maruku
|
40
|
+
RedCloth .textile redcloth
|
41
|
+
RDoc .rdoc rdoc
|
42
|
+
Radius .radius radius
|
43
|
+
Markaby .mab markaby
|
44
|
+
Nokogiri .nokogiri nokogiri
|
45
|
+
CoffeeScript .coffee coffee-script (+ javascript)
|
46
|
+
Creole (Wiki markup) .creole creole
|
40
47
|
|
41
48
|
These template engines ship with their own Tilt integration:
|
42
49
|
|
@@ -116,7 +123,7 @@ classes based on those associations.
|
|
116
123
|
The `Tilt::register` method associates a filename pattern with a specific
|
117
124
|
template implementation. To use ERB for files ending in a `.bar` extension:
|
118
125
|
|
119
|
-
>> Tilt.register 'bar'
|
126
|
+
>> Tilt.register Tilt::ERBTemplate, 'bar'
|
120
127
|
>> Tilt.new('views/foo.bar')
|
121
128
|
=> #<Tilt::ERBTemplate @file="views/foo.bar" ...>
|
122
129
|
|
@@ -131,7 +138,7 @@ It's also possible to register template file mappings that are more specific
|
|
131
138
|
than a file extension. To use Erubis for `bar.erb` but ERB for all other `.erb`
|
132
139
|
files:
|
133
140
|
|
134
|
-
>> Tilt.register 'bar.erb'
|
141
|
+
>> Tilt.register Tilt::ErubisTemplate, 'bar.erb'
|
135
142
|
>> Tilt.new('views/foo.erb')
|
136
143
|
=> Tilt::ERBTemplate
|
137
144
|
>> Tilt.new('views/bar.erb')
|
@@ -147,14 +154,37 @@ mappings:
|
|
147
154
|
3. `html.erb`
|
148
155
|
4. `erb`
|
149
156
|
|
150
|
-
|
151
|
-
|
157
|
+
### Fallback mode
|
158
|
+
|
159
|
+
If there are more than one template class registered for a file extension, Tilt
|
160
|
+
will automatically try to load the version that works on your machine:
|
161
|
+
|
162
|
+
1. If any of the template engines has been loaded already: Use that one.
|
163
|
+
2. If not, it will try to initialize each of the classes with an empty template.
|
164
|
+
3. Tilt will use the first that doesn't raise an exception.
|
165
|
+
4. If however *all* of them failed, Tilt will raise the exception of the first
|
166
|
+
template engine, since that was the most preferred one.
|
167
|
+
|
168
|
+
Template classes that were registered *last* would be tried first. Because the
|
169
|
+
Markdown extensions are registered like this:
|
170
|
+
|
171
|
+
Tilt.register Tilt::BlueClothTemplate, 'md'
|
172
|
+
Tilt.register Tilt::RDiscountTemplate, 'md'
|
173
|
+
|
174
|
+
Tilt will first try RDiscount and then BlueCloth. You could say that RDiscount
|
175
|
+
has a *higher priority* than BlueCloth.
|
152
176
|
|
153
|
-
|
177
|
+
The fallback mode works nicely when you just need to render an ERB or Markdown
|
178
|
+
template, but if you depend on a specific implementation, you should use #prefer:
|
154
179
|
|
155
|
-
|
180
|
+
# Prefer BlueCloth for all its registered extensions (markdown, mkd, md)
|
181
|
+
Tilt.prefer Tilt::BlueClothTemplate
|
182
|
+
|
183
|
+
# Prefer Erubis for .erb only:
|
184
|
+
Tilt.prefer Tilt::ErubisTemplate, 'erb'
|
156
185
|
|
157
|
-
|
186
|
+
When a file extension has a preferred template class, Tilt will *always* use
|
187
|
+
that class, even if it raises an exception.
|
158
188
|
|
159
189
|
Template Compilation
|
160
190
|
--------------------
|
@@ -164,7 +194,7 @@ it on subsequent template invocations. Benchmarks show this yields a 5x-10x
|
|
164
194
|
performance increase over evaluating the Ruby source on each invocation.
|
165
195
|
|
166
196
|
Template compilation is currently supported for these template engines:
|
167
|
-
StringTemplate, ERB, Erubis, Haml, and Builder.
|
197
|
+
StringTemplate, ERB, Erubis, Haml, Nokogiri and Builder.
|
168
198
|
|
169
199
|
LICENSE
|
170
200
|
-------
|
data/TEMPLATES.md
CHANGED
@@ -1,65 +1,122 @@
|
|
1
1
|
Tilt Templates
|
2
2
|
==============
|
3
3
|
|
4
|
+
(See <https://github.com/rtomayko/tilt/blob/master/TEMPLATES.md> for a rendered,
|
5
|
+
HTML-version of this file).
|
6
|
+
|
4
7
|
While all Tilt templates use the same basic interface for template loading and
|
5
8
|
evaluation, each varies in its capabilities and available options. Detailed
|
6
9
|
documentation on each supported template engine is provided below.
|
7
10
|
|
8
|
-
|
11
|
+
There are also some file extensions that have several implementations
|
12
|
+
(currently ERB and Markdown). These template classes have certain features
|
13
|
+
which are guaranteed to work across all the implementations. If you wish to be
|
14
|
+
compatible with all of these template classes, you should only depend on the
|
15
|
+
cross-implementation features.
|
16
|
+
|
17
|
+
* [ERB](#erb) - Generic ERB implementation (backed by erb.rb or Erubis)
|
18
|
+
* [erb.rb](#erbrb) - `Tilt::ERBTemplate`
|
9
19
|
* [Erubis](#erubis) - `Tilt::ErubisTemplate`
|
10
20
|
* [Haml](#haml) - `Tilt::HamlTemplate`
|
11
21
|
* [Liquid](#liquid) - `Tilt::LiquidTemplate`
|
22
|
+
* Nokogiri - `Tilt::NokogiriTemplate`
|
23
|
+
* Builder - `Tilt::BuilderTemplate`
|
24
|
+
* Markaby - `Tilt::MarkabyTemplate`
|
25
|
+
* [Radius](#radius) - `Tilt::RadiusTemplate`
|
12
26
|
|
13
|
-
Tilt includes support for CSS processors like [lesscss]
|
14
|
-
|
15
|
-
text formats.
|
27
|
+
Tilt also includes support for CSS processors like [LessCSS][lesscss] and
|
28
|
+
[Sass][sass], [CoffeeScript][coffee-script] and some simple text formats.
|
16
29
|
|
17
30
|
* Less - `Tilt::LessTemplate`
|
18
31
|
* Sass - `Tilt::SassTemplate`
|
19
|
-
*
|
32
|
+
* Scss - `Tilt::ScssTemplate`
|
33
|
+
* CoffeeScript - `Tilt::CoffeeScriptTemplate`
|
34
|
+
* [Textile](#redcloth) - `Tilt::RedClothTemplate`
|
35
|
+
* Creole - `Tilt::CreoleTemplate`
|
20
36
|
* [RDoc](#rdoc) - `Tilt::RDocTemplate`
|
21
37
|
|
38
|
+
Tilt has extensive support for Markdown, backed by one of four different
|
39
|
+
implementations (depending on which are available on your system):
|
40
|
+
|
41
|
+
* [Markdown](#markdown) - Generic Markdown implementation
|
42
|
+
* [RDiscount](#rdiscount) - `Tilt::RDiscountTemplate`
|
43
|
+
* BlueCloth - `Tilt::BlueClothTemplate`
|
44
|
+
* Kramdown - `Tilt::KramdownTemplate`
|
45
|
+
* Maruku - `Tilt::MarukuTemplate`
|
46
|
+
|
22
47
|
<a name='erb'></a>
|
23
48
|
ERB (`erb`, `rhtml`)
|
24
49
|
--------------------
|
25
50
|
|
26
|
-
|
51
|
+
ERB is a simple but powerful template languge for Ruby. In Tilt it's backed by
|
52
|
+
[Erubis](#erubis) (if installed on your system) or by [erb.rb](#erbrb) (which
|
53
|
+
is included in Ruby's standard library). This documentation applies to both
|
54
|
+
implementations.
|
27
55
|
|
28
56
|
### Example
|
29
57
|
|
30
58
|
Hello <%= world %>!
|
31
|
-
|
59
|
+
|
32
60
|
### Usage
|
33
61
|
|
34
|
-
|
35
|
-
`.rhtml` by default. ERB templates support custom evaluation scopes and locals:
|
62
|
+
ERB templates support custom evaluation scopes and locals:
|
36
63
|
|
37
64
|
>> require 'erb'
|
38
|
-
>> template = Tilt.new('hello.html.erb'
|
39
|
-
=> #<Tilt::ERBTemplate @file='hello.html.erb'>
|
65
|
+
>> template = Tilt.new('hello.html.erb')
|
40
66
|
>> template.render(self, :world => 'World!')
|
41
67
|
=> "Hello World!"
|
42
68
|
|
43
|
-
Or, use
|
69
|
+
Or, use `Tilt['erb']` directly to process strings:
|
44
70
|
|
45
|
-
|
46
|
-
template = Tilt::ERBTemplate.new(nil, :trim => '<>') { "Hello <%= world %>!" }
|
71
|
+
template = Tilt['erb'].new { "Hello <%= world %>!" }
|
47
72
|
template.render(self, :world => 'World!')
|
48
73
|
|
74
|
+
### Options
|
75
|
+
|
76
|
+
#### `:trim => trim`
|
77
|
+
|
78
|
+
Omits newlines and spaces around certain lines (usually those that starts with
|
79
|
+
`<%` and ends with `%>`). There isn't a specification for how trimming in ERB
|
80
|
+
should work, so if you need more control over the whitespace, you should use
|
81
|
+
[erb.rb](#erbrb) or [Erubis](#erubis) directly.
|
82
|
+
|
83
|
+
|
84
|
+
#### `:outvar => '_erbout'`
|
85
|
+
|
86
|
+
The name of the variable used to accumulate template output. This can be
|
87
|
+
any valid Ruby expression but must be assignable. By default a local
|
88
|
+
variable named `_erbout` is used.
|
89
|
+
|
90
|
+
<a name='erbrb'></a>
|
91
|
+
erb.rb (`erb`, `rhtml`)
|
92
|
+
-----------------------
|
93
|
+
|
94
|
+
[ERB](#erb) implementation available in Ruby's standard library.
|
95
|
+
|
96
|
+
All the documentation of [ERB](#erb) applies in addition to the following:
|
97
|
+
|
98
|
+
### Usage
|
99
|
+
|
100
|
+
The `Tilt::ERBTemplate` class is registered for all files ending in `.erb` or
|
101
|
+
`.rhtml` by default, but with a *lower* priority than ErubisTemplate. If you
|
102
|
+
specifically want to use ERB, it's recommended to use `#prefer`:
|
103
|
+
|
104
|
+
Tilt.prefer Tilt::ERBTemplate
|
105
|
+
|
49
106
|
__NOTE:__ It's suggested that your program `require 'erb'` at load time when
|
50
107
|
using this template engine within a threaded environment.
|
51
108
|
|
52
109
|
### Options
|
53
110
|
|
54
|
-
#### `:trim =>
|
111
|
+
#### `:trim => true`
|
55
112
|
|
56
|
-
The ERB trim mode flags. This is a string consisting
|
57
|
-
|
113
|
+
The ERB trim mode flags. This is a string consisting of any combination of the
|
114
|
+
following characters:
|
58
115
|
|
59
116
|
* `'>'` omits newlines for lines ending in `>`
|
60
117
|
* `'<>'` omits newlines for lines starting with `<%` and ending in `%>`
|
61
|
-
* `'-'` omits newlines for lines ending in `-%>`.
|
62
118
|
* `'%'` enables processing of lines beginning with `%`
|
119
|
+
* `true` is an alias of `<>`
|
63
120
|
|
64
121
|
#### `:safe => nil`
|
65
122
|
|
@@ -78,18 +135,23 @@ variable named `_erbout` is used.
|
|
78
135
|
|
79
136
|
|
80
137
|
<a name='erubis'></a>
|
81
|
-
Erubis (`erubis`)
|
82
|
-
|
138
|
+
Erubis (`erb`, `rhtml`, `erubis`)
|
139
|
+
---------------------------------
|
83
140
|
|
84
|
-
Erubis is a fast, secure, and very extensible implementation of
|
141
|
+
[Erubis][erubis] is a fast, secure, and very extensible implementation of [ERB](#erb).
|
142
|
+
|
143
|
+
All the documentation of [ERB](#erb) applies in addition to the following:
|
85
144
|
|
86
145
|
### Usage
|
87
146
|
|
88
|
-
|
89
|
-
|
147
|
+
The `Tilt::ErubisTemplate` class is registered for all files ending in `.erb` or
|
148
|
+
`.rhtml` by default, but with a *higher* priority than `ERBTemplate`. If you
|
149
|
+
specifically want to use Erubis, it's recommended to use `#prefer`:
|
150
|
+
|
151
|
+
Tilt.prefer Tilt::ErubisTemplate
|
90
152
|
|
91
|
-
|
92
|
-
|
153
|
+
__NOTE:__ It's suggested that your program `require 'erubis'` at load time when
|
154
|
+
using this template engine within a threaded environment.
|
93
155
|
|
94
156
|
### Options
|
95
157
|
|
@@ -114,30 +176,26 @@ variable named `_erbout` is used.
|
|
114
176
|
|
115
177
|
Set pattern for embedded Ruby code.
|
116
178
|
|
117
|
-
See the [ERB](#erb) template documentation for examples, usage, and options.
|
118
|
-
|
119
179
|
#### `:trim => true`
|
120
180
|
|
121
|
-
Delete spaces around
|
181
|
+
Delete spaces around `<% %>`. (But, spaces around `<%= %>` are preserved.)
|
122
182
|
|
123
183
|
### See also
|
124
184
|
|
125
|
-
* [Erubis Home]
|
185
|
+
* [Erubis Home][erubis]
|
126
186
|
* [Erubis User's Guide](http://www.kuwata-lab.com/erubis/users-guide.html)
|
127
187
|
|
128
|
-
__NOTE:__ It's suggested that your program `require 'erubis'` at load time when
|
129
|
-
using this template engine within a threaded environment.
|
130
188
|
|
131
189
|
<a name='haml'></a>
|
132
190
|
Haml (`haml`)
|
133
191
|
-------------
|
134
192
|
|
135
|
-
Haml is a markup language that’s used to cleanly and simply describe
|
136
|
-
any web document without the use of inline code. Haml functions as
|
137
|
-
for inline page templating systems such as PHP, ASP, and ERB, the
|
138
|
-
language used in most Ruby on Rails applications. However, Haml
|
139
|
-
need for explicitly coding HTML into the template, because it itself
|
140
|
-
description of the HTML, with some code to generate dynamic content.
|
193
|
+
[Haml][haml] is a markup language that’s used to cleanly and simply describe
|
194
|
+
the HTML of any web document without the use of inline code. Haml functions as
|
195
|
+
a replacement for inline page templating systems such as PHP, ASP, and ERB, the
|
196
|
+
templating language used in most Ruby on Rails applications. However, Haml
|
197
|
+
avoids the need for explicitly coding HTML into the template, because it itself
|
198
|
+
is a description of the HTML, with some code to generate dynamic content.
|
141
199
|
([more](http://haml-lang.com/about.html))
|
142
200
|
|
143
201
|
|
@@ -184,74 +242,21 @@ using this template engine within a threaded environment.
|
|
184
242
|
|
185
243
|
### Options
|
186
244
|
|
187
|
-
|
188
|
-
|
189
|
-
Determines the output format. The default is `:xhtml`. Other options are
|
190
|
-
`:html4` and `:html5`, which are identical to `:xhtml` except there are no
|
191
|
-
self-closing tags, the XML prolog is ignored and correct DOCTYPEs are generated.
|
192
|
-
|
193
|
-
#### `:escape_html => false`
|
194
|
-
|
195
|
-
Sets whether or not to escape HTML-sensitive characters in script. If this is
|
196
|
-
true, `=` behaves like `&=;` otherwise, it behaves like `!=`. Note that if this
|
197
|
-
is set, `!=` should be used for yielding to subtemplates and rendering partials.
|
198
|
-
Defaults to false.
|
199
|
-
|
200
|
-
#### `:ugly => false`
|
201
|
-
|
202
|
-
If set to true, Haml makes no attempt to properly indent or format the HTML
|
203
|
-
output. This causes the rendering to be done much quicker than it would
|
204
|
-
otherwise, but makes viewing the source unpleasant. Defaults to false.
|
205
|
-
|
206
|
-
#### `:suppress_eval => false`
|
207
|
-
|
208
|
-
Whether or not attribute hashes and Ruby scripts designated by `=` or `~` should
|
209
|
-
be evaluated. If this is true, said scripts are rendered as empty strings.
|
210
|
-
Defaults to false.
|
211
|
-
|
212
|
-
#### `:attr_wrapper => "'"`
|
213
|
-
|
214
|
-
The character that should wrap element attributes. This defaults to `'` (an
|
215
|
-
apostrophe). Characters of this type within the attributes will be escaped (e.g.
|
216
|
-
by replacing them with `'`) if the character is an apostrophe or a
|
217
|
-
quotation mark.
|
218
|
-
|
219
|
-
#### `:autoclose => %w[meta img link br hr input area param col base]`
|
220
|
-
|
221
|
-
A list of tag names that should be automatically self-closed if they have no
|
222
|
-
content. Defaults to `['meta', 'img', 'link', 'br', 'hr', 'input', 'area',
|
223
|
-
'param', 'col', 'base']`.
|
224
|
-
|
225
|
-
#### `:preserve => %w[textarea pre]`
|
226
|
-
|
227
|
-
A list of tag names that should automatically have their newlines preserved
|
228
|
-
using the `Haml::Helpers#preserve` helper. This means that any content given on
|
229
|
-
the same line as the tag will be preserved. For example, `%textarea= "Foo\nBar"`
|
230
|
-
compiles to `<textarea>Foo
Bar</textarea>`. Defaults to `['textarea',
|
231
|
-
'pre']`.
|
232
|
-
|
233
|
-
#### `:encoding => 'utf-8'`
|
234
|
-
|
235
|
-
The encoding to use for the HTML output. Only available in Ruby 1.9 or higher.
|
236
|
-
This can be a string or an Encoding Object. Note that Haml does not
|
237
|
-
automatically re-encode Ruby values; any strings coming from outside the
|
238
|
-
application should be converted before being passed into the Haml template.
|
239
|
-
Defaults to `Encoding.default_internal` or, if that's not set, `"utf-8"`.
|
245
|
+
Please see the [Haml Reference](http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#options) for all available options.
|
240
246
|
|
241
247
|
### See also
|
242
248
|
|
243
249
|
* [#haml.docs](http://haml-lang.com/docs.html)
|
244
250
|
* [Haml Tutorial](http://haml-lang.com/tutorial.html)
|
245
251
|
* [Haml Reference](http://haml-lang.com/docs/yardoc/HAML_REFERENCE.md.html)
|
246
|
-
* [Whitespace Preservation](http://haml-lang.com/docs/yardoc/HAML_REFERENCE.md.html#whitespace_preservation)
|
247
252
|
|
248
253
|
|
249
254
|
<a name='liquid'></a>
|
250
255
|
Liquid (`liquid`)
|
251
256
|
-----------------
|
252
257
|
|
253
|
-
Liquid is for rendering safe templates which cannot affect the
|
254
|
-
of the server they are rendered on.
|
258
|
+
[Liquid][liquid] is for rendering safe templates which cannot affect the
|
259
|
+
security of the server they are rendered on.
|
255
260
|
|
256
261
|
### Example
|
257
262
|
|
@@ -289,7 +294,7 @@ default. Liquid templates support locals and objects that respond to
|
|
289
294
|
Or, use `Tilt::LiquidTemplate` directly to process strings:
|
290
295
|
|
291
296
|
>> require 'haml'
|
292
|
-
>> template = Tilt::
|
297
|
+
>> template = Tilt::LiquidTemplate.new { "<h1>Hello Liquid!</h1>" }
|
293
298
|
=> #<Tilt::LiquidTemplate @file=nil ...>
|
294
299
|
>> template.render
|
295
300
|
=> "<h1>Hello Liquid!</h1>"
|
@@ -303,137 +308,207 @@ time when using this template engine within a threaded environment.
|
|
303
308
|
* [Liquid Docs](http://liquid.rubyforge.org/)
|
304
309
|
* GitHub: [tobi/liquid](http://github.com/tobi/liquid/)
|
305
310
|
|
306
|
-
<a name='markdown'></a>
|
307
|
-
Markdown (`markdown`, `md`, `mkd`)
|
308
|
-
----------------------------------
|
309
311
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
Markdown formatted texts are readable.
|
312
|
+
<a name='radius'></a>
|
313
|
+
Radius (`radius`)
|
314
|
+
-----------------
|
314
315
|
|
315
|
-
|
316
|
-
|
316
|
+
[Radius][radius] is the template language used by [Radiant CMS][radiant]. It is
|
317
|
+
a tag language designed to be valid XML/HTML.
|
317
318
|
|
318
319
|
### Example
|
319
320
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
321
|
+
<html>
|
322
|
+
<body>
|
323
|
+
<h1><r:title /></h1>
|
324
|
+
<ul class="<r:type />">
|
325
|
+
<r:repeat times="3">
|
326
|
+
<li><r:hello />!</li>
|
327
|
+
</r:repeat>
|
328
|
+
</ul>
|
329
|
+
<r:yield />
|
330
|
+
</body>
|
331
|
+
</html>
|
324
332
|
|
325
333
|
### Usage
|
326
334
|
|
327
|
-
To
|
335
|
+
To render a template such as the one above.
|
328
336
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
"<!doctype html><title></title>{%= yield %}"
|
333
|
-
end
|
334
|
-
data = Tilt::RDiscountTemplate.new { "# hello tilt" }
|
335
|
-
layout.render { data.render }
|
336
|
-
# => "<!doctype html><title></title><h1>hello tilt</h1>\n"
|
337
|
+
scope = OpenStruct.new
|
338
|
+
scope.title = "Radius Example"
|
339
|
+
scope.hello = "Hello, World!"
|
337
340
|
|
338
|
-
|
339
|
-
|
341
|
+
require 'radius'
|
342
|
+
template = Tilt::RadiusTemplate.new('example.radius', :tag_prefix=>'r')
|
343
|
+
template.render(scope, :type=>'hlist'){ "Jackpot!" }
|
340
344
|
|
341
|
-
|
345
|
+
The result will be:
|
346
|
+
|
347
|
+
<html>
|
348
|
+
<body>
|
349
|
+
<h1>Radius Example</h1>
|
350
|
+
<ul class="hlist">
|
351
|
+
<li>Hello, World!</li>
|
352
|
+
<li>Hello, World!</li>
|
353
|
+
<li>Hello, World!</li>
|
354
|
+
</ul>
|
355
|
+
Jackpot!
|
356
|
+
</body>
|
357
|
+
</html>
|
342
358
|
|
343
|
-
|
359
|
+
### See also
|
344
360
|
|
345
|
-
|
361
|
+
* [Radius][radius]
|
362
|
+
* [Radiant CMS][radiant]
|
346
363
|
|
347
|
-
Set `true` to enable [Smarty Pants](http://daringfireball.net/projects/smartypants/)
|
348
|
-
style punctuation replacement.
|
349
364
|
|
350
|
-
|
365
|
+
<a name='textile'></a>
|
366
|
+
Textile (`textile`)
|
367
|
+
-------------------
|
351
368
|
|
352
|
-
|
353
|
-
|
369
|
+
Textile is a lightweight markup language originally developed by Dean Allen and
|
370
|
+
billed as a "humane Web text generator". Textile converts its marked-up text
|
371
|
+
input to valid, well-formed XHTML and also inserts character entity references
|
372
|
+
for apostrophes, opening and closing single and double quotation marks,
|
373
|
+
ellipses and em dashes.
|
354
374
|
|
355
|
-
|
375
|
+
Textile formatted texts are converted to HTML with the [RedCloth][redcloth]
|
376
|
+
engine, which is a Ruby extension written in C.
|
356
377
|
|
357
|
-
|
358
|
-
* GitHub: [rtomayko/rdiscount][rdiscount]
|
378
|
+
### Example
|
359
379
|
|
360
|
-
|
361
|
-
|
362
|
-
|
380
|
+
h1. Hello Textile Templates
|
381
|
+
|
382
|
+
Hello World. This is a paragraph.
|
383
|
+
|
384
|
+
### Usage
|
385
|
+
|
386
|
+
__NOTE:__ It's suggested that your program `require 'redcloth'` at load time
|
387
|
+
when using this template engine in a threaded environment.
|
388
|
+
|
389
|
+
### See Also
|
390
|
+
|
391
|
+
* [RedCloth][redcloth]
|
363
392
|
|
364
393
|
|
365
394
|
<a name='rdoc'></a>
|
366
395
|
RDoc (`rdoc`)
|
367
396
|
-------------
|
368
397
|
|
369
|
-
RDoc is the simple text markup system that comes with Ruby's standard
|
398
|
+
[RDoc][rdoc] is the simple text markup system that comes with Ruby's standard
|
370
399
|
library.
|
371
400
|
|
401
|
+
### Example
|
402
|
+
|
403
|
+
= Hello RDoc Templates
|
404
|
+
|
405
|
+
Hello World. This is a paragraph.
|
406
|
+
|
372
407
|
### Usage
|
373
408
|
|
374
409
|
__NOTE:__ It's suggested that your program `require 'rdoc/markup'` and
|
375
410
|
`require 'rdoc/markup/to_html'` at load time when using this template
|
376
411
|
engine in a threaded environment.
|
377
412
|
|
378
|
-
###
|
413
|
+
### See also
|
379
414
|
|
380
|
-
|
415
|
+
* [RDoc][rdoc]
|
381
416
|
|
382
|
-
Hello World. This is a paragraph.
|
383
417
|
|
384
|
-
|
418
|
+
<a name='markdown'></a>
|
419
|
+
Markdown (`markdown`, `md`, `mkd`)
|
420
|
+
----------------------------------
|
385
421
|
|
386
|
-
|
422
|
+
[Markdown][markdown] is a lightweight markup language, created by John Gruber
|
423
|
+
and Aaron Swartz. For any markup that is not covered by Markdown’s syntax, HTML
|
424
|
+
is used. Marking up plain text with Markdown markup is easy and Markdown
|
425
|
+
formatted texts are readable.
|
387
426
|
|
427
|
+
Markdown formatted texts are converted to HTML with one of these libraries:
|
388
428
|
|
389
|
-
|
390
|
-
|
391
|
-
|
429
|
+
* [RDiscount](#rdiscount) - `Tilt::RDiscountTemplate`
|
430
|
+
* BlueCloth - `Tilt::BlueClothTemplate`
|
431
|
+
* Kramdown - `Tilt::KramdownTemplate`
|
432
|
+
* Maruku - `Tilt::MarukuTemplate`
|
392
433
|
|
393
|
-
|
394
|
-
|
434
|
+
Tilt will use fallback mode (as documented in the README) for determining which
|
435
|
+
library to use. RDiscount has highest priority - Maruku has lowest.
|
395
436
|
|
396
437
|
### Example
|
397
438
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
<r:repeat times="3">
|
403
|
-
<li><r:hello />!</li>
|
404
|
-
</r:repeat>
|
405
|
-
</ul>
|
406
|
-
<r:yield />
|
407
|
-
</body>
|
408
|
-
</html>
|
439
|
+
Hello Markdown Templates
|
440
|
+
========================
|
441
|
+
|
442
|
+
Hello World. This is a paragraph.
|
409
443
|
|
410
444
|
### Usage
|
411
445
|
|
412
|
-
To
|
446
|
+
To wrap a Markdown formatted document with a layout:
|
413
447
|
|
414
|
-
|
415
|
-
|
416
|
-
|
448
|
+
layout = Tilt['erb'].new do
|
449
|
+
"<!doctype html><title></title><%= yield %>"
|
450
|
+
end
|
451
|
+
data = Tilt['md'].new { "# hello tilt" }
|
452
|
+
layout.render { data.render }
|
453
|
+
# => "<!doctype html><title></title><h1>hello tilt</h1>\n"
|
417
454
|
|
418
|
-
|
419
|
-
template = Tilt::RadiusTemplate.new('example.radius', :tag_prefix=>'r')
|
420
|
-
template.render(scope, :type=>'hlist'){ "Jackpot!" }
|
455
|
+
### Options
|
421
456
|
|
422
|
-
|
457
|
+
Every implementation of Markdown *should* support these options, but there are
|
458
|
+
some known problems with the Kramdown and Maruku engines.
|
423
459
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
</body>
|
434
|
-
</html>
|
460
|
+
#### `:smartypants => true|false`
|
461
|
+
|
462
|
+
Set `true` to enable [Smarty Pants][smartypants]
|
463
|
+
style punctuation replacement.
|
464
|
+
|
465
|
+
#### `:escape_html => true|false`
|
466
|
+
|
467
|
+
Set `true` disallow raw HTML in Markdown contents. HTML is converted to
|
468
|
+
literal text by escaping `<` characters.
|
435
469
|
|
436
470
|
### See also
|
437
471
|
|
438
|
-
* [
|
439
|
-
|
472
|
+
* [Markdown Syntax Documentation](http://daringfireball.net/projects/markdown/syntax/)
|
473
|
+
|
474
|
+
<a name='rdiscount'></a>
|
475
|
+
RDiscount (`markdown`, `md`, `mkd`)
|
476
|
+
-----------------------------------
|
477
|
+
|
478
|
+
[Discount][discount] is an implementation of the Markdown markup language in C.
|
479
|
+
[RDiscount][rdiscount] is a Ruby wrapper around Discount.
|
480
|
+
|
481
|
+
All the documentation of [Markdown](#markdown) applies in addition to the following:
|
482
|
+
|
483
|
+
### Usage
|
484
|
+
|
485
|
+
The `Tilt::RDiscountTemplate` class is registered for all files ending in
|
486
|
+
`.markdown`, `.md` or `.mkd` by default with the highest priority. If you
|
487
|
+
specifically want to use RDiscount, it's recommended to use `#prefer`:
|
488
|
+
|
489
|
+
Tilt.prefer Tilt::RDiscountTemplate
|
490
|
+
|
491
|
+
__NOTE:__ It's suggested that your program `require 'erubis'` at load time when
|
492
|
+
using this template engine within a threaded environment.
|
493
|
+
|
494
|
+
### See also
|
495
|
+
|
496
|
+
* [Discount][discount]
|
497
|
+
* [RDiscount][rdiscount]
|
498
|
+
* GitHub: [rtomayko/rdiscount][rdiscount]
|
499
|
+
|
500
|
+
|
501
|
+
[lesscss]: http://lesscss.org/ "Less CSS"
|
502
|
+
[sass]: http://sass-lang.com/ "Sass"
|
503
|
+
[coffee-script]: http://jashkenas.github.com/coffee-script/ "Coffee Script"
|
504
|
+
[erubis]: http://www.kuwata-lab.com/erubis/ "Erubis"
|
505
|
+
[haml]: http://haml-lang.org/ "Haml"
|
506
|
+
[liquid]: http://www.liquidmarkup.org/ "Liquid"
|
507
|
+
[radius]: http://radius.rubyforge.org/ "Radius"
|
508
|
+
[radiant]: http://radiantcms.org/ "Radiant CMS"
|
509
|
+
[redcloth]: http://redcloth.org/ "RedCloth"
|
510
|
+
[rdoc]: http://rdoc.rubyforge.org/ "RDoc"
|
511
|
+
[discount]: http://www.pell.portland.or.us/~orc/Code/discount/ "Discount"
|
512
|
+
[rdiscount]: http://github.com/rtomayko/rdiscount/ "RDiscount"
|
513
|
+
[smartypants]: http://daringfireball.net/projects/smartypants/ "Smarty Pants"
|
514
|
+
|