Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New PackageLoader class to load packages outside of amber.js

  • Loading branch information...
commit 17331f9de80ae7f9afa01bad9571cb49b399e916 1 parent b1cd261
@NicolasPetton authored
View
2  index.html
@@ -103,7 +103,7 @@
</div>
</div>
- <script type='text/javascript'> loadAmber({packages: [ 'Test' ]}) </script>
+ <script type='text/javascript'> loadAmber() </script>
</body>
</html>
View
69 js/Importer-Exporter.deploy.js
@@ -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);
+
+
View
89 js/Importer-Exporter.js
@@ -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);
+
+
View
43 st/Importer-Exporter.st
@@ -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
+! !
+
Please sign in to comment.
Something went wrong with that request. Please try again.