Herbert Vojčík пре 9 година
родитељ
комит
f2ddf82e7f
4 измењених фајлова са 116 додато и 13 уклоњено
  1. 59 0
      src/Silk-Tests.js
  2. 20 0
      src/Silk-Tests.st
  3. 28 10
      src/Silk.js
  4. 9 3
      src/Silk.st

+ 59 - 0
src/Silk-Tests.js

@@ -190,6 +190,65 @@ messageSends: ["asSilk", "TABLE", "TD:", "TR", "assertBodyEndsWith:"]
 }),
 $globals.SilkTest);
 
+$core.addMethod(
+$core.method({
+selector: "testInsertTable2",
+protocol: 'testing',
+fn: function (){
+var self=this;
+var d,tbl;
+function $Silk(){return $globals.Silk||(typeof Silk=="undefined"?nil:Silk)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1,$2,$4,$5,$6,$3,$8,$10,$11,$9,$7;
+d="html body div#fixture"._asSilk();
+tbl=$recv(d)._TABLE();
+$1=tbl;
+$2=$1;
+$4=$recv($Silk())._TD_("A");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["TD:"]=1;
+//>>excludeEnd("ctx");
+$5=$recv($Silk())._TD_("B");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["TD:"]=2;
+//>>excludeEnd("ctx");
+$6=$recv($Silk())._TD_("C");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["TD:"]=3;
+//>>excludeEnd("ctx");
+$3=[$4,$5,$6];
+$recv($2)._TR_($3);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["TR:"]=1;
+//>>excludeEnd("ctx");
+$8=$1;
+$10=$recv($Silk())._TD_("D");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["TD:"]=4;
+//>>excludeEnd("ctx");
+$11=$recv($Silk())._TD_("E");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["TD:"]=5;
+//>>excludeEnd("ctx");
+$9=[$10,$11,$recv($Silk())._TD_("F")];
+$7=$recv($8)._TR_($9);
+self._assertBodyEndsWith_(">sentinel<table><tr><td>A</td><td>B</td><td>C</td></tr><tr><td>D</td><td>E</td><td>F</td></tr></table></div>");
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"testInsertTable2",{d:d,tbl:tbl},$globals.SilkTest)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "testInsertTable2\x0a\x0a\x09| d tbl  |\x0a\x0a\x09d := 'html body div#fixture' asSilk.\x0a\x0a\x09tbl := d TABLE.\x0a\x0a\x09tbl TR: {\x0a\x09\x09Silk TD: 'A'.\x0a\x09\x09Silk TD: 'B'.\x0a\x09\x09Silk TD: 'C'};\x0a\x09\x09TR: {\x0a\x09\x09Silk TD: 'D'.\x0a\x09\x09Silk TD: 'E'.\x0a\x09\x09Silk TD: 'F'}.\x0a\x09\x0a\x09self assertBodyEndsWith: '>sentinel<table><tr><td>A</td><td>B</td><td>C</td></tr><tr><td>D</td><td>E</td><td>F</td></tr></table></div>'",
+referencedClasses: ["Silk"],
+//>>excludeEnd("ide");
+messageSends: ["asSilk", "TABLE", "TR:", "TD:", "assertBodyEndsWith:"]
+}),
+$globals.SilkTest);
+
 $core.addMethod(
 $core.method({
 selector: "testNestedDIVsWithAttributes",

+ 20 - 0
src/Silk-Tests.st

@@ -63,6 +63,26 @@ testInsertTable
 	self assertBodyEndsWith: '>sentinel<table><tr><td>A</td><td>B</td><td>C</td></tr><tr><td>D</td><td>E</td><td>F</td></tr></table></div>'
 !
 
+testInsertTable2
+
+	| d tbl  |
+
+	d := 'html body div#fixture' asSilk.
+
+	tbl := d TABLE.
+
+	tbl TR: {
+		Silk TD: 'A'.
+		Silk TD: 'B'.
+		Silk TD: 'C'};
+		TR: {
+		Silk TD: 'D'.
+		Silk TD: 'E'.
+		Silk TD: 'F'}.
+	
+	self assertBodyEndsWith: '>sentinel<table><tr><td>A</td><td>B</td><td>C</td></tr><tr><td>D</td><td>E</td><td>F</td></tr></table></div>'
+!
+
 testNestedDIVsWithAttributes
  "demonstrates how DIVs are nested and given attributes"
 	| s |

+ 28 - 10
src/Silk.js

@@ -128,13 +128,16 @@ selector: "doesNotUnderstand:",
 protocol: 'message handling',
 fn: function (aMessage){
 var self=this;
-var selector;
+var selector,newElement,useArg;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$3,$4,$5;
+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)){
 $2=(
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -149,9 +152,19 @@ $ctx1.sendIdx["doesNotUnderstand:"]=1;
 //>>excludeEnd("ctx");
 return $2;
 };
-$3=$recv(selector)._includes_(":");
+$3=$recv($recv(selector)._last()).__eq(":");
 if($core.assert($3)){
-$4=(
+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");
@@ -159,20 +172,25 @@ $globals.Silk.klass.superclass.fn.prototype._doesNotUnderstand_.apply($recv(self
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
-return $4;
-};
-$5=self._newElement_($recv(selector)._asLowercase());
 return $5;
+};
+newElement=self._newElement_($recv(selector)._asLowercase());
+$6=useArg;
+if($core.assert($6)){
+$recv(newElement).__lt_lt($recv($recv(aMessage)._arguments())._first());
+};
+$7=newElement;
+return $7;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"doesNotUnderstand:",{aMessage:aMessage,selector:selector},$globals.Silk.klass)});
+}, function($ctx1) {$ctx1.fill(self,"doesNotUnderstand:",{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\x22\x0a\x09| selector |\x0a\x09selector := aMessage selector.\x0a\x09selector asUppercase = selector\x0a\x09\x09ifFalse: [ ^ super doesNotUnderstand: aMessage ].\x0a\x09(selector includes: ':')\x0a\x09\x09ifTrue: [ ^ super doesNotUnderstand: aMessage ].\x0a\x09^ self newElement: selector asLowercase",
+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",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["selector", "ifFalse:", "=", "asUppercase", "doesNotUnderstand:", "ifTrue:", "includes:", "newElement:", "asLowercase"]
+messageSends: ["selector", "ifFalse:", "=", "asUppercase", "doesNotUnderstand:", "ifTrue:ifFalse:", "last", "allButLast", "ifTrue:", "includes:", "newElement:", "asLowercase", "<<", "first", "arguments"]
 }),
 $globals.Silk.klass);
 

+ 9 - 3
src/Silk.st

@@ -74,14 +74,20 @@ nextPut: anObject
 !Silk class methodsFor: 'message handling'!
 
 doesNotUnderstand: aMessage
-	"`Silk DIV` creates a div element"
-	| selector |
+	"`Silk DIV` creates a div element.
+	`Silk DIV: anObject` creates a div element 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 ].
-	^ self newElement: selector asLowercase
+	newElement := self newElement: selector asLowercase.
+	useArg ifTrue: [ newElement << aMessage arguments first ].
+	^ newElement
 ! !
 
 !Association methodsFor: '*Silk'!