Skip to content

Commit

Permalink
added browser compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
warmuuh committed Feb 26, 2013
1 parent 4e9c5fa commit 3a959e5
Show file tree
Hide file tree
Showing 21 changed files with 270 additions and 130 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
node_modules
node_modules
components
2 changes: 1 addition & 1 deletion .scripted
Expand Up @@ -6,6 +6,6 @@
}
},
"jshint" : {
options: {node: true}
options: {node: true, white:false}
}
}
36 changes: 36 additions & 0 deletions browser-example/MyClass.js
@@ -0,0 +1,36 @@
define([], function(){
function MyClass (val){
this.value = val;
}


MyClass.prototype = {

doSomething: function( /*@Default("Default Message")*/msg, /*@Autowired("message")*/msg2, /*@Autowired*/message) {
console.log("default: " +msg );
console.log("wired: " + this.value );
console.log("autowired: " +msg2 );
console.log("autowired(pname): " + message );

},


doSomethingElse: function( msg) /*@NotNull*/{
console.log(msg + " " +this.value);
},

doSomethingElseAgain: function( message) /*@Autowired*/{
console.log("autowired(fn): " + message );
},

};






return MyClass;
});


13 changes: 13 additions & 0 deletions browser-example/component.json
@@ -0,0 +1,13 @@
{

"name": "browser-example",
"version": "0.0.2",
"dependencies": {
"curl": "0.7.3",
"meld": "1.2.0",
"underscore": "1.4.4",
"when": "1.8.1",
"wire": "0.9.1",
"yaap": "0.0.2"
}
}
49 changes: 49 additions & 0 deletions browser-example/index.html
@@ -0,0 +1,49 @@
<html>
<head>

<!--<script src="components/underscore/underscore.js"></script>-->
<script type="text/javascript">
curl = {

paths: {
curl: 'components/curl/src/curl/'
},
packages: {
wire: { path: 'components/wire', main: 'wire'},
when: { path: 'components/when/', main: 'when'},
yaap: { path: '../yaap/', main: 'yaap'},
meld: { path: 'components/meld', main: 'meld' },
underscore:{ path: 'components/underscore', main: 'underscore',
config: {moduleLoader: 'curl/loader/cjsm11'}
}

}
};


</script>
</head>
<body>

<script src="components/curl/src/curl.js"></script>
<script type="text/javascript">

curl(['wire!spec']).then(function(ctx){

console.log("----- initialized -----");
ctx.myComponent.doSomething();
ctx.myComponent.doSomethingElseAgain();

},function(err){
console.log("err: " + err);
})


</script>





</body>
</html>
21 changes: 21 additions & 0 deletions browser-example/spec.js
@@ -0,0 +1,21 @@
define([], function(){


return {
message: "autowired",
myComponent: {
create: {
module: 'MyClass',
args: "wired"
}
},

plugins: [
//{module: "wire/debug", trace: true},
{module: "yaap/wire/wireplugin"}

]

}

});
9 changes: 9 additions & 0 deletions component.json
@@ -0,0 +1,9 @@
{
"name": "yaap",
"version": "0.0.2",
"main": "./yaap/yaap.js",
"repository": {
"type": "git",
"url": "git://github.com/warmuuh/yaap.git"
}
}
File renamed without changes.
6 changes: 3 additions & 3 deletions example/main.js → node-example/main.js
Expand Up @@ -18,15 +18,15 @@ wire({

plugins: [
//{module: "wire/debug", trace: true},
{module: "../yaap/wire", hookRequire: require}
{module: "../yaap/wire"}

]

}, {require: require}).then(function(ctx){

console.log("----- initialized -----");
ctx.myComponent.doSomething();
ctx.myComponent.doSomethingElseAgain();
ctx.myComponent.doSomethingElseAgain();

}, console.error);
}, function(err){console.error(err);});

