Forráskód Böngészése

DNU element creation extracted

Herbert Vojčík 9 éve
szülő
commit
a72a5c7187
2 módosított fájl, 80 hozzáadás és 94 törlés
  1. 61 75
      src/Silk.js
  2. 19 19
      src/Silk.st

+ 61 - 75
src/Silk.js

@@ -14,17 +14,12 @@ selector: "doesNotUnderstand:",
 protocol: 'writing',
 fn: function (aMessage){
 var self=this;
-var selector,newElement,useArg;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$3,$4,$5,$6,$7;
-selector=$recv(aMessage)._selector();
-$1=$recv($recv(selector)._asUppercase()).__eq(selector);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["="]=1;
-//>>excludeEnd("ctx");
-if(!$core.assert($1)){
+var $1,$2,$receiver;
+$1=$recv(self._class())._tryMakeDnuElement_(aMessage);
+if(($receiver = $1) == null || $receiver.isNil){
 $2=(
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = true, 
@@ -33,54 +28,24 @@ $globals.Silk.superclass.fn.prototype._doesNotUnderstand_.apply($recv(self), [aM
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["doesNotUnderstand:"]=1;
-//>>excludeEnd("ctx");
 return $2;
-};
-$3=$recv($recv(selector)._last()).__eq(":");
-if($core.assert($3)){
-useArg=true;
-useArg;
-selector=$recv(selector)._allButLast();
-selector;
 } else {
-useArg=false;
-useArg;
-};
-$4=$recv(selector)._includes_(":");
-if($core.assert($4)){
-$5=(
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = true, 
-//>>excludeEnd("ctx");
-$globals.Silk.superclass.fn.prototype._doesNotUnderstand_.apply($recv(self), [aMessage]));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = false;
-//>>excludeEnd("ctx");;
-return $5;
-};
-newElement=$recv(self._class())._newElement_($recv(selector)._asLowercase());
+var newElement;
+newElement=$receiver;
 self.__lt_lt(newElement);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["<<"]=1;
-//>>excludeEnd("ctx");
-$6=useArg;
-if($core.assert($6)){
-$recv(newElement).__lt_lt($recv($recv(aMessage)._arguments())._first());
+return newElement;
 };
-$7=newElement;
-return $7;
+return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"doesNotUnderstand:",{aMessage:aMessage,selector:selector,newElement:newElement,useArg:useArg},$globals.Silk)});
+}, function($ctx1) {$ctx1.fill(self,"doesNotUnderstand:",{aMessage:aMessage},$globals.Silk)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aMessage"],
-source: "doesNotUnderstand: aMessage\x0a\x09\x22`aSilk DIV` creates a div element and inserts it.\x0a\x09`aSilk DIV: anObject` creates a div element, inserts it\x0a\x09and puts contents in it\x22\x0a\x09| selector newElement useArg |\x0a\x09selector := aMessage selector.\x0a\x09selector asUppercase = selector\x0a\x09\x09ifFalse: [ ^ super doesNotUnderstand: aMessage ].\x0a\x09selector last = ':'\x0a\x09\x09ifTrue: [ useArg := true. selector := selector allButLast ]\x0a\x09\x09ifFalse: [ useArg := false ].\x0a\x09(selector includes: ':')\x0a\x09\x09ifTrue: [ ^ super doesNotUnderstand: aMessage ].\x0a\x09newElement := self class newElement: selector asLowercase.\x0a\x09self << newElement.\x0a\x09useArg ifTrue: [ newElement << aMessage arguments first ].\x0a\x09^ newElement",
+source: "doesNotUnderstand: aMessage\x0a\x09\x22`aSilk DIV` creates a div element and inserts it.\x0a\x09`aSilk DIV: anObject` creates a div element, inserts it\x0a\x09and puts contents in it\x22\x0a\x09(self class tryMakeDnuElement: aMessage)\x0a\x09\x09ifNil: [ ^ super doesNotUnderstand: aMessage ]\x0a\x09\x09ifNotNil: [ :newElement | self << newElement. ^ newElement ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["selector", "ifFalse:", "=", "asUppercase", "doesNotUnderstand:", "ifTrue:ifFalse:", "last", "allButLast", "ifTrue:", "includes:", "newElement:", "class", "asLowercase", "<<", "first", "arguments"]
+messageSends: ["ifNil:ifNotNil:", "tryMakeDnuElement:", "class", "doesNotUnderstand:", "<<"]
 }),
 $globals.Silk);
 
