Skip to content

Commit

Permalink
New PackageLoader class to load packages outside of amber.js
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasPetton committed Oct 18, 2012
1 parent b1cd261 commit 17331f9
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h2>Examples</h2>
</div>
</div>

<script type='text/javascript'> loadAmber({packages: [ 'Test' ]}) </script>
<script type='text/javascript'> loadAmber() </script>

</body>
</html>
69 changes: 69 additions & 0 deletions js/Importer-Exporter.deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,72 @@ smalltalk.Importer);



smalltalk.addClass('PackageLoader', smalltalk.Object, [], 'Importer-Exporter');
smalltalk.addMethod(
"_initializePackageNamed_prefix_",
smalltalk.method({
selector: "initializePackageNamed:prefix:",
fn: function (packageName,aString){
var self=this;
var $1,$2;
smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Package || Package),"_named_",[packageName]),"_classes",[]),"_do_",[(function(each){
smalltalk.init(each);
;
return smalltalk.send(each,"_initialize",[]);
})]);
$1=smalltalk.send((smalltalk.Package || Package),"_named_",[packageName]);
smalltalk.send($1,"_commitPathJs_",[smalltalk.send(smalltalk.send("/","__comma",[aString]),"__comma",["/js"])]);
$2=smalltalk.send($1,"_commitPathSt_",[smalltalk.send(smalltalk.send("/","__comma",[aString]),"__comma",["/st"])]);
return self}
}),
smalltalk.PackageLoader);

smalltalk.addMethod(
"_loadPackage_prefix_",
smalltalk.method({
selector: "loadPackage:prefix:",
fn: function (packageName,aString){
var self=this;
var $1;
var url;
url=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send("/","__comma",[aString]),"__comma",["/js/"]),"__comma",[packageName]),"__comma",[".js"]);
smalltalk.send(jQuery,"_ajax_options_",[url,smalltalk.HashedCollection._fromPairs_([smalltalk.send("type","__minus_gt",["GET"]),smalltalk.send("dataType","__minus_gt",["script"]),smalltalk.send("complete","__minus_gt",[(function(jqXHR,textStatus){
$1=smalltalk.send(smalltalk.send(jqXHR,"_readyState",[]),"__eq",[(4)]);
if(smalltalk.assert($1)){
return smalltalk.send(self,"_initializePackageNamed_prefix_",[packageName,aString]);
};
})]),smalltalk.send("error","__minus_gt",[(function(){
return smalltalk.send(window,"_alert_",[smalltalk.send("Could not load package at: ","__comma",[url])]);
})])])]);
return self}
}),
smalltalk.PackageLoader);

smalltalk.addMethod(
"_loadPackages_prefix_",
smalltalk.method({
selector: "loadPackages:prefix:",
fn: function (aCollection,aString){
var self=this;
smalltalk.send(aCollection,"_do_",[(function(each){
return smalltalk.send(self,"_loadPackage_prefix_",[each,aString]);
})]);
return self}
}),
smalltalk.PackageLoader);


smalltalk.addMethod(
"_loadPackages_prefix_",
smalltalk.method({
selector: "loadPackages:prefix:",
fn: function (aCollection,aString){
var self=this;
var $1;
$1=smalltalk.send(smalltalk.send(self,"_new",[]),"_loadPackages_prefix_",[aCollection,aString]);
return $1;
}
}),
smalltalk.PackageLoader.klass);


89 changes: 89 additions & 0 deletions js/Importer-Exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,3 +725,92 @@ smalltalk.Importer);



smalltalk.addClass('PackageLoader', smalltalk.Object, [], 'Importer-Exporter');
smalltalk.addMethod(
"_initializePackageNamed_prefix_",
smalltalk.method({
selector: "initializePackageNamed:prefix:",
category: 'not yet classified',
fn: function (packageName,aString){
var self=this;
var $1,$2;
smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Package || Package),"_named_",[packageName]),"_classes",[]),"_do_",[(function(each){
smalltalk.init(each);
;
return smalltalk.send(each,"_initialize",[]);
})]);
$1=smalltalk.send((smalltalk.Package || Package),"_named_",[packageName]);
smalltalk.send($1,"_commitPathJs_",[smalltalk.send(smalltalk.send("/","__comma",[aString]),"__comma",["/js"])]);
$2=smalltalk.send($1,"_commitPathSt_",[smalltalk.send(smalltalk.send("/","__comma",[aString]),"__comma",["/st"])]);
return self},
args: ["packageName", "aString"],
source: "initializePackageNamed: packageName prefix: aString\x0a\x0a\x09(Package named: packageName) classes do: [ :each |\x0a \x09<smalltalk.init(each)>.\x0a each initialize. ].\x0a \x0a (Package named: packageName) \x0a \x09commitPathJs: '/', aString, '/js';\x0a commitPathSt: '/', aString, '/st'",
messageSends: ["do:", "initialize", "classes", "named:", "commitPathJs:", ",", "commitPathSt:"],
referencedClasses: ["Package"]
}),
smalltalk.PackageLoader);

