Browse Source

- adds Package >> definition
- adds Package class >> named:transport:
- Trigger and announcement on Package creation

Nicolas Petton 10 years ago
parent
commit
980f580425
4 changed files with 232 additions and 22 deletions
  1. 51 3
      js/Importer-Exporter.js
  2. 126 12
      js/Kernel-Infrastructure.js
  3. 13 1
      st/Importer-Exporter.st
  4. 42 6
      st/Kernel-Infrastructure.st

+ 51 - 3
js/Importer-Exporter.js

@@ -1457,14 +1457,14 @@ $8=_st($9).__comma(_st(xhr)._responseText());
 $ctx2.sendIdx[","]=2;
 $7=_st($8).__comma("\x22");
 $ctx2.sendIdx[","]=1;
-return self._error_($7);
+return self._alert_($7);
 }, function($ctx2) {$ctx2.fillBlock({xhr:xhr},$ctx1,1)})}));
 $1=smalltalk.HashedCollection._from_([$2,$3,$4,$5,$6]);
 self._ajax_($1);
 return self}, function($ctx1) {$ctx1.fill(self,"ajaxPutAt:data:",{aURL:aURL,aString:aString},smalltalk.PackageHandler)})},
 args: ["aURL", "aString"],
-source: "ajaxPutAt: aURL data: aString\x0a\x09self\x0a\x09\x09ajax: #{\x0a\x09\x09\x09'url' -> aURL.\x0a\x09\x09\x09'type' -> 'PUT'.\x0a\x09\x09\x09'data' -> aString.\x0a\x09\x09\x09'contentType' -> 'text/plain;charset=UTF-8'.\x0a\x09\x09\x09'error' -> [ :xhr | self error: 'Commiting ' , aURL , ' failed with reason: \x22' , (xhr responseText) , '\x22'] }",
-messageSends: ["ajax:", "->", "error:", ",", "responseText"],
+source: "ajaxPutAt: aURL data: aString\x0a\x09self\x0a\x09\x09ajax: #{\x0a\x09\x09\x09'url' -> aURL.\x0a\x09\x09\x09'type' -> 'PUT'.\x0a\x09\x09\x09'data' -> aString.\x0a\x09\x09\x09'contentType' -> 'text/plain;charset=UTF-8'.\x0a\x09\x09\x09'error' -> [ :xhr | self alert: 'Commiting ' , aURL , ' failed with reason: \x22' , (xhr responseText) , '\x22'] }",
+messageSends: ["ajax:", "->", "alert:", ",", "responseText"],
 referencedClasses: []
 }),
 smalltalk.PackageHandler);
@@ -1899,6 +1899,22 @@ referencedClasses: []
 }),
 smalltalk.PackageTransport);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "definition",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return "";
+}, function($ctx1) {$ctx1.fill(self,"definition",{},smalltalk.PackageTransport)})},
+args: [],
+source: "definition\x0a\x09^ ''",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.PackageTransport);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "package",
@@ -2190,6 +2206,38 @@ referencedClasses: ["Smalltalk"]
 }),
 smalltalk.AmdPackageTransport);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "definition",
+category: 'accessing',
+fn: function (){
+var self=this;
+function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
+return smalltalk.withContext(function($ctx1) { 
+var $2,$4,$6,$5,$3,$1;
+$1=_st($String())._streamContents_((function(stream){
+return smalltalk.withContext(function($ctx2) {
+$2=stream;
+_st($2)._nextPutAll_(_st(self._class())._name());
+$ctx2.sendIdx["nextPutAll:"]=1;
+_st($2)._nextPutAll_(" namespace: ");
+$ctx2.sendIdx["nextPutAll:"]=2;
+$4=$2;
+$6="'".__comma(self._namespace());
+$5=_st($6).__comma("'");
+$ctx2.sendIdx[","]=1;
+$3=_st($4)._nextPutAll_($5);
+return $3;
+}, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})}));
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"definition",{},smalltalk.AmdPackageTransport)})},
+args: [],
+source: "definition\x0a\x09^ String streamContents: [ :stream |\x0a\x09\x09stream \x0a\x09\x09\x09nextPutAll: self class name;\x0a\x09\x09\x09nextPutAll: ' namespace: ';\x0a\x09\x09\x09nextPutAll: '''', self namespace, '''' ]",
+messageSends: ["streamContents:", "nextPutAll:", "name", "class", ",", "namespace"],
+referencedClasses: ["String"]
+}),
+smalltalk.AmdPackageTransport);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "namespace",

