Jelajahi Sumber

path processor

Herbert Vojčík 11 tahun lalu
induk
melakukan
d6880f5ceb
3 mengubah file dengan 87 tambahan dan 22 penghapusan
  1. 56 9
      js/Trapped-Frontend.js
  2. 5 7
      meta/demo.html
  3. 26 6
      st/Trapped-Frontend.st

+ 56 - 9
js/Trapped-Frontend.js

@@ -654,6 +654,25 @@ referencedClasses: ["TrappedProcessorInputValue"]
 }),
 smalltalk.TrappedProcessor.klass);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "path",
+category: 'factory',
+fn: function (){
+var self=this;
+function $TrappedProcessorDescend(){return smalltalk.TrappedProcessorDescend||(typeof TrappedProcessorDescend=="undefined"?nil:TrappedProcessorDescend)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st($TrappedProcessorDescend())._new();
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"path",{},smalltalk.TrappedProcessor.klass)})},
+args: [],
+source: "path\x0a\x09^TrappedProcessorDescend new",
+messageSends: ["new"],
+referencedClasses: ["TrappedProcessorDescend"]
+}),
+smalltalk.TrappedProcessor.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "signal:",
@@ -917,6 +936,27 @@ smalltalk.TrappedProcessorBlackboard);
 
 
 
+smalltalk.addClass('TrappedProcessorDescend', smalltalk.TrappedProcessor, [], 'Trapped-Frontend');
+smalltalk.TrappedProcessorDescend.comment="I intepret data-trap in descendants of my brush.";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "toView:",
+category: 'data transformation',
+fn: function (aDataCarrier){
+var self=this;
+function $Trapped(){return smalltalk.Trapped||(typeof Trapped=="undefined"?nil:Trapped)}
+return smalltalk.withContext(function($ctx1) { 
+_st(_st($Trapped())._current())._injectToJQuery_(_st(_st(_st(aDataCarrier)._target())._asJQuery())._children());
+return self}, function($ctx1) {$ctx1.fill(self,"toView:",{aDataCarrier:aDataCarrier},smalltalk.TrappedProcessorDescend)})},
+args: ["aDataCarrier"],
+source: "toView: aDataCarrier\x0a\x09Trapped current injectToJQuery: aDataCarrier target asJQuery children",
+messageSends: ["injectToJQuery:", "current", "children", "asJQuery", "target"],
+referencedClasses: ["Trapped"]
+}),
+smalltalk.TrappedProcessorDescend);
+
+
+
 smalltalk.addClass('TrappedProcessorGuard', smalltalk.TrappedProcessor, ['guardPath'], 'Trapped-Frontend');
 smalltalk.TrappedProcessorGuard.comment="I am used to guard contants of the brush I am installed on.\x0a\x0aI observe guard expression in the model,\x0aand when it changes to nil or false, I delete the brush contents;\x0aon the other hand, when it changes to non-nil and non-false,\x0aI run the rest on the chain, which should be one-time\x0athat sets up the contents,";
 smalltalk.addMethod(
@@ -1327,26 +1367,33 @@ var self=this;
 function $Trapped(){return smalltalk.Trapped||(typeof Trapped=="undefined"?nil:Trapped)}
 function $HTMLCanvas(){return smalltalk.HTMLCanvas||(typeof HTMLCanvas=="undefined"?nil:HTMLCanvas)}
 return smalltalk.withContext(function($ctx1) { 
-_st(_st(aJQuery)._find_("[data-trap]"))._each_((function(index,elem){
-var jq,parsed;
+var $1;
+_st(aJQuery)._each_((function(index,elem){
+var jq;
 return smalltalk.withContext(function($ctx2) {
 jq=_st(elem)._asJQuery();
 jq;
+$1=_st(jq)._is_("[data-trap]");
+if(smalltalk.assert($1)){
+var parsed;
 parsed=_st($Trapped())._parse_(_st(jq)._attr_("data-trap"));
 parsed;
-_st(parsed)._do_((function(rule){
+_st(jq)._removeAttr_("data-trap");
+return _st(parsed)._do_((function(rule){
 return smalltalk.withContext(function($ctx3) {
 return _st(_st(_st($HTMLCanvas())._onJQuery_(jq))._root())._trap_processors_(_st(rule)._first(),_st(rule)._at_ifAbsent_((2),(function(){
 return smalltalk.withContext(function($ctx4) {
 return [];
-}, function($ctx4) {$ctx4.fillBlock({},$ctx3,3)})})));
-}, function($ctx3) {$ctx3.fillBlock({rule:rule},$ctx2,2)})}));
-return _st(jq)._removeAttr_("data-trap");
-}, function($ctx2) {$ctx2.fillBlock({index:index,elem:elem,jq:jq,parsed:parsed},$ctx1,1)})}));
+}, function($ctx4) {$ctx4.fillBlock({},$ctx3,4)})})));
+}, function($ctx3) {$ctx3.fillBlock({rule:rule},$ctx2,3)})}));
+} else {
+return self._injectToJQuery_(_st(jq)._children());
+};
+}, function($ctx2) {$ctx2.fillBlock({index:index,elem:elem,jq:jq},$ctx1,1)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"injectToJQuery:",{aJQuery:aJQuery},smalltalk.Trapped)})},
 args: ["aJQuery"],
