tilt 1.2.2 → 1.3.3

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.
Files changed (43) hide show
  1. data/Gemfile +2 -0
  2. data/README.md +59 -24
  3. data/TEMPLATES.md +252 -175
  4. data/lib/tilt/builder.rb +40 -0
  5. data/lib/tilt/coffee.rb +50 -0
  6. data/lib/tilt/css.rb +72 -0
  7. data/lib/tilt/erb.rb +110 -0
  8. data/lib/tilt/haml.rb +64 -0
  9. data/lib/tilt/liquid.rb +41 -0
  10. data/lib/tilt/markaby.rb +52 -0
  11. data/lib/tilt/markdown.rb +190 -0
  12. data/lib/tilt/nokogiri.rb +43 -0
  13. data/lib/tilt/radius.rb +51 -0
  14. data/lib/tilt/rdoc.rb +32 -0
  15. data/lib/tilt/string.rb +21 -0
  16. data/lib/tilt/template.rb +285 -0
  17. data/lib/tilt/textile.rb +25 -0
  18. data/lib/tilt/wiki.rb +50 -0
  19. data/lib/tilt/yajl.rb +94 -0
  20. data/lib/tilt.rb +105 -816
  21. data/test/tilt_blueclothtemplate_test.rb +6 -25
  22. data/test/tilt_coffeescripttemplate_test.rb +32 -1
  23. data/test/tilt_compilesite_test.rb +1 -1
  24. data/test/tilt_creoletemplate_test.rb +28 -0
  25. data/test/tilt_erbtemplate_test.rb +18 -19
  26. data/test/tilt_erubistemplate_test.rb +12 -2
  27. data/test/tilt_fallback_test.rb +122 -0
  28. data/test/tilt_hamltemplate_test.rb +4 -4
  29. data/test/tilt_kramdown_test.rb +42 -0
  30. data/test/tilt_lesstemplate_test.rb +3 -2
  31. data/test/tilt_markdown_test.rb +161 -0
  32. data/test/tilt_marukutemplate_test.rb +48 -0
  33. data/test/tilt_nokogiritemplate_test.rb +11 -0
  34. data/test/tilt_radiustemplate_test.rb +3 -3
  35. data/test/tilt_rdiscounttemplate_test.rb +16 -6
  36. data/test/tilt_redcarpettemplate_test.rb +59 -0
  37. data/test/tilt_sasstemplate_test.rb +0 -1
  38. data/test/tilt_stringtemplate_test.rb +10 -3
  39. data/test/tilt_template_test.rb +6 -0
  40. data/test/tilt_wikiclothtemplate_test.rb +32 -0
  41. data/test/tilt_yajltemplate_test.rb +92 -0
  42. data/tilt.gemspec +39 -8
  43. metadata +276 -150
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/README.md CHANGED
@@ -21,28 +21,40 @@ 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) .wiki, .creole creole
47
+ WikiCloth (Wiki markup) .wiki, .mediawiki, .mw wikicloth
48
+ Yajl .yajl yajl-ruby
40
49
 
41
50
  These template engines ship with their own Tilt integration:
42
51
 
43
52
  ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
44
53
  -------------------------- ----------------- ----------------------------
45
54
  Slim .slim slim (>= 0.7)
55
+ Embedded JavaScript sprockets
56
+ Embedded CoffeeScript sprockets
57
+ JST sprockets
46
58
 
47
59
  See [TEMPLATES.md][t] for detailed information on template engine
48
60
  options and supported features.
@@ -116,7 +128,7 @@ classes based on those associations.
116
128
  The `Tilt::register` method associates a filename pattern with a specific
117
129
  template implementation. To use ERB for files ending in a `.bar` extension:
118
130
 
119
- >> Tilt.register 'bar', Tilt::ERBTemplate
131
+ >> Tilt.register Tilt::ERBTemplate, 'bar'
120
132
  >> Tilt.new('views/foo.bar')
121
133
  => #<Tilt::ERBTemplate @file="views/foo.bar" ...>
122
134
 
@@ -131,7 +143,7 @@ It's also possible to register template file mappings that are more specific
131
143
  than a file extension. To use Erubis for `bar.erb` but ERB for all other `.erb`
132
144
  files:
133
145
 
134
- >> Tilt.register 'bar.erb', Tilt::ErubisTemplate
146
+ >> Tilt.register Tilt::ErubisTemplate, 'bar.erb'
135
147
  >> Tilt.new('views/foo.erb')
136
148
  => Tilt::ERBTemplate
137
149
  >> Tilt.new('views/bar.erb')
@@ -147,14 +159,37 @@ mappings:
147
159
  3. `html.erb`
148
160
  4. `erb`
149
161
 
150
- `Tilt::register` can also be used to select between alternative template
151
- engines. To use Erubis instead of ERB for `.erb` files:
162
+ ### Fallback mode
163
+
164
+ If there are more than one template class registered for a file extension, Tilt
165
+ will automatically try to load the version that works on your machine:
166
+
167
+ 1. If any of the template engines has been loaded already: Use that one.
168
+ 2. If not, it will try to initialize each of the classes with an empty template.
169
+ 3. Tilt will use the first that doesn't raise an exception.
170
+ 4. If however *all* of them failed, Tilt will raise the exception of the first
171
+ template engine, since that was the most preferred one.
172
+
173
+ Template classes that were registered *last* would be tried first. Because the
174
+ Markdown extensions are registered like this:
175
+
176
+ Tilt.register Tilt::BlueClothTemplate, 'md'
177
+ Tilt.register Tilt::RDiscountTemplate, 'md'
178
+
179
+ Tilt will first try RDiscount and then BlueCloth. You could say that RDiscount
180
+ has a *higher priority* than BlueCloth.
152
181
 
153
- Tilt.register 'erb', Tilt::ErubisTemplate
182
+ The fallback mode works nicely when you just need to render an ERB or Markdown
183
+ template, but if you depend on a specific implementation, you should use #prefer:
154
184
 
155
- Or, use BlueCloth for markdown instead of RDiscount:
185
+ # Prefer BlueCloth for all its registered extensions (markdown, mkd, md)
186
+ Tilt.prefer Tilt::BlueClothTemplate
187
+
188
+ # Prefer Erubis for .erb only:
189
+ Tilt.prefer Tilt::ErubisTemplate, 'erb'
156
190
 
157
- Tilt.register 'markdown', Tilt::BlueClothTemplate
191
+ When a file extension has a preferred template class, Tilt will *always* use
192
+ that class, even if it raises an exception.
158
193
 
159
194
  Template Compilation
160
195
  --------------------
@@ -164,7 +199,7 @@ it on subsequent template invocations. Benchmarks show this yields a 5x-10x
164
199
  performance increase over evaluating the Ruby source on each invocation.
165
200
 
166
201
  Template compilation is currently supported for these template engines:
167
- StringTemplate, ERB, Erubis, Haml, and Builder.
202
+ StringTemplate, ERB, Erubis, Haml, Nokogiri, Builder and Yajl.
168
203
 
169
204
  LICENSE
170
205
  -------