From 17331f9de80ae7f9afa01bad9571cb49b399e916 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Thu, 18 Oct 2012 15:57:10 +0200 Subject: [PATCH] New PackageLoader class to load packages outside of amber.js --- index.html | 2 +- js/Importer-Exporter.deploy.js | 69 ++++++++++++++++++++++++++ js/Importer-Exporter.js | 89 ++++++++++++++++++++++++++++++++++ st/Importer-Exporter.st | 43 ++++++++++++++++ 4 files changed, 202 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index b1e032853..2a2ad0038 100644 --- a/index.html +++ b/index.html @@ -103,7 +103,7 @@

Examples

- + diff --git a/js/Importer-Exporter.deploy.js b/js/Importer-Exporter.deploy.js index e1c2b627c..bf2d6fd04 100644 --- a/js/Importer-Exporter.deploy.js +++ b/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); + + diff --git a/js/Importer-Exporter.js b/js/Importer-Exporter.js index 157417bb1..790093236 100644 --- a/js/Importer-Exporter.js +++ b/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.\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); + + diff --git a/st/Importer-Exporter.st b/st/Importer-Exporter.st index 572b7b4a9..9ca479f49 100644 --- a/st/Importer-Exporter.st +++ b/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 | + . + 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 +! ! +