+ 126 - 12
js/Kernel-Infrastructure.js

@@ -1286,6 +1286,65 @@ referencedClasses: []
 }),
 smalltalk.Package);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "definition",
+category: 'accessing',
+fn: function (){
+var self=this;
+function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
+return smalltalk.withContext(function($ctx1) { 
+var $2,$3,$4,$5,$7,$8,$6,$9,$12,$11,$10,$13,$15,$16,$14,$18,$19,$17,$1;
+$1=_st($String())._streamContents_((function(stream){
+return smalltalk.withContext(function($ctx2) {
+$2=stream;
+$3=$2;
+$4=_st(self._class())._name();
+$ctx2.sendIdx["name"]=1;
+_st($3)._nextPutAll_($4);
+$ctx2.sendIdx["nextPutAll:"]=1;
+$5=$2;
+$7=_st($String())._lf();
+$ctx2.sendIdx["lf"]=1;
+$8=_st($String())._tab();
+$ctx2.sendIdx["tab"]=1;
+$6=_st($7).__comma($8);
+$ctx2.sendIdx[","]=1;
+_st($5)._nextPutAll_($6);
+$ctx2.sendIdx["nextPutAll:"]=2;
+_st($2)._nextPutAll_(" named: ");
+$ctx2.sendIdx["nextPutAll:"]=3;
+$9=$2;
+$12=self._name();
+$11="'".__comma($12);
+$ctx2.sendIdx[","]=3;
+$10=_st($11).__comma("'");
+$ctx2.sendIdx[","]=2;
+_st($9)._nextPutAll_($10);
+$ctx2.sendIdx["nextPutAll:"]=4;
+$13=$2;
+$15=_st($String())._lf();
+$16=_st($String())._tab();
+$14=_st($15).__comma($16);
+$ctx2.sendIdx[","]=4;
+_st($13)._nextPutAll_($14);
+$ctx2.sendIdx["nextPutAll:"]=5;
+_st($2)._nextPutAll_(" transport: (");
+$ctx2.sendIdx["nextPutAll:"]=6;
+$18=$2;
+$19=_st(_st(self._transport())._definition()).__comma(")");
+$17=_st($18)._nextPutAll_($19);
+return $17;
+}, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})}));
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"definition",{},smalltalk.Package)})},
+args: [],
+source: "definition\x0a\x09^ String streamContents: [ :stream |\x0a\x09\x09stream \x0a\x09\x09\x09nextPutAll: self class name;\x0a\x09\x09\x09nextPutAll: String lf, String tab;\x0a\x09\x09\x09nextPutAll: ' named: ';\x0a\x09\x09\x09nextPutAll: '''', self name, '''';\x0a\x09\x09\x09nextPutAll: String lf, String tab;\x0a\x09\x09\x09nextPutAll:  ' transport: (';\x0a\x09\x09\x09nextPutAll: self transport definition, ')' ]",
+messageSends: ["streamContents:", "nextPutAll:", "name", "class", ",", "lf", "tab", "definition", "transport"],
+referencedClasses: ["String"]
+}),
+smalltalk.Package);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "isPackage",
@@ -1523,10 +1582,11 @@ fn: function (aPackageTransport){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 self["@transport"]=aPackageTransport;
+_st(aPackageTransport)._package_(self);
 return self}, function($ctx1) {$ctx1.fill(self,"transport:",{aPackageTransport:aPackageTransport},smalltalk.Package)})},
 args: ["aPackageTransport"],
-source: "transport: aPackageTransport\x0a\x09transport := aPackageTransport",
-messageSends: [],
+source: "transport: aPackageTransport\x0a\x09transport := aPackageTransport.\x0a\x09aPackageTransport package: self",
+messageSends: ["package:"],
 referencedClasses: []
 }),
 smalltalk.Package);
@@ -1541,13 +1601,19 @@ fn: function (aPackageName){
 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())._packageAt_(aPackageName);
