Browse Source

Convenience messages asSilk and inSilk

Herbert Vojčík 9 năm trước cách đây
mục cha
commit
091e63af30
2 tập tin đã thay đổi với 108 bổ sung3 xóa
  1. 86 2
      src/Silk.js
  2. 22 1
      src/Silk.st

+ 86 - 2
src/Silk.js

@@ -1,4 +1,4 @@
-define("silk/Silk", ["amber/boot", "domite/DOMite", "amber_core/Kernel-Objects", "amber_core/Kernel-Methods"], function($boot){
+define("silk/Silk", ["amber/boot", "domite/DOMite", "amber_core/Kernel-Objects", "amber_core/Kernel-Methods", "amber_core/Kernel-Collections", "amber_core/Kernel-Infrastructure"], function($boot){
 var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
 $core.addPackage('Silk');
 $core.packages["Silk"].innerEval = function (expr) { return eval(expr); };
@@ -6,7 +6,7 @@ $core.packages["Silk"].transport = {"type":"amd","amdNamespace":"silk"};
 
 $core.addClass('Silk', $globals.Domite, [], 'Silk');
 //>>excludeStart("ide", pragmas.excludeIdeData);
-$globals.Silk.comment="I am adding convenience APIs to my subclass, `Domite`.\x0a\x0a##Rendering\x0a\x0a - `aSilk << anObject` uses double-dispatch via `renderOnSilk:`. This allows creating widgets (no formal superclass, anything with `renderOnSilk:` is a widget), as well as incorporating blocks: `aSilk << aBlock` runs the block, passing aSilk as a parameter.";
+$globals.Silk.comment="I am adding convenience APIs to my subclass, `Domite`.\x0a\x0a##Rendering\x0a\x0a - `aSilk << anObject` uses double-dispatch via `renderOnSilk:`. This allows creating widgets (no formal superclass, anything with `renderOnSilk:` is a widget), as well as incorporating blocks: `aSilk << aBlock` runs the block, passing aSilk as a parameter.\x0a\x0a##Convenience\x0a\x0a - `aCssSelectorString asSilk` returns Silk wrapping an element at a selector.\x0a - `anObject inSilk` returns anObject rendered in a document fragment.";
 //>>excludeEnd("ide");
 $core.addMethod(
 $core.method({
@@ -70,6 +70,90 @@ messageSends: ["value:"]
 }),
 $globals.BlockClosure);
 
+$core.addMethod(
+$core.method({
+selector: "asSilk",
+protocol: '*Silk',
+fn: function (){
+var self=this;
+function $Silk(){return $globals.Silk||(typeof Silk=="undefined"?nil:Silk)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+$1=$recv($Silk())._at_(self._asString());
+return $1;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"asSilk",{},$globals.CharacterArray)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "asSilk\x0a\x09^ Silk at: self asString",
+referencedClasses: ["Silk"],
+//>>excludeEnd("ide");
+messageSends: ["at:", "asString"]
+}),
+$globals.CharacterArray);
+
+$core.addMethod(
+$core.method({
+selector: "inSilk",
+protocol: '*Silk',
+fn: function (){
+var self=this;
+function $Silk(){return $globals.Silk||(typeof Silk=="undefined"?nil:Silk)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $2,$3,$1;
+$2=$recv($Silk())._newStream();
+$recv($2).__lt_lt(self);
+$3=$recv($2)._yourself();
+$1=$3;
+return $1;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"inSilk",{},$globals.JSObjectProxy)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "inSilk\x0a\x09^ Silk newStream << self; yourself",
+referencedClasses: ["Silk"],
+//>>excludeEnd("ide");
+messageSends: ["<<", "newStream", "yourself"]
+}),
+$globals.JSObjectProxy);
+
+$core.addMethod(
+$core.method({
+selector: "inSilk",
+protocol: '*Silk',
+fn: function (){
+var self=this;
+function $Silk(){return $globals.Silk||(typeof Silk=="undefined"?nil:Silk)}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $2,$3,$1;
+$2=$recv($Silk())._newStream();
+$recv($2).__lt_lt(self);
+$3=$recv($2)._yourself();
+$1=$3;
+return $1;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"inSilk",{},$globals.Object)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "inSilk\x0a\x09^ Silk newStream << self; yourself",
+referencedClasses: ["Silk"],
+//>>excludeEnd("ide");
+messageSends: ["<<", "newStream", "yourself"]
+}),
+$globals.Object);
+
 $core.addMethod(
 $core.method({
 selector: "renderOnSilk:",

+ 22 - 1
src/Silk.st

@@ -7,7 +7,12 @@ I am adding convenience APIs to my subclass, `Domite`.
 
 ##Rendering
 
- - `aSilk << anObject` uses double-dispatch via `renderOnSilk:`. This allows creating widgets (no formal superclass, anything with `renderOnSilk:` is a widget), as well as incorporating blocks: `aSilk << aBlock` runs the block, passing aSilk as a parameter.!
+ - `aSilk << anObject` uses double-dispatch via `renderOnSilk:`. This allows creating widgets (no formal superclass, anything with `renderOnSilk:` is a widget), as well as incorporating blocks: `aSilk << aBlock` runs the block, passing aSilk as a parameter.
+
+##Convenience
+
+ - `aCssSelectorString asSilk` returns Silk wrapping an element at a selector.
+ - `anObject inSilk` returns anObject rendered in a document fragment.!
 
 !Silk methodsFor: 'writing'!
 
@@ -26,8 +31,24 @@ renderOnSilk: aSilk
 	self value: aSilk
 ! !
 
+!CharacterArray methodsFor: '*Silk'!
+
+asSilk
+	^ Silk at: self asString
+! !
+
+!JSObjectProxy methodsFor: '*Silk'!
+
+inSilk
+	^ Silk newStream << self; yourself
+! !
+
 !Object methodsFor: '*Silk'!
 
+inSilk
+	^ Silk newStream << self; yourself
+!
+
 renderOnSilk: aSilk
 	^ nil
 ! !