tilt 1.2.2 → 1.3.1

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.
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 REQUIRED LIBRARIES
25
- -------------------------- ----------------- ----------------------------
26
- ERB .erb none (included ruby stdlib)
27
- Interpolated String .str none (included ruby core)
28
- Haml .haml haml
29
- Sass .sass haml
30
- Less CSS .less less
31
- Builder .builder builder
32
- Liquid .liquid liquid
33
- RDiscount .markdown rdiscount
34
- RedCloth .textile redcloth
35
- RDoc .rdoc rdoc
36
- Radius .radius radius
37
- Markaby .mab markaby
38
- Nokogiri .nokogiri nokogiri
39
- CoffeeScript .coffee coffee-script (+node coffee)
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', Tilt::ERBTemplate
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', Tilt::ErubisTemplate
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
- `Tilt::register` can also be used to select between alternative template
151
- engines. To use Erubis instead of ERB for `.erb` files:
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
- Tilt.register 'erb', Tilt::ErubisTemplate
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
- Or, use BlueCloth for markdown instead of RDiscount:
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
- Tilt.register 'markdown', Tilt::BlueClothTemplate
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
  -------