+var $2,$3,$1;
+$2=_st($Smalltalk())._current();
+$ctx1.sendIdx["current"]=1;
+$1=_st($2)._packageAt_ifAbsent_(aPackageName,(function(){
+return smalltalk.withContext(function($ctx2) {
+$3=_st($Smalltalk())._current();
+return _st($3)._createPackage_(aPackageName);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"named:",{aPackageName:aPackageName},smalltalk.Package.klass)})},
 args: ["aPackageName"],
-source: "named: aPackageName\x0a\x0a\x09^Smalltalk current packageAt: aPackageName",
-messageSends: ["packageAt:", "current"],
+source: "named: aPackageName\x0a\x09^ Smalltalk current \x0a\x09\x09packageAt: aPackageName\x0a\x09\x09ifAbsent: [ \x0a\x09\x09\x09Smalltalk current createPackage: aPackageName ]",
+messageSends: ["packageAt:ifAbsent:", "current", "createPackage:"],
 referencedClasses: ["Smalltalk"]
 }),
 smalltalk.Package.klass);
@@ -1565,12 +1631,33 @@ $1=_st(_st($Smalltalk())._current())._packageAt_ifAbsent_(aPackageName,aBlock);
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"named:ifAbsent:",{aPackageName:aPackageName,aBlock:aBlock},smalltalk.Package.klass)})},
 args: ["aPackageName", "aBlock"],
-source: "named: aPackageName ifAbsent: aBlock\x0a\x0a\x09^Smalltalk current packageAt: aPackageName ifAbsent: aBlock",
+source: "named: aPackageName ifAbsent: aBlock\x0a\x09^ Smalltalk current packageAt: aPackageName ifAbsent: aBlock",
 messageSends: ["packageAt:ifAbsent:", "current"],
 referencedClasses: ["Smalltalk"]
 }),
 smalltalk.Package.klass);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "named:transport:",
+category: 'accessing',
+fn: function (aPackageName,aTransport){
+var self=this;
+var package_;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+package_=self._named_(aPackageName);
+_st(package_)._transport_(aTransport);
+$1=package_;
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"named:transport:",{aPackageName:aPackageName,aTransport:aTransport,package_:package_},smalltalk.Package.klass)})},
+args: ["aPackageName", "aTransport"],
+source: "named: aPackageName transport: aTransport\x0a\x09| package |\x0a\x09\x0a\x09package := self named: aPackageName.\x0a\x09package transport: aTransport.\x0a\x09\x0a\x09^ package",
+messageSends: ["named:", "transport:"],
+referencedClasses: []
+}),
+smalltalk.Package.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "sortedClasses:",
@@ -2026,6 +2113,22 @@ referencedClasses: []
 }),
 smalltalk.Smalltalk);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "basicCreatePackage:",
+category: 'private',
+fn: function (packageName){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return smalltalk.addPackage(packageName);
+return self}, function($ctx1) {$ctx1.fill(self,"basicCreatePackage:",{packageName:packageName},smalltalk.Smalltalk)})},
+args: ["packageName"],
+source: "basicCreatePackage: packageName\x0a\x09\x22Create and bind a new bare package with given name and return it.\x22\x0a\x09<return smalltalk.addPackage(packageName)>",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Smalltalk);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "basicParse:",
@@ -2064,13 +2167,24 @@ selector: "createPackage:",
 category: 'packages',
 fn: function (packageName){
 var self=this;
+var package_,announcement;
+function $PackageAdded(){return smalltalk.PackageAdded||(typeof PackageAdded=="undefined"?nil:PackageAdded)}
+function $SystemAnnouncer(){return smalltalk.SystemAnnouncer||(typeof SystemAnnouncer=="undefined"?nil:SystemAnnouncer)}
 return smalltalk.withContext(function($ctx1) { 
-return smalltalk.addPackage(packageName);
-return self}, function($ctx1) {$ctx1.fill(self,"createPackage:",{packageName:packageName},smalltalk.Smalltalk)})},
+var $1,$2,$3;
+package_=self._basicCreatePackage_(packageName);
+$1=_st($PackageAdded())._new();
+_st($1)._package_(package_);
+$2=_st($1)._yourself();
+announcement=$2;
+_st(_st($SystemAnnouncer())._current())._announce_(announcement);
+$3=package_;
+return $3;
+}, function($ctx1) {$ctx1.fill(self,"createPackage:",{packageName:packageName,package_:package_,announcement:announcement},smalltalk.Smalltalk)})},
 args: ["packageName"],