@@ -128,17 +93,12 @@ selector: "doesNotUnderstand:",
 protocol: 'message handling',
 fn: function (aMessage){
 var self=this;
-var selector,newElement,useArg;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$3,$4,$5,$6,$7;
-selector=$recv(aMessage)._selector();
-$1=$recv($recv(selector)._asUppercase()).__eq(selector);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["="]=1;
-//>>excludeEnd("ctx");
-if(!$core.assert($1)){
+var $1,$2,$receiver;
+$1=self._tryMakeDnuElement_(aMessage);
+if(($receiver = $1) == null || $receiver.isNil){
 $2=(
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = true, 
@@ -147,13 +107,47 @@ $globals.Silk.klass.superclass.fn.prototype._doesNotUnderstand_.apply($recv(self
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
+return $2;
+} else {
+var newElement;
+newElement=$receiver;
+return newElement;
+};
+return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["doesNotUnderstand:"]=1;
+}, function($ctx1) {$ctx1.fill(self,"doesNotUnderstand:",{aMessage:aMessage},$globals.Silk.klass)});
 //>>excludeEnd("ctx");
-return $2;
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aMessage"],
+source: "doesNotUnderstand: aMessage\x0a\x09\x22`Silk DIV` creates a div element.\x0a\x09`Silk DIV: anObject` creates a div element and puts contents in it\x22\x0a\x09(self tryMakeDnuElement: aMessage)\x0a\x09\x09ifNil: [ ^ super doesNotUnderstand: aMessage ]\x0a\x09\x09ifNotNil: [ :newElement | ^ newElement ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["ifNil:ifNotNil:", "tryMakeDnuElement:", "doesNotUnderstand:"]
+}),
+$globals.Silk.klass);
+
+$core.addMethod(
+$core.method({
+selector: "tryMakeDnuElement:",
+protocol: 'instance creation',
+fn: function (aMessage){
+var self=this;
+var selector,newElement,useArg;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1,$2,$3,$4,$5;
+selector=$recv(aMessage)._selector();
+$1=$recv($recv(selector)._asUppercase()).__eq(selector);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["="]=1;
+//>>excludeEnd("ctx");
+if(!$core.assert($1)){
+return nil;
 };
-$3=$recv($recv(selector)._last()).__eq(":");
-if($core.assert($3)){
+$2=$recv($recv(selector)._last()).__eq(":");
+if($core.assert($2)){
 useArg=true;
 useArg;
 selector=$recv(selector)._allButLast();
@@ -162,35 +156,27 @@ selector;
 useArg=false;
 useArg;
 };
-$4=$recv(selector)._includes_(":");
-if($core.assert($4)){
-$5=(
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = true, 
-//>>excludeEnd("ctx");
-$globals.Silk.klass.superclass.fn.prototype._doesNotUnderstand_.apply($recv(self), [aMessage]));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = false;
-//>>excludeEnd("ctx");;
-return $5;
+$3=$recv(selector)._includes_(":");
+if($core.assert($3)){
+return nil;
 };
 newElement=self._newElement_($recv(selector)._asLowercase());
-$6=useArg;
-if($core.assert($6)){
+$4=useArg;
+if($core.assert($4)){
 $recv(newElement).__lt_lt($recv($recv(aMessage)._arguments())._first());
 };
-$7=newElement;
-return $7;
+$5=newElement;
+return $5;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"doesNotUnderstand:",{aMessage:aMessage,selector:selector,newElement:newElement,useArg:useArg},$globals.Silk.klass)});
+}, function($ctx1) {$ctx1.fill(self,"tryMakeDnuElement:",{aMessage:aMessage,selector:selector,newElement:newElement,useArg:useArg},$globals.Silk.klass)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aMessage"],
-source: "doesNotUnderstand: aMessage\x0a\x09\x22`Silk DIV` creates a div element.\x0a\x09`Silk DIV: anObject` creates a div element and puts contents in it\x22\x0a\x09| selector newElement useArg |\x0a\x09selector := aMessage selector.\x0a\x09selector asUppercase = selector\x0a\x09\x09ifFalse: [ ^ super doesNotUnderstand: aMessage ].\x0a\x09selector last = ':'\x0a\x09\x09ifTrue: [ useArg := true. selector := selector allButLast ]\x0a\x09\x09ifFalse: [ useArg := false ].\x0a\x09(selector includes: ':')\x0a\x09\x09ifTrue: [ ^ super doesNotUnderstand: aMessage ].\x0a\x09newElement := self newElement: selector asLowercase.\x0a\x09useArg ifTrue: [ newElement << aMessage arguments first ].\x0a\x09^ newElement",
+source: "tryMakeDnuElement: aMessage\x0a\x09\x22`DIV` creates a div element.\x0a\x09`DIV: anObject` creates a div element and puts contents in it\x22\x0a\x09| selector newElement useArg |\x0a\x09selector := aMessage selector.\x0a\x09selector asUppercase = selector\x0a\x09\x09ifFalse: [ ^ nil ].\x0a\x09selector last = ':'\x0a\x09\x09ifTrue: [ useArg := true. selector := selector allButLast ]\x0a\x09\x09ifFalse: [ useArg := false ].\x0a\x09(selector includes: ':')\x0a\x09\x09ifTrue: [ ^ nil ].\x0a\x09newElement := self newElement: selector asLowercase.\x0a\x09useArg ifTrue: [ newElement << aMessage arguments first ].\x0a\x09^ newElement",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["selector", "ifFalse:", "=", "asUppercase", "doesNotUnderstand:", "ifTrue:ifFalse:", "last", "allButLast", "ifTrue:", "includes:", "newElement:", "asLowercase", "<<", "first", "arguments"]
+messageSends: ["selector", "ifFalse:", "=", "asUppercase", "ifTrue:ifFalse:", "last", "allButLast", "ifTrue:", "includes:", "newElement:", "asLowercase", "<<", "first", "arguments"]
 }),
 $globals.Silk.klass);
 

+ 19 - 19
src/Silk.st

@@ -47,19 +47,9 @@ doesNotUnderstand: aMessage
 	"`aSilk DIV` creates a div element and inserts it.
 	`aSilk DIV: anObject` creates a div element, inserts it
 	and puts contents in it"
-	| selector newElement useArg |
-	selector := aMessage selector.
-	selector asUppercase = selector
-		ifFalse: [ ^ super doesNotUnderstand: aMessage ].
-	selector last = ':'
-		ifTrue: [ useArg := true. selector := selector allButLast ]
-		ifFalse: [ useArg := false ].
-	(selector includes: ':')
-		ifTrue: [ ^ super doesNotUnderstand: aMessage ].
-	newElement := self class newElement: selector asLowercase.
-	self << newElement.
-	useArg ifTrue: [ newElement << aMessage arguments first ].
-	^ newElement
+	(self class tryMakeDnuElement: aMessage)
+		ifNil: [ ^ super doesNotUnderstand: aMessage ]
+		ifNotNil: [ :newElement | self << newElement. ^ newElement ]
 !
 
 nextPut: anObject
@@ -71,25 +61,35 @@ nextPut: anObject
 		ifNil: [ super nextPut: anObject ]
 ! !
 
-!Silk class methodsFor: 'message handling'!
+!Silk class methodsFor: 'instance creation'!
 
-doesNotUnderstand: aMessage
-	"`Silk DIV` creates a div element.
-	`Silk DIV: anObject` creates a div element and puts contents in it"
+tryMakeDnuElement: aMessage
+	"`DIV` creates a div element.
+	`DIV: anObject` creates a div element and puts contents in it"
 	| selector newElement useArg |
 	selector := aMessage selector.
 	selector asUppercase = selector
-		ifFalse: [ ^ super doesNotUnderstand: aMessage ].
+		ifFalse: [ ^ nil ].
 	selector last = ':'
 		ifTrue: [ useArg := true. selector := selector allButLast ]
 		ifFalse: [ useArg := false ].
 	(selector includes: ':')
-		ifTrue: [ ^ super doesNotUnderstand: aMessage ].
+		ifTrue: [ ^ nil ].
 	newElement := self newElement: selector asLowercase.
 	useArg ifTrue: [ newElement << aMessage arguments first ].
 	^ newElement
 ! !
 
+!Silk class methodsFor: 'message handling'!
+
+doesNotUnderstand: aMessage
+	"`Silk DIV` creates a div element.
+	`Silk DIV: anObject` creates a div element and puts contents in it"
+	(self tryMakeDnuElement: aMessage)
+		ifNil: [ ^ super doesNotUnderstand: aMessage ]
+		ifNotNil: [ :newElement | ^ newElement ]
+! !
+
 !Association methodsFor: '*Silk'!
 
 renderOnSilk: aSilk