buildjs / rigger

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

Support for Include Variables #5

Open DamonOehlman opened 12 years ago

DamonOehlman commented 12 years ago

I would like to have the ability to use "bake style" variables in the include statements. This would allow for extending a particular package types functionality with platform specific implementations. For instance, you could easily include some additional functionality for the commonjs implementation.

giannif commented 11 years ago

Not exactly sure what you mean by "bake style", but I'd like to be able to pass variables to the include statements.

Let's say you specify the values in a data option:

rig: {
            devel: {
                options:{
                    data:{
                       source:"src/include1.js",
                       otherSource:"src/include2"
                    }
                }
                files:....

And then in the rigged files use those vars.

//= source
//= otherSource

Perhaps they are preceded with:

//=data source

I attempted to do this in a plugin, but the plugins don't have access to options, I don't think.

Any ideas?

giannif commented 11 years ago

I forked the grunt-rigger project and changed what I needed in the rig function. https://github.com/giannif/grunt-rigger/commit/81f0205a3f9af72f61c3e5743af66ade1ca9b2c5

An example rig config using the processContent (probably not the best name for this option):

rig: {
            options:{
                processContent:true
            },
            project1: {
                options: {
                    data: {
                        content: "project1.js"
                    }
                },
                files: {
                    "dist/project1.js": "src/main.js"
                }
            },
            project2: {
                options: {
                    data: {
                        content: "project2.js"
                    }
                },
                files: {
                    "dist/project2.js": "src/main.js"
                }
            }
        },

Then in src/main.js

(function(){
// main.js stuff....
//= <%= content %>
// other main.js stuff
})();

Let me know what you think. Or if there's an easier way to do this that I'm totally missing.

DamonOehlman commented 11 years ago

@giannif I'll take a look at this in the next couple of days. Sorry I didn't respond earlier, I don't seem to be getting emails for this repo at the moment. Will investigate that too...