2
2
var Promise = require ( 'native-or-bluebird' )
3
3
var resolve = require ( 'path' ) . resolve
4
4
var extname = require ( 'path' ) . extname
5
+ var assert = require ( 'assert' )
5
6
var fs = require ( 'fs' )
6
7
7
8
Templation . engines = require ( './engines' )
@@ -23,8 +24,8 @@ function Templation(options) {
23
24
}
24
25
25
26
Templation . prototype . use = function ( ext , engine ) {
27
+ assert ( engine , 'no engine defined' )
26
28
if ( typeof ext !== 'string' ) throw new TypeError ( 'each engine must map to an extension' )
27
- if ( ! engine ) throw new Error ( 'no engine defined' )
28
29
if ( typeof engine . compile !== 'function' ) throw new TypeError ( 'each engine must define a .compile()' )
29
30
if ( typeof engine . render !== 'function' ) throw new TypeError ( 'each engine must define a .render()' )
30
31
this . engines [ ext ] = engine
@@ -43,7 +44,7 @@ Templation.prototype.render = function (name, options, fn) {
43
44
return self . _render ( compiled . __templation_engine , compiled , options )
44
45
} )
45
46
. then ( validateOutput )
46
-
47
+
47
48
if ( typeof fn === 'function' ) {
48
49
promise . then ( function ( out ) {
49
50
fn ( null , out )
@@ -61,8 +62,7 @@ Templation.prototype._lookup = function (name) {
61
62
var engine
62
63
63
64
if ( ext ) {
64
- engine = engines [ ext ]
65
- if ( ! engine ) throw new Error ( 'no view engine found for: ' + ext )
65
+ assert ( engine = engines [ ext ] , 'no view engine found for: ' + ext )
66
66
return [ filename , engine ]
67
67
}
68
68
0 commit comments