Bläddra i källkod

First class package transport. Not used yet.

Nicolas Petton 10 år sedan
förälder
incheckning
3c9ea1abdf
2 ändrade filer med 309 tillägg och 99 borttagningar
  1. 162 7
      js/Importer-Exporter.js
  2. 147 92
      st/Importer-Exporter.st

+ 162 - 7
js/Importer-Exporter.js

@@ -1954,12 +1954,12 @@ var self=this;
 function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
 return smalltalk.withContext(function($ctx1) { 
 var $1;
-$1=_st(_st($Smalltalk())._current())._defaultAMDNamespace();
+$1=_st(_st($Smalltalk())._current())._defaultAmdNamespace();
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"defaultNamespace",{},smalltalk.AmdPackageHandler.klass)})},
 args: [],
-source: "defaultNamespace\x0a\x09^ Smalltalk current defaultAMDNamespace",
-messageSends: ["defaultAMDNamespace", "current"],
+source: "defaultNamespace\x0a\x09^ Smalltalk current defaultAmdNamespace",
+messageSends: ["defaultAmdNamespace", "current"],
 referencedClasses: ["Smalltalk"]
 }),
 smalltalk.AmdPackageHandler.klass);
@@ -1987,14 +1987,15 @@ selector: "initialize",
 category: 'initialization',
 fn: function (){
 var self=this;
+function $AMDPackageTransport(){return smalltalk.AMDPackageTransport||(typeof AMDPackageTransport=="undefined"?nil:AMDPackageTransport)}
 return smalltalk.withContext(function($ctx1) { 
 smalltalk.AmdPackageHandler.klass.superclass.fn.prototype._initialize.apply(_st(self), []);
-self._registerFor_("amd");
+self._registerFor_(_st($AMDPackageTransport())._type());
 return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.AmdPackageHandler.klass)})},
 args: [],
-source: "initialize\x0a\x09super initialize.\x0a\x09self registerFor: 'amd'",
-messageSends: ["initialize", "registerFor:"],
-referencedClasses: []
+source: "initialize\x0a\x09super initialize.\x0a\x09self registerFor: AMDPackageTransport type",
+messageSends: ["initialize", "registerFor:", "type"],
+referencedClasses: ["AMDPackageTransport"]
 }),
 smalltalk.AmdPackageHandler.klass);
 
@@ -2308,6 +2309,160 @@ referencedClasses: []
 smalltalk.LegacyPackageHandler.klass);
 
 