-source: "injectToJQuery: aJQuery\x0a\x09(aJQuery find: '[data-trap]') each: [ :index :elem |\x0a\x09\x09| jq parsed |\x0a\x09\x09jq := elem asJQuery.\x0a\x09\x09parsed := Trapped parse: (jq attr: 'data-trap').\x0a\x09\x09parsed do: [ :rule |\x0a\x09\x09\x09(HTMLCanvas onJQuery: jq) root trap: rule first processors: (rule at: 2 ifAbsent: [#()]) ].\x0a\x09\x09jq removeAttr: 'data-trap' ]",
-messageSends: ["each:", "find:", "asJQuery", "parse:", "attr:", "do:", "trap:processors:", "root", "onJQuery:", "first", "at:ifAbsent:", "removeAttr:"],
+source: "injectToJQuery: aJQuery\x0a\x09aJQuery each: [ :index :elem |\x0a\x09\x09| jq |\x0a\x09\x09jq := elem asJQuery.\x0a\x09\x09(jq is: '[data-trap]')\x0a\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09| parsed |\x0a\x09\x09\x09\x09parsed := Trapped parse: (jq attr: 'data-trap').\x0a\x09\x09\x09\x09jq removeAttr: 'data-trap'.\x0a\x09\x09\x09\x09parsed do: [ :rule |\x0a\x09\x09\x09\x09\x09(HTMLCanvas onJQuery: jq) root trap: rule first processors: (rule at: 2 ifAbsent: [#()]) ] ]\x0a\x09\x09\x09ifFalse: [ self injectToJQuery: jq children ] ]",
+messageSends: ["each:", "asJQuery", "ifTrue:ifFalse:", "is:", "parse:", "attr:", "removeAttr:", "do:", "trap:processors:", "root", "onJQuery:", "first", "at:ifAbsent:", "injectToJQuery:", "children"],
 referencedClasses: ["Trapped", "HTMLCanvas"]
 }),
 smalltalk.Trapped);

+ 5 - 7
meta/demo.html

@@ -1,6 +1,6 @@
-<html>
+<html data-trap="App: (path)">
 <head>
-    <title data-trap="App (title)"></title>
+    <title data-trap="(title)"></title>
     <script src="../bower_components/amber/support/amber.js"></script>
     <script type='text/javascript' src='../bower_components/amber/support/requirejs/require.min.js'></script>
     <link rel="stylesheet" href="demo.css" />
@@ -29,10 +29,8 @@
             }
     );
 </script>
-<div>
-    <h2 data-trap="App (title)"></h2>
-    <div data-trap="App: (guard ((todos) (notNil))) (widget TemporaryWidget)"></div>
-    <p data-trap="App: (guard ((todos) (isNil))) (widget TemporaryWidget2)"></p>
-</div>
+    <h2 data-trap="(title)"></h2>
+    <div data-trap=": (guard ((todos) (notNil))) (widget TemporaryWidget)"></div>
+    <p data-trap=": (guard ((todos) (isNil))) (widget TemporaryWidget2)"></p>
 </body>
 </html>

+ 26 - 6
st/Trapped-Frontend.st

@@ -214,6 +214,10 @@ inputValue
 	^TrappedProcessorInputValue new
 !
 
+path
+	^TrappedProcessorDescend new
+!
+
 signal: aString
 	^TrappedProcessorSignal new: aString
 !
@@ -328,6 +332,18 @@ installToView: aDataCarrier toModel: anotherDataCarrier
 	aDataCarrier value: false
 ! !
 
+TrappedProcessor subclass: #TrappedProcessorDescend
+	instanceVariableNames: ''
+	package: 'Trapped-Frontend'!
+!TrappedProcessorDescend commentStamp!
+I intepret data-trap in descendants of my brush.!
+
+!TrappedProcessorDescend methodsFor: 'data transformation'!
+
+toView: aDataCarrier
+	Trapped current injectToJQuery: aDataCarrier target asJQuery children
+! !
+
 TrappedProcessor subclass: #TrappedProcessorGuard
 	instanceVariableNames: 'guardPath'
 	package: 'Trapped-Frontend'!
@@ -518,13 +534,17 @@ descend: anArray snapshotDo: aBlock
 !
 
 injectToJQuery: aJQuery
-	(aJQuery find: '[data-trap]') each: [ :index :elem |
-		| jq parsed |
+	aJQuery each: [ :index :elem |
+		| jq |
 		jq := elem asJQuery.
-		parsed := Trapped parse: (jq attr: 'data-trap').
-		parsed do: [ :rule |
-			(HTMLCanvas onJQuery: jq) root trap: rule first processors: (rule at: 2 ifAbsent: [#()]) ].
-		jq removeAttr: 'data-trap' ]
+		(jq is: '[data-trap]')
+			ifTrue: [
+				| parsed |
+				parsed := Trapped parse: (jq attr: 'data-trap').
+				jq removeAttr: 'data-trap'.
+				parsed do: [ :rule |
+					(HTMLCanvas onJQuery: jq) root trap: rule first processors: (rule at: 2 ifAbsent: [#()]) ] ]
+			ifFalse: [ self injectToJQuery: jq children ] ]
 !
 
 start: args