smalltalk.addMethod(
"_loadPackage_prefix_",
smalltalk.method({
selector: "loadPackage:prefix:",
category: 'not yet classified',
fn: function (packageName,aString){
var self=this;
var $1;
var url;
url=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send("/","__comma",[aString]),"__comma",["/js/"]),"__comma",[packageName]),"__comma",[".js"]);
smalltalk.send(jQuery,"_ajax_options_",[url,smalltalk.HashedCollection._fromPairs_([smalltalk.send("type","__minus_gt",["GET"]),smalltalk.send("dataType","__minus_gt",["script"]),smalltalk.send("complete","__minus_gt",[(function(jqXHR,textStatus){
$1=smalltalk.send(smalltalk.send(jqXHR,"_readyState",[]),"__eq",[(4)]);
if(smalltalk.assert($1)){
return smalltalk.send(self,"_initializePackageNamed_prefix_",[packageName,aString]);
};
})]),smalltalk.send("error","__minus_gt",[(function(){
return smalltalk.send(window,"_alert_",[smalltalk.send("Could not load package at: ","__comma",[url])]);
})])])]);
return self},
args: ["packageName", "aString"],
source: "loadPackage: packageName prefix: aString\x09\x0a\x09| url |\x0a url := '/', aString, '/js/', packageName, '.js'.\x0a\x09jQuery \x0a\x09\x09ajax: url\x0a options: #{\x0a\x09\x09\x09'type' -> 'GET'.\x0a\x09\x09\x09'dataType' -> 'script'.\x0a \x09\x09'complete' -> [ :jqXHR :textStatus | \x0a\x09\x09\x09\x09jqXHR readyState = 4 \x0a \x09ifTrue: [ self initializePackageNamed: packageName prefix: aString ] ].\x0a\x09\x09\x09'error' -> [ window alert: 'Could not load package at: ', url ]\x0a\x09\x09}",
messageSends: [",", "ajax:options:", "->", "ifTrue:", "initializePackageNamed:prefix:", "=", "readyState", "alert:"],
referencedClasses: []
}),
smalltalk.PackageLoader);

smalltalk.addMethod(
"_loadPackages_prefix_",
smalltalk.method({
selector: "loadPackages:prefix:",
category: 'not yet classified',
fn: function (aCollection,aString){
var self=this;
smalltalk.send(aCollection,"_do_",[(function(each){
return smalltalk.send(self,"_loadPackage_prefix_",[each,aString]);
})]);
return self},
args: ["aCollection", "aString"],
source: "loadPackages: aCollection prefix: aString\x0a\x09aCollection do: [ :each |\x0a \x09self loadPackage: each prefix: aString ]",
messageSends: ["do:", "loadPackage:prefix:"],
referencedClasses: []
}),
smalltalk.PackageLoader);


smalltalk.addMethod(
"_loadPackages_prefix_",
smalltalk.method({
selector: "loadPackages:prefix:",
category: 'not yet classified',
fn: function (aCollection,aString){
var self=this;
var $1;
$1=smalltalk.send(smalltalk.send(self,"_new",[]),"_loadPackages_prefix_",[aCollection,aString]);
return $1;
},
args: ["aCollection", "aString"],
source: "loadPackages: aCollection prefix: aString\x0a\x09^ self new loadPackages: aCollection prefix: aString",
messageSends: ["loadPackages:prefix:", "new"],
referencedClasses: []
}),
smalltalk.PackageLoader.klass);


43 changes: 43 additions & 0 deletions st/Importer-Exporter.st
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,46 @@ import: aStream
result scanFrom: parser]]]
! !

Object subclass: #PackageLoader
instanceVariableNames: ''
package: 'Importer-Exporter'!

!PackageLoader methodsFor: 'not yet classified'!

initializePackageNamed: packageName prefix: aString

(Package named: packageName) classes do: [ :each |
<smalltalk.init(each)>.
each initialize. ].

(Package named: packageName)
commitPathJs: '/', aString, '/js';
commitPathSt: '/', aString, '/st'
!

loadPackage: packageName prefix: aString
| url |
url := '/', aString, '/js/', packageName, '.js'.
jQuery
ajax: url
options: #{
'type' -> 'GET'.
'dataType' -> 'script'.
'complete' -> [ :jqXHR :textStatus |
jqXHR readyState = 4
ifTrue: [ self initializePackageNamed: packageName prefix: aString ] ].
'error' -> [ window alert: 'Could not load package at: ', url ]
}
!

loadPackages: aCollection prefix: aString
aCollection do: [ :each |
self loadPackage: each prefix: aString ]
! !

!PackageLoader class methodsFor: 'not yet classified'!

loadPackages: aCollection prefix: aString
^ self new loadPackages: aCollection prefix: aString
! !

0 comments on commit 17331f9

Please sign in to comment.