+smalltalk.addClass('PackageTransport', smalltalk.Object, [], 'Importer-Exporter');
+smalltalk.addMethod(
+smalltalk.method({
+selector: "commitHandler",
+category: 'accessing',
+fn: function (){
+var self=this;
+function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st($PackageHandler())._for_(self._type());
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"commitHandler",{},smalltalk.PackageTransport)})},
+args: [],
+source: "commitHandler\x0a\x09^ PackageHandler for: self type",
+messageSends: ["for:", "type"],
+referencedClasses: ["PackageHandler"]
+}),
+smalltalk.PackageTransport);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "type",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st(self._class())._type();
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"type",{},smalltalk.PackageTransport)})},
+args: [],
+source: "type\x0a\x09^ self class type",
+messageSends: ["type", "class"],
+referencedClasses: []
+}),
+smalltalk.PackageTransport);
+
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "type",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return nil;
+}, function($ctx1) {$ctx1.fill(self,"type",{},smalltalk.PackageTransport.klass)})},
+args: [],
+source: "type\x0a\x09\x22Override in subclasses\x22\x0a\x09^ nil",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.PackageTransport.klass);
+
+
+smalltalk.addClass('AmdPackageTransport', smalltalk.PackageTransport, ['namespace'], 'Importer-Exporter');
+smalltalk.addMethod(
+smalltalk.method({
+selector: "defaultNamespace",
+category: 'defaults',
+fn: function (){
+var self=this;
+function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st(_st($Smalltalk())._current())._defaultAmdNamespace();
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"defaultNamespace",{},smalltalk.AmdPackageTransport)})},
+args: [],
+source: "defaultNamespace\x0a\x09^ Smalltalk current defaultAmdNamespace",
+messageSends: ["defaultAmdNamespace", "current"],
+referencedClasses: ["Smalltalk"]
+}),
+smalltalk.AmdPackageTransport);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "namespace",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $2,$1;
+$2=self["@namespace"];
+if(($receiver = $2) == nil || $receiver == undefined){
+$1=self._defaultNamespace();
+} else {
+$1=$2;
+};
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"namespace",{},smalltalk.AmdPackageTransport)})},
+args: [],
+source: "namespace\x0a\x09^ namespace ifNil: [ self defaultNamespace ]",
+messageSends: ["ifNil:", "defaultNamespace"],
+referencedClasses: []
+}),
+smalltalk.AmdPackageTransport);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "namespace:",
+category: 'accessing',
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self["@namespace"]=aString;
+return self}, function($ctx1) {$ctx1.fill(self,"namespace:",{aString:aString},smalltalk.AmdPackageTransport)})},
+args: ["aString"],
+source: "namespace: aString\x0a\x09namespace := aString",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.AmdPackageTransport);
+
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "namespace:",
+category: 'instance creation',
+fn: function (aString){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $2,$3,$1;
+$2=self._new();
+_st($2)._namespace_(aString);
+$3=_st($2)._yourself();
+$1=$3;
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"namespace:",{aString:aString},smalltalk.AmdPackageTransport.klass)})},
+args: ["aString"],
+source: "namespace: aString\x0a\x09^ self new\x0a\x09\x09namespace: aString;\x0a\x09\x09yourself",
+messageSends: ["namespace:", "new", "yourself"],
+referencedClasses: []
+}),
+smalltalk.AmdPackageTransport.klass);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "type",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return "amd";
+}, function($ctx1) {$ctx1.fill(self,"type",{},smalltalk.AmdPackageTransport.klass)})},
+args: [],
+source: "type\x0a\x09^ 'amd'",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.AmdPackageTransport.klass);
+
+
 smalltalk.addClass('PluggableExporter', smalltalk.Object, ['recipe'], 'Importer-Exporter');
 smalltalk.PluggableExporter.comment="I am an engine for exporting structured data on a Stream.\x0a\x0aMy instances are created using\x0a  PluggableExporter forRecipe: aRecipe,\x0awhere recipe is structured description of the exporting algorithm (see `ExportRecipeInterpreter`).\x0a\x0aThe actual exporting is done by interpreting the recipe using a `RecipeInterpreter`.\x0a\x0a\x0aI am used to export amber packages, so I have a convenience method\x0a`exportPackage: aPackage on: aStream`\x0awhich exports `aPackage` using the `recipe`\x0a(it is otherwise no special, so it may be renamed to export:on:)";
 smalltalk.addMethod(

+ 147 - 92
st/Importer-Exporter.st

@@ -11,6 +11,17 @@ Use `#exportPackage:on:` to export a given package on a Stream.!
 
 !AbstractExporter methodsFor: 'accessing'!
 
+extensionMethodsOfPackage: aPackage
+	| result |
+	
+	result := OrderedCollection new.
+	
+	(self extensionProtocolsOfPackage: aPackage) do: [ :each |
+		result addAll: each methods ].
+		
+	^ result
+!
+
 extensionProtocolsOfPackage: aPackage
 	| extensionName result |
 	
@@ -27,17 +38,6 @@ extensionProtocolsOfPackage: aPackage
 				result add: (ExportMethodProtocol name: extensionName theClass: behavior) ] ] ].
 
 	^result
-!
-
-extensionMethodsOfPackage: aPackage
-	| result |
-	
-	result := OrderedCollection new.
-	
-	(self extensionProtocolsOfPackage: aPackage) do: [ :each |
-		result addAll: each methods ].
-		
-	^ result
 ! !
 
 !AbstractExporter methodsFor: 'convenience'!
@@ -205,34 +205,6 @@ exportMethod: aMethod on: aStream
 		nextPutAll: '!!'
 !
 