-source: "createPackage: packageName\x0a\x09\x22Create and bind a new bare package with given name and return it.\x22\x0a\x09<return smalltalk.addPackage(packageName)>",
-messageSends: [],
-referencedClasses: []
+source: "createPackage: packageName\x0a\x09| package announcement |\x0a\x09\x0a\x09package := self basicCreatePackage: packageName.\x0a\x09announcement := PackageAdded new\x0a\x09\x09package: package;\x0a\x09\x09yourself.\x0a\x09\x09\x0a\x09SystemAnnouncer current announce: announcement.\x0a\x09\x0a\x09^ package",
+messageSends: ["basicCreatePackage:", "package:", "new", "yourself", "announce:", "current"],
+referencedClasses: ["PackageAdded", "SystemAnnouncer"]
 }),
 smalltalk.Smalltalk);
 

+ 13 - 1
st/Importer-Exporter.st

@@ -599,7 +599,7 @@ ajaxPutAt: aURL data: aString
 			'type' -> 'PUT'.
 			'data' -> aString.
 			'contentType' -> 'text/plain;charset=UTF-8'.
-			'error' -> [ :xhr | self error: 'Commiting ' , aURL , ' failed with reason: "' , (xhr responseText) , '"'] }
+			'error' -> [ :xhr | self alert: 'Commiting ' , aURL , ' failed with reason: "' , (xhr responseText) , '"'] }
 ! !
 
 PackageHandler subclass: #AmdPackageHandler
@@ -663,6 +663,10 @@ commitHandlerClass
 	self subclassResponsibility
 !
 
+definition
+	^ ''
+!
+
 package
 	^ package
 !
@@ -763,6 +767,14 @@ commitHandlerClass
 	^ AmdPackageHandler
 !
 
+definition
+	^ String streamContents: [ :stream |
+		stream 
+			nextPutAll: self class name;
+			nextPutAll: ' namespace: ';
+			nextPutAll: '''', self namespace, '''' ]
+!
+
 namespace
 	^ namespace ifNil: [ self defaultNamespace ]
 !

+ 42 - 6
st/Kernel-Infrastructure.st

@@ -489,6 +489,18 @@ basicTransport
 	<return self.transport>
 !
 
+definition
+	^ String streamContents: [ :stream |
+		stream 
+			nextPutAll: self class name;
+			nextPutAll: String lf, String tab;
+			nextPutAll: ' named: ';
+			nextPutAll: '''', self name, '''';
+			nextPutAll: String lf, String tab;
+			nextPutAll:  ' transport: (';
+			nextPutAll: self transport definition, ')' ]
+!
+
 name
 	<return self.pkgName>
 !
@@ -509,7 +521,8 @@ transport
 !
 
 transport: aPackageTransport
-	transport := aPackageTransport
+	transport := aPackageTransport.
+	aPackageTransport package: self
 ! !
 
 !Package methodsFor: 'classes'!
@@ -577,13 +590,23 @@ Package class instanceVariableNames: 'defaultCommitPathJs defaultCommitPathSt'!
 !Package class methodsFor: 'accessing'!
 
 named: aPackageName
-
-	^Smalltalk current packageAt: aPackageName
+	^ Smalltalk current 
+		packageAt: aPackageName
+		ifAbsent: [ 
+			Smalltalk current createPackage: aPackageName ]
 !
 
 named: aPackageName ifAbsent: aBlock
+	^ Smalltalk current packageAt: aPackageName ifAbsent: aBlock
+!
 
-	^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
+named: aPackageName transport: aTransport
+	| package |
+	
+	package := self named: aPackageName.
+	package transport: aTransport.
+	
+	^ package
 ! !
 
 !Package class methodsFor: 'sorting'!
@@ -867,8 +890,16 @@ globalJsVariables
 !Smalltalk methodsFor: 'packages'!
 
 createPackage: packageName
-	"Create and bind a new bare package with given name and return it."
-	<return smalltalk.addPackage(packageName)>
+	| package announcement |
+	
+	package := self basicCreatePackage: packageName.
+	announcement := PackageAdded new
+		package: package;
+		yourself.
+		
+	SystemAnnouncer current announce: announcement.
+	
+	^ package
 !
 
 packageAt: packageName
@@ -914,6 +945,11 @@ renamePackage: packageName to: newName
 
 !Smalltalk methodsFor: 'private'!
 
+basicCreatePackage: packageName
+	"Create and bind a new bare package with given name and return it."
+	<return smalltalk.addPackage(packageName)>
+!
+
 basicParse: aString
 	<return smalltalk.parser.parse(aString)>
 !