Browse Source

Using template tag for iterating contents.

Herbert Vojčík 10 years ago
parent
commit
4c2869f183
4 changed files with 41 additions and 22 deletions
  1. 5 5
      js/Trapped-Frontend.js
  2. 29 13
      js/Trapped-Processors.js
  3. 2 2
      st/Trapped-Frontend.st
  4. 5 2
      st/Trapped-Processors.st

+ 5 - 5
js/Trapped-Frontend.js

@@ -1355,12 +1355,12 @@ var self=this;
 return smalltalk.withContext(function($ctx1) { 
 self._with_((function(html){
 return smalltalk.withContext(function($ctx2) {
-return _st(_st(html)._noscript())._trapIter_after_(path,aBlock);
+return _st(_st(html)._tag_("template"))._trapIter_after_(path,aBlock);
 }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"trapIter:do:",{path:path,aBlock:aBlock},smalltalk.HTMLCanvas)})},
 args: ["path", "aBlock"],
-source: "trapIter: path do: aBlock\x0a    self with: [ :html | html noscript trapIter: path after: aBlock ]",
-messageSends: ["with:", "trapIter:after:", "noscript"],
+source: "trapIter: path do: aBlock\x0a    self with: [ :html | (html tag: 'template') trapIter: path after: aBlock ]",
+messageSends: ["with:", "trapIter:after:", "tag:"],
 referencedClasses: []
 }),
 smalltalk.HTMLCanvas);
@@ -1498,7 +1498,7 @@ function $TagBrush(){return smalltalk.TagBrush||(typeof TagBrush=="undefined"?ni
 function $Trapped(){return smalltalk.Trapped||(typeof Trapped=="undefined"?nil:Trapped)}
 return smalltalk.withContext(function($ctx1) { 
 var $2,$1;
-$2="<noscript />"._asJQuery();
+$2="<script type=\x22text/plain\x22 />"._asJQuery();
 $ctx1.sendIdx["asJQuery"]=1;
 $1=_st($2)._insertAfter_(self._asJQuery());
 end=_st($TagBrush())._fromJQuery_canvas_($1,self["@canvas"]);
@@ -1508,7 +1508,7 @@ return _st($Trapped())._loop_between_and_do_(model,self,end,aBlock);
 }, function($ctx2) {$ctx2.fillBlock({model:model},$ctx1,1)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"trapIter:after:",{path:path,aBlock:aBlock,end:end},smalltalk.TagBrush)})},
 args: ["path", "aBlock"],
-source: "trapIter: path after: aBlock\x0a\x09| end |\x0a\x09end := TagBrush fromJQuery: ('<noscript />' asJQuery insertAfter: self asJQuery) canvas: canvas.\x0a    self trap: path read: [ :model |\x0a    \x09Trapped loop: model between: self and: end do: aBlock.\x0a    ]",
+source: "trapIter: path after: aBlock\x0a\x09| end |\x0a\x09end := TagBrush fromJQuery: ('<script type=\x22text/plain\x22 />' asJQuery insertAfter: self asJQuery) canvas: canvas.\x0a    self trap: path read: [ :model |\x0a    \x09Trapped loop: model between: self and: end do: aBlock.\x0a    ]",
 messageSends: ["fromJQuery:canvas:", "insertAfter:", "asJQuery", "trap:read:", "loop:between:and:do:"],
 referencedClasses: ["TagBrush", "Trapped"]
 }),

+ 29 - 13
js/Trapped-Processors.js