-exportPackageDefinitionOf: aPackage on: aStream
-	aStream
-		nextPutAll: 'Smalltalk current createPackage: ''', aPackage name, '''!!';
-		lf
-!
-
-exportProtocolEpilogueOf: aProtocol on: aStream
-	aStream nextPutAll: ' !!'; lf; lf
-!
-
-exportProtocolPrologueOf: aProtocol on: aStream
-	aStream
-		nextPutAll: '!!', (self classNameFor: aProtocol theClass);
-		nextPutAll: ' methodsFor: ''', aProtocol name, '''!!'
-!
-
-exportProtocol: aProtocol on: aStream
-	self exportProtocolPrologueOf: aProtocol on: aStream.
-	aProtocol methods do: [ :method | 
-		self exportMethod: method on: aStream ].
-	self exportProtocolEpilogueOf: aProtocol on: aStream
-!
-
-exportProtocols: aCollection on: aStream
-	aCollection do: [ :each |
-		self exportProtocol: each on: aStream ]
-!
-
 exportPackage: aPackage on: aStream
 
 	self exportPackageDefinitionOf: aPackage on: aStream.
@@ -253,6 +225,34 @@ exportPackage: aPackage on: aStream
 	self 
 		exportProtocols: (self extensionProtocolsOfPackage: aPackage)
 		on: aStream
+!
+
+exportPackageDefinitionOf: aPackage on: aStream
+	aStream
+		nextPutAll: 'Smalltalk current createPackage: ''', aPackage name, '''!!';
+		lf
+!
+
+exportProtocol: aProtocol on: aStream
+	self exportProtocolPrologueOf: aProtocol on: aStream.
+	aProtocol methods do: [ :method | 
+		self exportMethod: method on: aStream ].
+	self exportProtocolEpilogueOf: aProtocol on: aStream
+!
+
+exportProtocolEpilogueOf: aProtocol on: aStream
+	aStream nextPutAll: ' !!'; lf; lf
+!
+
+exportProtocolPrologueOf: aProtocol on: aStream
+	aStream
+		nextPutAll: '!!', (self classNameFor: aProtocol theClass);
+		nextPutAll: ' methodsFor: ''', aProtocol name, '''!!'
+!
+
+exportProtocols: aCollection on: aStream
+	aCollection do: [ :each |
+		self exportProtocol: each on: aStream ]
 ! !
 
 AbstractExporter subclass: #Exporter
@@ -387,6 +387,28 @@ exportMethod: aMethod on: aStream
 		nextPutAll: ');';lf;lf
 !
 
+exportPackage: aPackage on: aStream
+	
+	self 
+		exportPackagePrologueOf: aPackage on: aStream;
+		exportPackageDefinitionOf: aPackage on: aStream;
+		exportPackageTransportOf: aPackage on: aStream.
+	
+	aPackage sortedClasses do: [ :each |
+		self exportDefinitionOf: each on: aStream.
+		each ownMethods do: [ :method |
+			self exportMethod: method on: aStream ].
+			
+		self exportMetaDefinitionOf: each on: aStream.
+		each class ownMethods do: [ :method |
+			self exportMethod: method on: aStream ] ].
+			
+	(self extensionMethodsOfPackage: aPackage) do: [ :each |
+		self exportMethod: each on: aStream ].
+		
+	self exportPackageEpilogueOf: aPackage on: aStream
+!
+
 exportPackageDefinitionOf: aPackage on: aStream
 	aStream
 		nextPutAll: 'smalltalk.addPackage(';
@@ -417,28 +439,6 @@ exportPackageTransportOf: aPackage on: aStream
 			nextPutAll: json;
 			nextPutAll: ';';
 			lf ]
-!
-
-exportPackage: aPackage on: aStream
-	
-	self 
-		exportPackagePrologueOf: aPackage on: aStream;
-		exportPackageDefinitionOf: aPackage on: aStream;
-		exportPackageTransportOf: aPackage on: aStream.
-	
-	aPackage sortedClasses do: [ :each |
-		self exportDefinitionOf: each on: aStream.
-		each ownMethods do: [ :method |
-			self exportMethod: method on: aStream ].
-			
-		self exportMetaDefinitionOf: each on: aStream.
-		each class ownMethods do: [ :method |
-			self exportMethod: method on: aStream ] ].
-			
-	(self extensionMethodsOfPackage: aPackage) do: [ :each |
-		self exportMethod: each on: aStream ].
-		
-	self exportPackageEpilogueOf: aPackage on: aStream
 ! !
 
 Exporter subclass: #AmdExporter
@@ -576,16 +576,16 @@ name: aString
 	name := aString
 !
 
+sortedMethods
+	^ self methods sorted: [ :a :b | a selector <= b selector ]
+!
+
 theClass
 	^theClass
 !
 
 theClass: aClass
 	theClass := aClass
-!
-
-sortedMethods
-	^ self methods sorted: [ :a :b | a selector <= b selector ]
 ! !
 
 !ExportMethodProtocol class methodsFor: 'instance creation'!
@@ -680,30 +680,30 @@ I should not be used directly. Instead, use the corresponding `Package` methods.
 
 !PackageHandler methodsFor: 'accessing'!
 
-commitPathJsFor: aPackage
-	self subclassResponsibility
-!
-
-commitPathStFor: aPackage
-	self subclassResponsibility
-!
-
-exporterClass
-	^ Exporter
+chunkContentsFor: aPackage
+	^ String streamContents: [ :str |
+		self chunkExporter exportPackage: aPackage on: str ]
 !
 
 chunkExporterClass
 	^ ChunkExporter
 !
 
-chunkContentsFor: aPackage
-	^ String streamContents: [ :str |
-		self chunkExporter exportPackage: aPackage on: str ]
+commitPathJsFor: aPackage
+	self subclassResponsibility
+!
+
+commitPathStFor: aPackage
+	self subclassResponsibility
 !
 
 contentsFor: aPackage
 	^ String streamContents: [ :str |
 		self exporter exportPackage: aPackage on: str ]
+!
+
+exporterClass
+	^ Exporter
 ! !
 
 !PackageHandler methodsFor: 'committing'!
@@ -717,6 +717,18 @@ commit: aPackage
 		displayingProgress: 'Committing package ', aPackage name
 !
 
+commitJsFileFor: aPackage
+	self 
+		ajaxPutAt: (self commitPathJsFor: aPackage), '/', aPackage name, '.js'
+		data: (self contentsFor: aPackage)
+!
+
+commitStFileFor: aPackage
+	self 
+		ajaxPutAt: (self commitPathStFor: aPackage), '/', aPackage name, '.st'
+		data: (self chunkContentsFor: aPackage)
+!
+
 oldCommit: aPackage
 	
 	self commitChannels
@@ -726,18 +738,6 @@ oldCommit: aPackage
 				(PluggableExporter forRecipe: commitStrategy key) exportPackage: aPackage on: stream ].
 			self ajaxPutAt: commitStrategy value data: fileContents ]
 		displayingProgress: 'Committing package ', aPackage name
-!
-
-commitStFileFor: aPackage
-	self 
-		ajaxPutAt: (self commitPathStFor: aPackage), '/', aPackage name, '.st'
-		data: (self chunkContentsFor: aPackage)
-!
-
-commitJsFileFor: aPackage
-	self 
-		ajaxPutAt: (self commitPathJsFor: aPackage), '/', aPackage name, '.js'
-		data: (self contentsFor: aPackage)
 ! !
 
 !PackageHandler methodsFor: 'factory'!
@@ -832,7 +832,7 @@ toUrl: aString
 !AmdPackageHandler class methodsFor: 'commit paths'!
 
 defaultNamespace
-	^ Smalltalk current defaultAMDNamespace
+	^ Smalltalk current defaultAmdNamespace
 !
 
 defaultNamespace: aString
@@ -847,7 +847,7 @@ resetCommitPaths
 
 initialize
 	super initialize.
-	self registerFor: 'amd'
+	self registerFor: AMDPackageTransport type
 ! !
 
 PackageHandler subclass: #LegacyPackageHandler
@@ -956,6 +956,61 @@ loadPackages: aCollection prefix: aString
 	^ self new loadPackages: aCollection prefix: aString
 ! !
 
+Object subclass: #PackageTransport
+	instanceVariableNames: ''
+	package: 'Importer-Exporter'!
+
+!PackageTransport methodsFor: 'accessing'!
+
+type
+	^ self class type
+!
+
+commitHandler
+	^ PackageHandler for: self type
+! !
+
+!PackageTransport class methodsFor: 'accessing'!
+
+type
+	"Override in subclasses"
+	^ nil
+! !
+
+PackageTransport subclass: #AmdPackageTransport
+	instanceVariableNames: 'namespace'
+	package: 'Importer-Exporter'!
+
+!AmdPackageTransport methodsFor: 'accessing'!
+
+namespace
+	^ namespace ifNil: [ self defaultNamespace ]
+!
+
+namespace: aString
+	namespace := aString
+! !
+
+!AmdPackageTransport methodsFor: 'defaults'!
+
+defaultNamespace
+	^ Smalltalk current defaultAmdNamespace
+! !
+
+!AmdPackageTransport class methodsFor: 'accessing'!
+
+type
+	^ 'amd'
+! !
+
+!AmdPackageTransport class methodsFor: 'instance creation'!
+
+namespace: aString
+	^ self new
+		namespace: aString;
+		yourself
+! !
+
 Object subclass: #PluggableExporter
 	instanceVariableNames: 'recipe'
 	package: 'Importer-Exporter'!