buildjs / rigger

Javascript file parser and include engine
http://buildjs.github.io/rigger
60 stars 15 forks source link

recursive includes #31

Open Enkil opened 9 years ago

Enkil commented 9 years ago

Hi! Thanx for this great lib

I have some problems

Rigger should to normally works with recursive includes, but not for me

I have next file structures

/file.html /folder1/file1.html /folder/file2.html

in /file.html I wrote //= folder1/file1.html

in folder1/file1.html I wrote //= file2.html

and catch the problem

buffer.js:68
    throw new TypeError('must start with number, buffer, array or string');
          ^
TypeError: must start with number, buffer, array or string
    at new Buffer (buffer.js:68:11)
    at /Users/itimohin/Documents/CLOUD_STORAGES/OneDrive/PHPStorm-Projects/template-frontend/node_modules/gulp-rigger/index.js:20:29
    at Rigger.<anonymous> (/Users/itimohin/Documents/CLOUD_STORAGES/OneDrive/PHPStorm-Projects/template-frontend/node_modules/gulp-rigger/node_modules/rigger/index.js:719:9)
    at Rigger.emit (events.js:107:17)
    at /Users/itimohin/Documents/CLOUD_STORAGES/OneDrive/PHPStorm-Projects/template-frontend/node_modules/gulp-rigger/node_modules/rigger/index.js:252:16
    at /Users/itimohin/Documents/CLOUD_STORAGES/OneDrive/PHPStorm-Projects/template-frontend/node_modules/gulp-rigger/node_modules/rigger/node_modules/async/lib/async.js:232:13
    at /Users/itimohin/Documents/CLOUD_STORAGES/OneDrive/PHPStorm-Projects/template-frontend/node_modules/gulp-rigger/node_modules/rigger/node_modules/async/lib/async.js:113:21
    at /Users/itimohin/Documents/CLOUD_STORAGES/OneDrive/PHPStorm-Projects/template-frontend/node_modules/gulp-rigger/node_modules/rigger/node_modules/async/lib/async.js:24:16
    at /Users/itimohin/Documents/CLOUD_STORAGES/OneDrive/PHPStorm-Projects/template-frontend/node_modules/gulp-rigger/node_modules/rigger/node_modules/async/lib/async.js:229:17
    at /Users/itimohin/Documents/CLOUD_STORAGES/OneDrive/PHPStorm-Projects/template-frontend/node_modules/gulp-rigger/node_modules/rigger/index.js:391:21

also I tried to write //= ./file2.html but result was just like this

Can you help me?

Thank you

DamonOehlman commented 9 years ago

Thanks for reporting the problem. I will update the tests to include new node versions (0.12, iojs) etc, as it's possible that it's related to that. Will try and take a look at that tonight or over the weekend.

Enkil commented 9 years ago

Thanx! I hope all will be good

DamonOehlman commented 9 years ago

@Enkil I had a look at this on the weekend (updating tests to cover 0.12 and iojs), and I think part of the problem was that you were including including html flies. Was this what you intended?

If it was I did have a look at how hard it would be to add support for including HTML files in the same way as JS files are done, and it turns out it wasn't too hard (see this test).

This code only exists in the master branch of rigger at the moment (but can be installed fairly easily by doing npm install buildjs/rigger), so if you'd like to take it for a spin then go for it :)

One thing to note is that only whole line includes are parsed and replaced by rigger, and the following would not be modified by rigger:

<title><!--= title.html --></title>