Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/jupiterjs/steal
Browse files Browse the repository at this point in the history
Conflicts:
	build/build.js
  • Loading branch information
nafeger committed Nov 16, 2010
2 parents cf2096f + 91ef893 commit 7e9d1c2
Show file tree
Hide file tree
Showing 24 changed files with 24,797 additions and 23,002 deletions.
9 changes: 8 additions & 1 deletion build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ steal(function( steal ) {
Envjs(url, {
scriptTypes: {
"text/javascript": true,
"text/envjs": true
"text/envjs": true,
"": true
},
fireLoad: false,
logLevel: 2,
Expand All @@ -242,10 +243,16 @@ steal(function( steal ) {
},
afterInlineScriptLoad: function( script ) {
scripts.push(script);
<<<<<<< HEAD
},
onScriptLoadError: function(script) {
success = false;
}
=======
},
dontPrintUserAgent: true,
killTimersAfterLoad: true
>>>>>>> 91ef893af0ae5f931c2b76f6bbee871cb486de02
});
if (!success) {
java.lang.System.exit(-1);
Expand Down
74 changes: 0 additions & 74 deletions build/pluginify.js

This file was deleted.

45 changes: 45 additions & 0 deletions build/pluginify/parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
steal("//steal/build/pluginify/tokens").
plugins('steal/build').then(function(){

steal.build.parse = function(str){
//print("Breaking up strs")
var tokens = str.tokens('=<>!+-*&|/%^', '=<>&|'),
tokenNum = 0;

var moveNext = function(){
var next = tokens[tokenNum++];
if(next){
//print("Next TOken = "+next.value);
}
return next;
}

return {
moveNext : moveNext,
next : function(){
return tokens[tokenNum];
},
until: function(){
var token, matchCounts = [];
for(var i =0; i < arguments.length;i++){
matchCounts[i] =0;
if(typeof arguments[i] == "string"){
arguments[i] = [arguments[i]]
}
}
while (token = moveNext() ) {
for(var i =0; i< arguments.length; i++){
if(token.value == arguments[i][matchCounts[i]]){
matchCounts[i] = matchCounts[i]+1;
if(matchCounts[i] == arguments[i].length){
return token;
}
}else{
matchCounts[i] = 0;
}
}
}
}
}
};
})
182 changes: 182 additions & 0 deletions build/pluginify/pluginify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// usage:
// js steal\scripts\pluginify.js funcunit/functional -destination funcunit/dist/funcunit.js
// js steal\scripts\pluginify.js jquery/controller
// js steal\scripts\pluginify.js jquery/event/drag -exclude jquery/lang/vector/vector.js jquery/event/livehack/livehack.js
// load("steal/rhino/steal.js");

steal("//steal/build/pluginify/parse").plugins('steal/build/scripts').then(
function(s) {

/**
* Builds a 'steal-less' version of your application. To use this, files that use steal must
* have their code within a callback function.
* @param {Object} plugin
* @param {Object} opts
*/
s.build.pluginify = function( plugin, opts ) {
print(""+plugin+" >");
var jq = true,
othervar,
opts = steal.opts(opts, {
"destination": 1,
"exclude": -1,
"nojquery": 0,
"global" : 0
}),
destination = opts.destination || plugin + ".js";

opts.exclude = !opts.exclude ? [] : (steal.isArray(opts.exclude) ? opts.exclude : [opts.exclude]);

if ( opts.nojquery ) {
jq = false;
//othervar = opts.nojquery;
opts.exclude.push('jquery.js');
}
opts.exclude.push("steal/")
rhinoLoader = {
callback: function( s ) {
s.plugin(plugin);
}
};

steal.win().build_in_progress = true;

var pageSteal = steal.build.open("steal/rhino/empty.html").steal,
out = [],
str, i, inExclude = function( path ) {
for ( var i = 0; i < opts.exclude.length; i++ ) {
if ( path.indexOf(opts.exclude[i]) > -1 ) {
return true;
}
}
return false;
},
steals = pageSteal.total;

for ( i = 0; i < steals.length; i++ ) {
if(!inExclude(steals[i].path)){

var content = steal.build.pluginify.content(steals[i], opts.global ? opts.global : "jQuery" );
if(content){
print(" > "+steals[i].path)
out.push(content);
}
}
}
print("--> " + destination);
new steal.File(destination).save(out.join(";\n"));
//print("pluginified " + plugin)
};


//keeps track of which 'then' we are in with steal
var funcCount = {};

//gets content from a steal
s.build.pluginify.content = function(steal, param){
if(steal.func){
// if it's a function, go to the file it's in ... pull out the content
var index = funcCount[steal.path] || 0,
contents = readFile(steal.path);
//print("FOOO "+steal.path);
funcCount[steal.path]++;
return "("+s.build.pluginify.getFunction(contents, index)+")("+param+")";
}else{
var content = readFile(steal.path);
if( /steal[.\(]/.test(content) ){
return;
}
//make sure steal isn't in here
return content;
}
};
s.build.pluginify.getFunction = function(content, ith){

var p = s.build.parse(content),
token,
funcs = [];

while (token = p.moveNext() ) {
//print(token.value)
switch(token.value){
case "/" :
comment(p)
break;
case "steal" :
stealPull(p, content, function(func){
funcs.push(func)
});
break;
}
}
return funcs[ith||0];

};
//gets a function from steal
var stealPull = function(p, content, cb){
var token = p.next(),
startToken,
endToken;
if(!token || (token.value != "." && token.value != "(")){
// we said steal .. but we don't care
return;
}else{
p.moveNext();
}
if(token.value == "."){
p.until("(")
}
token = p.until("function",")");

if(token.value == "function"){

startToken = p.until("{");

endToken = nextBracket(p);
cb(content.substring(token.from, endToken.to))
//print("CONTENT\n"+ );
p.moveNext();
}else{

}
stealPull(p,content, cb );

},
//moves across a comment
comment = function(p){ //we don't really need this anymore
var n =p.next()
if(n.value == "*" && n.value != 'string'){
p.until(["*","/"])
}
},
//gets the next bracket
nextBracket = function(p){
var count = 1, token, last, prev;
while(token = p.moveNext()){
//print(token.value)
if(token.type == 'operator'){
switch(token.value){
case "{":

count++;
//print(" +"+count+" "+prev+" "+last)
break;
case "}" :

count--;
//print(" -"+count+" "+prev+" "+last)
if(count === 0){
return token;
}
break;
case "/" :
comment(p);
break;
}
}

prev = last;
last = (token.value)
}
}
});
8 changes: 8 additions & 0 deletions build/pluginify/test/firstFunc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function(abc){
(function(){});
"abc(){};";
/* steal */
// steal

boom
}
46 changes: 46 additions & 0 deletions build/pluginify/test/pluginify_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// load('steal/compress/test/run.js')
/**
* Tests compressing a very basic page and one that is using steal
*/
load('steal/rhino/steal.js')
steal.plugins('steal/test','steal/build/pluginify').then( function( s ) {
STEALPRINT = false;
s.test.module("steal/build/pluginify")

s.test.test("getFunctions", function(t){
var js = readFile('steal/build/pluginify/test/test_steals.js');
var firstFunc = steal.build.pluginify.getFunction(js, 0);

t.equals(firstFunc, readFile('steal/build/pluginify/test/firstFunc.js'));

var secondFunc = steal.build.pluginify.getFunction(js, 1);

t.equals(secondFunc, readFile('steal/build/pluginify/test/secondFunc.js'))

})
s.test.test("getFunctions2", function(t){
var js = readFile('jquery/view/micro/micro.js');
var firstFunc = steal.build.pluginify.getFunction(js, 0);
//print(firstFunc);
})
s.test.test("parse", function(t){
var js = readFile('jquery/class/class.js');
var tokens = js.tokens('=<>!+-*&|/%^', '=<>&|');

var js = readFile('jquery/view/ejs/ejs.js');
var tokens = js.tokens('=<>!+-*&|/%^', '=<>&|');

var js = readFile('jquery/lang/vector/vector.js');
var tokens = js.tokens('=<>!+-*&|/%^', '=<>&|');

var js = readFile('jquery/dom/fixture/fixture.js');
var tokens = js.tokens('=<>!+-*&|/%^', '=<>&|');

var js = readFile('jquery/view/view.js');
var tokens = js.tokens('=<>!+-*&|/%^', '=<>&|');

var js = readFile('jquery/lang/json/json.js');
var tokens = js.tokens('=<>!+-*&|/%^', '=<>&|');
})

});
3 changes: 3 additions & 0 deletions build/pluginify/test/secondFunc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function($,foo){
//yes
}
Loading

0 comments on commit 7e9d1c2

Please sign in to comment.