@@ -406,30 +406,46 @@ selector: "toView:",
 category: 'data transformation',
 fn: function (aDataCarrier){
 var self=this;
-var frozen,contents;
+var frozen,contents,tag;
 function $Trapped(){return smalltalk.Trapped||(typeof Trapped=="undefined"?nil:Trapped)}
 return smalltalk.withContext(function($ctx1) { 
-var $3,$2,$1,$5,$4;
+var $3,$2,$1,$4,$7,$6,$5,$10,$9,$8,$12,$11;
 frozen=_st(aDataCarrier)._copy();
 $3=_st(frozen)._target();
 $ctx1.sendIdx["target"]=1;
-$2=_st($3)._asJQuery();
+$2=_st($3)._element();
+$ctx1.sendIdx["element"]=1;
+$1=_st($2)._at_("tagName");
+tag=_st($1)._asLowercase();
+$4=_st(tag).__eq("template");
+if(smalltalk.assert($4)){
+$7=_st(frozen)._target();
+$ctx1.sendIdx["target"]=2;
+$6=_st($7)._element();
+$5=_st($6)._content();
+contents=_st($5)._asJQuery();
 $ctx1.sendIdx["asJQuery"]=1;
-$1=_st($2)._contents();
-contents=_st($1)._detach();
+} else {
+$10=_st(frozen)._target();
+$ctx1.sendIdx["target"]=3;
+$9=_st($10)._asJQuery();
+$ctx1.sendIdx["asJQuery"]=2;
+$8=_st($9)._contents();
+contents=_st($8)._detach();
+};
 _st(_st(frozen)._target())._trapIter_after_([],(function(html){
 return smalltalk.withContext(function($ctx2) {
-$5=_st(html)._root();
+$12=_st(html)._root();
 $ctx2.sendIdx["root"]=1;
-$4=_st($5)._asJQuery();
-$ctx2.sendIdx["asJQuery"]=2;
-_st($4)._append_(_st(contents)._clone());
+$11=_st($12)._asJQuery();
+$ctx2.sendIdx["asJQuery"]=3;
+_st($11)._append_(_st(contents)._clone());
 return _st(_st($Trapped())._current())._injectToJQuery_(_st(_st(html)._root())._asJQuery());
-}, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)})}));
-return self}, function($ctx1) {$ctx1.fill(self,"toView:",{aDataCarrier:aDataCarrier,frozen:frozen,contents:contents},smalltalk.TrappedProcessorLoopContents)})},
+}, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,3)})}));
+return self}, function($ctx1) {$ctx1.fill(self,"toView:",{aDataCarrier:aDataCarrier,frozen:frozen,contents:contents,tag:tag},smalltalk.TrappedProcessorLoopContents)})},
 args: ["aDataCarrier"],
-source: "toView: aDataCarrier\x0a\x09| frozen contents |\x0a\x09frozen := aDataCarrier copy.\x0a\x09contents := frozen target asJQuery contents detach.\x0a\x09frozen target trapIter: #() after: [ :html |\x0a\x09\x09html root asJQuery append: contents clone.\x0a\x09\x09Trapped current injectToJQuery: html root asJQuery ]",
-messageSends: ["copy", "detach", "contents", "asJQuery", "target", "trapIter:after:", "append:", "root", "clone", "injectToJQuery:", "current"],
+source: "toView: aDataCarrier\x0a\x09| frozen contents tag |\x0a\x09frozen := aDataCarrier copy.\x0a\x09tag := (frozen target element at: 'tagName') asLowercase.\x0a\x09contents := tag = 'template'\x0a\x09\x09ifTrue: [ frozen target element content asJQuery ]\x0a\x09\x09ifFalse: [ frozen target asJQuery contents detach ].\x0a\x09frozen target trapIter: #() after: [ :html |\x0a\x09\x09html root asJQuery append: contents clone.\x0a\x09\x09Trapped current injectToJQuery: html root asJQuery ]",
+messageSends: ["copy", "asLowercase", "at:", "element", "target", "ifTrue:ifFalse:", "=", "asJQuery", "content", "detach", "contents", "trapIter:after:", "append:", "root", "clone", "injectToJQuery:", "current"],
 referencedClasses: ["Trapped"]
 }),
 smalltalk.TrappedProcessorLoopContents);

+ 2 - 2
st/Trapped-Frontend.st

@@ -487,7 +487,7 @@ trapDescend: aBlock
 !HTMLCanvas methodsFor: '*Trapped-Frontend'!
 
 trapIter: path do: aBlock
-    self with: [ :html | html noscript trapIter: path after: aBlock ]
+    self with: [ :html | (html tag: 'template') trapIter: path after: aBlock ]
 ! !
 
 !TagBrush methodsFor: '*Trapped-Frontend'!
@@ -527,7 +527,7 @@ trapGuard: anArray contents: aBlock
 
 trapIter: path after: aBlock
 	| end |
-	end := TagBrush fromJQuery: ('<noscript />' asJQuery insertAfter: self asJQuery) canvas: canvas.
+	end := TagBrush fromJQuery: ('<script type="text/plain" />' asJQuery insertAfter: self asJQuery) canvas: canvas.
     self trap: path read: [ :model |
     	Trapped loop: model between: self and: end do: aBlock.
     ]

+ 5 - 2
st/Trapped-Processors.st

@@ -219,9 +219,12 @@ noscript, ins or del).!
 !TrappedProcessorLoopContents methodsFor: 'data transformation'!
 
 toView: aDataCarrier
-	| frozen contents |
+	| frozen contents tag |
 	frozen := aDataCarrier copy.
-	contents := frozen target asJQuery contents detach.
+	tag := (frozen target element at: 'tagName') asLowercase.
+	contents := tag = 'template'
+		ifTrue: [ frozen target element content asJQuery ]
+		ifFalse: [ frozen target asJQuery contents detach ].
 	frozen target trapIter: #() after: [ :html |
 		html root asJQuery append: contents clone.
 		Trapped current injectToJQuery: html root asJQuery ]