11'use strict' ;
22
3+ var jade = require ( 'jade' ) ;
4+ var extend = require ( 'xtend' ) ;
35var through = require ( 'through2' ) ;
46var ext = require ( 'gulp-util' ) . replaceExtension ;
57var PluginError = require ( 'gulp-util' ) . PluginError ;
68
9+ function handleCompile ( contents , opts ) {
10+ if ( opts . client ) {
11+ return opts . compileClient ( contents , opts ) ;
12+ }
713
8- module . exports = function ( options ) {
9- var opts = options || { } ;
10- var jade = opts . jade || require ( 'jade' ) ;
11- var compile = jade . compile ;
12- var compileClient = jade . compileClient ;
13-
14- function handleCompile ( contents ) {
15- if ( opts . client ) {
16- return compileClient ( contents , opts ) ;
17- }
14+ return opts . compile ( contents , opts ) ( opts . locals || opts . data ) ;
15+ }
1816
19- return compile ( contents , opts ) ( opts . locals || opts . data ) ;
17+ function handleExtension ( filepath , opts ) {
18+ if ( opts . client ) {
19+ return ext ( filepath , '.js' ) ;
2020 }
21+ return ext ( filepath , '.html' ) ;
22+ }
2123
22- function handleExtension ( filepath ) {
23- if ( opts . client ) {
24- return ext ( filepath , '.js' ) ;
25- }
26- return ext ( filepath , '.html' ) ;
27- }
24+ module . exports = function ( options ) {
25+ options = options || { } ;
26+ var opts = extend ( options , {
27+ compile : ( options . jade || jade ) . compile ,
28+ compileClient : ( options . jade || jade ) . compileClient
29+ } ) ;
2830
2931 function CompileJade ( file , enc , cb ) {
3032 opts . filename = file . path ;
@@ -33,7 +35,7 @@ module.exports = function(options){
3335 opts . data = file . data ;
3436 }
3537
36- file . path = handleExtension ( file . path ) ;
38+ file . path = handleExtension ( file . path , opts ) ;
3739
3840 if ( file . isStream ( ) ) {
3941 return cb ( new PluginError ( 'gulp-jade' , 'Streaming not supported' ) ) ;
0 commit comments