Browse Source

loopContents processor

Herbert Vojčík 10 years ago
parent
commit
00da2fbabf
5 changed files with 95 additions and 1 deletions
  1. 19 0
      js/Trapped-Frontend.js
  2. 38 0
      js/Trapped-Processors.js
  3. 6 1
      meta/demo.html
  4. 4 0
      st/Trapped-Frontend.st
  5. 28 0
      st/Trapped-Processors.st

+ 19 - 0
js/Trapped-Frontend.js

@@ -577,6 +577,25 @@ referencedClasses: ["TrappedProcessorInputValue"]
 }),
 smalltalk.TrappedProcessor.klass);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "loopContents",
+category: 'factory',
+fn: function (){
+var self=this;
+function $TrappedProcessorLoopContents(){return smalltalk.TrappedProcessorLoopContents||(typeof TrappedProcessorLoopContents=="undefined"?nil:TrappedProcessorLoopContents)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st($TrappedProcessorLoopContents())._new();
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"loopContents",{},smalltalk.TrappedProcessor.klass)})},
+args: [],
+source: "loopContents\x0a\x09^TrappedProcessorLoopContents new",
+messageSends: ["new"],
+referencedClasses: ["TrappedProcessorLoopContents"]
+}),
+smalltalk.TrappedProcessor.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "loopProc",

+ 38 - 0
js/Trapped-Processors.js

@@ -437,6 +437,44 @@ smalltalk.TrappedProcessorLoopBase);
 
 
 
+smalltalk.addClass('TrappedProcessorLoopContents', smalltalk.TrappedProcessorLoopBase, [], 'Trapped-Processors');
+smalltalk.TrappedProcessorLoopContents.comment="I am used to loop over data and repeat the contents\x0aof the brush I am installed on.\x0a\x0aI save the brush contents, then I observe the data in the model,\x0aand when it changes, I loop over it\x0aand restore the contents from remembered state\x0aand interpret all contained data-trap attributes inside\x0afor each element, putting the result _after_ my brush.\x0a\x0aMy brush itself should be as least visible as possible,\x0aas it only serve as a position flag (use for example\x0anoscript, ins or del).";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "toView:",
+category: 'data transformation',
+fn: function (aDataCarrier){
+var self=this;
+var frozen,contents;
+function $Trapped(){return smalltalk.Trapped||(typeof Trapped=="undefined"?nil:Trapped)}
+return smalltalk.withContext(function($ctx1) { 
+var $3,$2,$1,$5,$4;
+frozen=_st(aDataCarrier)._copy();
+$3=_st(frozen)._target();
+$ctx1.sendIdx["target"]=1;
+$2=_st($3)._asJQuery();
+$ctx1.sendIdx["asJQuery"]=1;
+$1=_st($2)._contents();
+contents=_st($1)._detach();
+_st(_st(frozen)._target())._trapIter_after_([],(function(html){
+return smalltalk.withContext(function($ctx2) {
+$5=_st(html)._root();
+$ctx2.sendIdx["root"]=1;
+$4=_st($5)._asJQuery();
+$ctx2.sendIdx["asJQuery"]=2;
+_st($4)._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)})},
+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"],
+referencedClasses: ["Trapped"]
+}),
+smalltalk.TrappedProcessorLoopContents);
+
+
+
 smalltalk.addClass('TrappedProcessorLoopProc', smalltalk.TrappedProcessorLoopBase, [], 'Trapped-Processors');
 smalltalk.TrappedProcessorLoopProc.comment="I am used to loop over data and repeat the contents filling process\x0aof the brush I am installed on.\x0a\x0aI observe the data in the model,\x0aand when it changes, I loop over it\x0aand run the rest of the processing chain\x0afor each element, putting the result _after_ my brush.\x0a\x0aMy brush itself should be as least visible as possible,\x0aas it only serve as a position flag (use for example\x0anoscript, ins or del).";
 smalltalk.addMethod(

+ 6 - 1
meta/demo.html

@@ -40,7 +40,12 @@
 <div data-trap=": (guardContents (#todos #notNil))">
     <span data-trap="#remaining"></span> of <span data-trap="#todos #size"></span> remaning
     [ <a href="" data-trap=": (signal archive) whenClicked">archive</a> ]
-    <ul><noscript data-trap="#todos: loopProc (widget TodoItemWidget)"></noscript></ul>
+    <ul><ins data-trap="#todos: loopContents">
+        <li>
+            <input type="checkbox" data-trap="done: inputChecked" />
+            <span data-trap="done: classDoneXxx. text" ></span>
+        </li>
+    </ins></ul>
     <form data-trap=": (signal addTodo) whenSubmitted">
         <input type="text" data-trap="#todoText: inputValue" size="30" placeholder="add new todo here"/>
         <input type="submit" class="btn-primary" value="add"/>

+ 4 - 0
st/Trapped-Frontend.st

@@ -200,6 +200,10 @@ inputValue
 	^TrappedProcessorInputValue new
 !
 
+loopContents
+	^TrappedProcessorLoopContents new
+!
+
 loopProc
 	^TrappedProcessorLoopProc new
 !

+ 28 - 0
st/Trapped-Processors.st

@@ -230,6 +230,34 @@ toView: aDataCarrier
 	self subclassResponsibility
 ! !
 
+TrappedProcessorLoopBase subclass: #TrappedProcessorLoopContents
+	instanceVariableNames: ''
+	package: 'Trapped-Processors'!
+!TrappedProcessorLoopContents commentStamp!
+I am used to loop over data and repeat the contents
+of the brush I am installed on.
+
+I save the brush contents, then I observe the data in the model,
+and when it changes, I loop over it
+and restore the contents from remembered state
+and interpret all contained data-trap attributes inside
+for each element, putting the result _after_ my brush.
+
+My brush itself should be as least visible as possible,
+as it only serve as a position flag (use for example
+noscript, ins or del).!
+
+!TrappedProcessorLoopContents methodsFor: 'data transformation'!
+
+toView: aDataCarrier
+	| frozen contents |
+	frozen := aDataCarrier copy.
+	contents := frozen target asJQuery contents detach.
+	frozen target trapIter: #() after: [ :html |
+		html root asJQuery append: contents clone.
+		Trapped current injectToJQuery: html root asJQuery ]
+! !
+
 TrappedProcessorLoopBase subclass: #TrappedProcessorLoopProc
 	instanceVariableNames: ''
 	package: 'Trapped-Processors'!