@@ -15,20 +15,26 @@ module.exports = Documentify
1515
1616var defaultHtml = '<!DOCTYPE html><html><head></head><body></body></html>'
1717
18+ function isStream ( maybe ) {
19+ return maybe !== null && typeof maybe === 'object' && typeof maybe . pipe === 'function'
20+ }
21+
1822function Documentify ( entry , html , opts ) {
1923 if ( ! ( this instanceof Documentify ) ) return new Documentify ( entry , html , opts )
2024
2125 EventEmitter . call ( this )
2226
23- assert . equal ( typeof entry , 'string' , 'documentify: entry should be type string' )
27+ if ( entry ) {
28+ assert . equal ( typeof entry , 'string' , 'documentify: entry should be type string' )
29+ }
2430
25- if ( typeof html === 'object' ) {
31+ if ( typeof html === 'object' && ! isStream ( html ) ) {
2632 opts = html
2733 html = null
2834 }
2935
30- if ( html ) {
31- assert . equal ( typeof html , 'string' , 'documentify: html should be type string' )
36+ if ( html && ! isStream ( html ) ) {
37+ assert . equal ( typeof html , 'string' , 'documentify: html should be type string or stream ' )
3238 }
3339
3440 opts = opts || { }
@@ -119,7 +125,7 @@ Documentify.prototype.bundle = function () {
119125 return pts
120126
121127 function findTransforms ( done ) {
122- var entry = path . join ( path . dirname ( self . entry ) , path . basename ( self . entry ) )
128+ var entry = self . entry ? path . join ( path . dirname ( self . entry ) , path . basename ( self . entry ) ) : self . basedir
123129 findup ( entry , 'package.json' , function ( err , pathname ) {
124130 // no package.json found - just run local transforms
125131 if ( err ) return done ( )
@@ -163,8 +169,8 @@ Documentify.prototype.bundle = function () {
163169 }
164170
165171 function createSource ( done ) {
166- if ( typeof self . html === 'string' ) {
167- source = fromString ( self . html )
172+ if ( typeof self . html === 'string' || isStream ( self . html ) ) {
173+ source = isStream ( self . html ) ? self . html : fromString ( self . html )
168174 return done ( )
169175 }
170176 resolve ( self . entry , { extensions : [ '.html' ] } , function ( err , entry ) {
0 commit comments