File renamed without changes.
2 changes: 1 addition & 1 deletion yaap/package.json
@@ -1,6 +1,6 @@
{
"name": "yaap",
"version": "0.0.1",
"version": "0.0.2",
"description": "yaap",
"keywords": [ "javascript", "dependency injection", "AOP", "IOC"],
"repository": {
Expand Down
6 changes: 5 additions & 1 deletion yaap/parser/ECMA5Parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions yaap/parser/PanPG_util.js
Expand Up @@ -4,8 +4,10 @@
* http://boshi.inimino.org/3box/PanPG/about.html
* MIT Licensed
*/
"use strict";
(function(define) {
define([],function() {

;(function(exports){

// (event array (can be partial), [name array], [input string], [state]) → [ascii-art tree, state]
// -or-
Expand Down Expand Up @@ -154,7 +156,9 @@ function treeWalker(dict,result){var p,any,anon,other,fail,except,index,cb=[],st
function warn(s){
if(dict.warn)dict.warn(s)}}

exports.showTree=showTree
exports.treeWalker=treeWalker
return {
showTree:showTree,
treeWalker:treeWalker
}

})(typeof exports=='object'?exports:PanPG_util={});
});})(typeof define == 'function'? define: function(deps, factory) {module.exports = factory.apply(this, deps.map(function(x) {return require(x);}));});
4 changes: 2 additions & 2 deletions yaap/parser/buildparser.js
Expand Up @@ -8,7 +8,7 @@
*
* @author Peter Mucha
*
* @version 0.0.1
* @version 0.0.2
*/
"use strict";

Expand All @@ -19,7 +19,7 @@ var grammar = fs.readFileSync("ECMAScript_5.peg").toString();
var parser = pg.generateParser(grammar);


parser = parser + "\nexports.Program = Program;";
parser = "(function(define) {\ndefine([],function(){\n\n" + parser + "return {Program:Program};\n\n});})(typeof define == 'function'? define: function(deps, factory) {module.exports = factory.apply(this, deps.map(function(x) {return require(x);}));});";


fs.writeFileSync("ECMA5Parser.js", parser);
15 changes: 10 additions & 5 deletions yaap/parser/walker.js
Expand Up @@ -8,14 +8,17 @@
*
* @author Peter Mucha
*
* @version 0.0.1
* @version 0.0.2
*/
"use strict";

var _ = require("underscore");
(function(define) {
define(["underscore"],
function(_) {


var treewalker = module.exports = {


return {
Program: function(match, children){
return children;
},
Expand Down Expand Up @@ -94,4 +97,6 @@ var treewalker = module.exports = {
//console.log("fn body annotations found: " + JSON.stringify(bodyObj));
}

};
};

});})(typeof define == 'function'? define: function(deps, factory) {module.exports = factory.apply(this, deps.map(function(x) {return require(x);}));});
13 changes: 7 additions & 6 deletions yaap/plugins/DefaultProcessor.js
Expand Up @@ -10,15 +10,15 @@
*
* @author Peter Mucha
*
* @version 0.0.1
* @version 0.0.2
*/
"use strict";

var meld = require("meld");
var _ = require("underscore");
(function(define) {
define(["underscore", "meld"],
function(_, meld) {


module.exports = {
return {
annotation: "@Default",

processParameter: function(obj, fnObj, param, annotationParams) {
Expand All @@ -32,3 +32,4 @@ module.exports = {
}
};

});})(typeof define == 'function'? define: function(deps, factory) {module.exports = factory.apply(this, deps.map(function(x) {return require(x);}));});
12 changes: 7 additions & 5 deletions yaap/plugins/NotNullProcessor.js
Expand Up @@ -10,15 +10,16 @@
*
* @author Peter Mucha
*
* @version 0.0.1
* @version 0.0.2
*/
"use strict";

var meld = require("meld");
var _ = require("underscore");
(function(define) {
define(["underscore", "meld"],
function(_, meld) {



module.exports = {
return {
annotation: "@NotNull",


Expand Down Expand Up @@ -46,3 +47,4 @@ module.exports = {
}
};

});})(typeof define == 'function'? define: function(deps, factory) {module.exports = factory.apply(this, deps.map(function(x) {return require(x);}));});
28 changes: 16 additions & 12 deletions yaap/registry.js
Expand Up @@ -8,23 +8,27 @@
*
* @author Peter Mucha
*
* @version 0.0.1
* @version 0.0.2
*/
"use strict";

var _ = require("underscore");

(function(define) {
define(["underscore"], function(_) {

var registry = [];

var register = exports.register = function(processors){
_(processors).each(function(proc){
registry.push(proc);
});
};



var getProcessors = exports.getProcessors = function(annotation){
return _(registry).where({annotation:annotation});
};
return {
getProcessors: function(annotation){
return _(registry).where({annotation:annotation});
},
register: function(processors){
_(processors).each(function(proc){
registry.push(proc);
})
}
}


});})(typeof define == 'function'? define: function(deps, factory) {module.exports = factory.apply(this, deps.map(function(x) {return require(x);}));});

0 comments on commit 3a959e5

Please sign in to comment.