فهرست منبع

Extract HTMLSnippet to package of its own.

Herbert Vojčík 7 سال پیش
والد
کامیت
d2f4b67bb5
6فایلهای تغییر یافته به همراه589 افزوده شده و 567 حذف شده
  1. 1 1
      Gruntfile.js
  2. 2 1
      deploy.js
  3. 429 0
      src/Web-Snippets.js
  4. 157 0
      src/Web-Snippets.st
  5. 0 412
      src/Web.js
  6. 0 153
      src/Web.st

+ 1 - 1
Gruntfile.js

@@ -33,7 +33,7 @@ module.exports = function (grunt) {
             },
             all: {
                 src: [
-                    'src/Web.st' // list all sources in dependency order
+                    'src/Web.st', 'src/Web-Snippets.js' // list all sources in dependency order
                     // list all tests in dependency order
                 ],
                 amd_namespace: 'amber/web',

+ 2 - 1
deploy.js

@@ -1,7 +1,8 @@
 define([
     'amber/deploy',
     // --- packages to be deployed begin here ---
-    "amber/web/Web"
+    "amber/web/Web",
+    "amber/web/Web-Snippets"
     // --- packages to be deployed end here ---
 ], function (amber) {
     return amber;

+ 429 - 0
src/Web-Snippets.js

@@ -0,0 +1,429 @@
+define(["amber/boot"
+//>>excludeStart("imports", pragmas.excludeImports);
+, "amber/jquery/Wrappers-JQuery"
+//>>excludeEnd("imports");
+, "amber/web/Web", "amber_core/Kernel-Collections", "amber_core/Kernel-Objects"], function($boot
+//>>excludeStart("imports", pragmas.excludeImports);
+
+//>>excludeEnd("imports");
+){"use strict";
+if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
+var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
+if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
+$core.addPackage('Web-Snippets');
+$core.packages["Web-Snippets"].innerEval = function (expr) { return eval(expr); };
+$core.packages["Web-Snippets"].imports = ["amber/jquery/Wrappers-JQuery"];
+$core.packages["Web-Snippets"].transport = {"type":"amd","amdNamespace":"amber/web"};
+
+$core.addClass('HTMLSnippet', $globals.Object, ['snippets'], 'Web-Snippets');
+//>>excludeStart("ide", pragmas.excludeIdeData);
+$globals.HTMLSnippet.comment="My sole instance is the registry of html snippets.\x0a`HTMLSnippet current` is the public singleton instance.\x0a\x0aOn startup, it scans the document for any html elements\x0awith `'data-snippet=\x22foo\x22'` attribute and takes them off the document,\x0aremembering them in the store under the specified name.\x0aIt also install method #foo into HTMLCanvas dynamically.\x0a\x0aEvery html snippet should mark a 'caret', a place where contents\x0acan be inserted, by 'data-snippet=\x22*\x22' (a special name for caret).\x0aFor example:\x0a\x0a`<li data-snippet='menuelement' class='...'><a data-snippet='*'></a></li>`\x0a\x0adefines a list element with a link inside; the link itself is marked as a caret.\x0a\x0aYou can later issue\x0a\x0a`html menuelement href: '/foo'; with: 'A foo'`\x0a\x0ato insert the whole snippet and directly manipulate the caret, so it renders:\x0a\x0a`<li class='...'><a href='/foo'>A foo</a></li>`\x0a\x0aFor a self-careting tags (not very useful, but you do not need to fill class etc.\x0ayou can use\x0a\x0a`<div class='lots of classes' attr1='one' attr2='two' data-snippet='*bar'></div>`\x0a\x0aand in code later do:\x0a\x0a`html bar with: [ xxx ]`\x0a\x0ato render\x0a\x0a`<div class='lots of classes' attr1='one' attr2='two'>...added by xxx...</div>`";
+//>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "initializeFromJQuery:",
+protocol: 'initialization',
+fn: function (aJQuery){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$recv(self._snippetsFromJQuery_(aJQuery))._do_((function(each){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return self._installSnippetFromJQuery_($recv(each)._asJQuery());
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
+//>>excludeEnd("ctx");
+}));
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"initializeFromJQuery:",{aJQuery:aJQuery},$globals.HTMLSnippet)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aJQuery"],
+source: "initializeFromJQuery: aJQuery\x0a\x09\x22Finds and takes out all snippets out of aJQuery.\x0a\x09Installs it into self.\x22\x0a\x09\x0a\x09(self snippetsFromJQuery: aJQuery) do: [ :each |\x0a\x09\x09self installSnippetFromJQuery: each asJQuery ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["do:", "snippetsFromJQuery:", "installSnippetFromJQuery:", "asJQuery"]
+}),
+$globals.HTMLSnippet);
+
+$core.addMethod(
+$core.method({
+selector: "installSnippetFromJQuery:",
+protocol: 'snippet installation',
+fn: function (element){
+var self=this;
+var name;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1,$2;
+name=$recv(element)._attr_("data-snippet");
+$1=$recv(name).__eq("*");
+if(!$core.assert($1)){
+$2=$recv("^\x5c*"._asRegexp())._test_(name);
+if($core.assert($2)){
+name=$recv(name)._allButFirst();
+name;
+$recv(element)._attr_put_("data-snippet","*");
+} else {
+$recv(element)._removeAttr_("data-snippet");
+}
+self._snippetAt_install_(name,$recv($recv(element)._detach())._get_((0)));
+}
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"installSnippetFromJQuery:",{element:element,name:name},$globals.HTMLSnippet)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["element"],
+source: "installSnippetFromJQuery: element\x0a\x09| name |\x0a\x09name := element attr: 'data-snippet'.\x0a\x09name = '*' ifFalse: [\x0a\x09\x09('^\x5c*' asRegexp test: name)\x0a\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09name := name allButFirst.\x0a\x09\x09\x09\x09element attr: 'data-snippet' put: '*' ]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09element removeAttr: 'data-snippet' ].\x0a\x09\x09self snippetAt: name install: (element detach get: 0) ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["attr:", "ifFalse:", "=", "ifTrue:ifFalse:", "test:", "asRegexp", "allButFirst", "attr:put:", "removeAttr:", "snippetAt:install:", "get:", "detach"]
+}),
+$globals.HTMLSnippet);
+
+$core.addMethod(
+$core.method({
+selector: "snippetAt:",
+protocol: 'accessing',
+fn: function (aString){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv(self._snippets())._at_(aString);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"snippetAt:",{aString:aString},$globals.HTMLSnippet)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aString"],
+source: "snippetAt: aString\x0a\x09^ self snippets at: aString",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["at:", "snippets"]
+}),
+$globals.HTMLSnippet);
+
+$core.addMethod(
+$core.method({
+selector: "snippetAt:compile:",
+protocol: 'method generation',
+fn: function (aString,anElement){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$recv($recv($globals.ClassBuilder)._new())._installMethod_forClass_protocol_($recv($recv((function(htmlReceiver){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $recv(htmlReceiver)._snippet_(anElement);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({htmlReceiver:htmlReceiver},$ctx1,1)});
+//>>excludeEnd("ctx");
+}))._currySelf())._asCompiledMethod_(aString),$globals.HTMLCanvas,"**snippets");
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"snippetAt:compile:",{aString:aString,anElement:anElement},$globals.HTMLSnippet)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aString", "anElement"],
+source: "snippetAt: aString compile: anElement\x0a\x09\x22Method generation for the snippet.\x0a\x09The selector is aString, the method block uses anElement\x22\x0a\x09\x0a\x09ClassBuilder new\x0a\x09\x09installMethod: ([ :htmlReceiver | htmlReceiver snippet: anElement ]\x0a\x09\x09\x09currySelf asCompiledMethod: aString)\x0a\x09\x09forClass: HTMLCanvas\x0a\x09\x09protocol: '**snippets'",
+referencedClasses: ["ClassBuilder", "HTMLCanvas"],
+//>>excludeEnd("ide");
+messageSends: ["installMethod:forClass:protocol:", "new", "asCompiledMethod:", "currySelf", "snippet:"]
+}),
+$globals.HTMLSnippet);
+
+$core.addMethod(
+$core.method({
+selector: "snippetAt:install:",
+protocol: 'snippet installation',
+fn: function (aString,anElement){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+$recv(self._snippets())._at_put_(aString,anElement);
+self._snippetAt_compile_(aString,anElement);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"snippetAt:install:",{aString:aString,anElement:anElement},$globals.HTMLSnippet)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aString", "anElement"],
+source: "snippetAt: aString install: anElement\x0a\x09self snippets at: aString put: anElement.\x0a\x09self snippetAt: aString compile: anElement",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["at:put:", "snippets", "snippetAt:compile:"]
+}),
+$globals.HTMLSnippet);
+
+$core.addMethod(
+$core.method({
+selector: "snippets",
+protocol: 'accessing',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1,$receiver;
+$1=self["@snippets"];
+if(($receiver = $1) == null || $receiver.isNil){
+self["@snippets"]=$globals.HashedCollection._newFromPairs_([]);
+return self["@snippets"];
+} else {
+return $1;
+}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"snippets",{},$globals.HTMLSnippet)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "snippets\x0a\x09^ snippets ifNil: [ snippets := #{} ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["ifNil:"]
+}),
+$globals.HTMLSnippet);
+
+$core.addMethod(
+$core.method({
+selector: "snippetsFromJQuery:",
+protocol: 'private',
+fn: function (aJQuery){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($recv(aJQuery)._find_("[data-snippet]"))._toArray();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"snippetsFromJQuery:",{aJQuery:aJQuery},$globals.HTMLSnippet)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aJQuery"],
+source: "snippetsFromJQuery: aJQuery\x0a\x09^ (aJQuery find: '[data-snippet]') toArray",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["toArray", "find:"]
+}),
+$globals.HTMLSnippet);
+
+
+$globals.HTMLSnippet.klass.iVarNames = ['current'];
+$core.addMethod(
+$core.method({
+selector: "current",
+protocol: 'instance creation',
+fn: function (){
+var self=this;
+return self["@current"];
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "current\x0a\x09^ current",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.HTMLSnippet.klass);
+
+$core.addMethod(
+$core.method({
+selector: "ensureCurrent",
+protocol: 'initialization',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1,$2,$receiver;
+$1=self["@current"];
+if(($receiver = $1) == null || $receiver.isNil){
+$2=(
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = true,
+//>>excludeEnd("ctx");
+($globals.HTMLSnippet.klass.superclass||$boot.nilAsClass).fn.prototype._new.apply($recv(self), []));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = false;
+//>>excludeEnd("ctx");;
+$recv($2)._initializeFromJQuery_($recv(document)._asJQuery());
+self["@current"]=$recv($2)._yourself();
+self["@current"];
+} else {
+$1;
+}
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"ensureCurrent",{},$globals.HTMLSnippet.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "ensureCurrent\x0a\x09current ifNil: [\x0a\x09\x09current := super new\x0a\x09\x09\x09initializeFromJQuery: document asJQuery;\x0a\x09\x09\x09yourself ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["ifNil:", "initializeFromJQuery:", "new", "asJQuery", "yourself"]
+}),
+$globals.HTMLSnippet.klass);
+
+$core.addMethod(
+$core.method({
+selector: "initialize",
+protocol: 'initialization',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+(
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = true,
+//>>excludeEnd("ctx");
+($globals.HTMLSnippet.klass.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($recv(self), []));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = false;
+//>>excludeEnd("ctx");;
+$1=self._isDOMAvailable();
+if($core.assert($1)){
+self._ensureCurrent();
+}
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.HTMLSnippet.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "initialize\x0a\x09super initialize.\x0a\x09self isDOMAvailable ifTrue: [\x0a\x09\x09self ensureCurrent ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["initialize", "ifTrue:", "isDOMAvailable", "ensureCurrent"]
+}),
+$globals.HTMLSnippet.klass);
+
+$core.addMethod(
+$core.method({
+selector: "isDOMAvailable",
+protocol: 'instance creation',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+ return typeof document !== 'undefined' ;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"isDOMAvailable",{},$globals.HTMLSnippet.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "isDOMAvailable\x0a\x09< return typeof document !== 'undefined' >",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.HTMLSnippet.klass);
+
+$core.addMethod(
+$core.method({
+selector: "new",
+protocol: 'instance creation',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+self._shouldNotImplement();
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"new",{},$globals.HTMLSnippet.klass)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "new\x0a\x09self shouldNotImplement",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["shouldNotImplement"]
+}),
+$globals.HTMLSnippet.klass);
+
+$core.addMethod(
+$core.method({
+selector: "asSnippet",
+protocol: '*Web-Snippets',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv($recv($globals.HTMLSnippet)._current())._snippetAt_(self._asString());
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"asSnippet",{},$globals.CharacterArray)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "asSnippet\x0a\x09^ HTMLSnippet current snippetAt: self asString",
+referencedClasses: ["HTMLSnippet"],
+//>>excludeEnd("ide");
+messageSends: ["snippetAt:", "current", "asString"]
+}),
+$globals.CharacterArray);
+
+$core.addMethod(
+$core.method({
+selector: "snippet:",
+protocol: '*Web-Snippets',
+fn: function (anElement){
+var self=this;
+var clone,caret;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+clone=$recv($recv(anElement)._asJQuery())._clone();
+$1=$recv($globals.TagBrush)._fromJQuery_canvas_(clone,self);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["fromJQuery:canvas:"]=1;
+//>>excludeEnd("ctx");
+self._with_($1);
+caret=$recv(clone)._find_("[data-snippet=\x22*\x22]");
+$recv($recv(caret)._toArray())._ifEmpty_((function(){
+caret=clone;
+return caret;
+
+}));
+return $recv($globals.TagBrush)._fromJQuery_canvas_($recv(caret)._removeAttr_("data-snippet"),self);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"snippet:",{anElement:anElement,clone:clone,caret:caret},$globals.HTMLCanvas)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anElement"],
+source: "snippet: anElement\x0a\x09\x22Adds clone of anElement, finds [data-snippet=\x22\x22*\x22\x22] subelement\x0a\x09and returns TagBrush as if that subelement was just added.\x0a\x09\x0a\x09Rarely needed to use directly, use `html foo` dynamically installed method\x0a\x09for a snippet named foo.\x22\x0a\x09\x0a\x09| clone caret |\x0a\x09\x0a\x09clone := anElement asJQuery clone.\x0a\x09self with: (TagBrush fromJQuery: clone canvas: self).\x0a\x09caret := clone find: '[data-snippet=\x22*\x22]'.\x0a\x09caret toArray ifEmpty: [ caret := clone ].\x0a\x09^ TagBrush fromJQuery: (caret removeAttr: 'data-snippet') canvas: self",
+referencedClasses: ["TagBrush"],
+//>>excludeEnd("ide");
+messageSends: ["clone", "asJQuery", "with:", "fromJQuery:canvas:", "find:", "ifEmpty:", "toArray", "removeAttr:"]
+}),
+$globals.HTMLCanvas);
+
+});

+ 157 - 0
src/Web-Snippets.st

@@ -0,0 +1,157 @@
+Smalltalk createPackage: 'Web-Snippets'!
+(Smalltalk packageAt: 'Web-Snippets') imports: {'amber/jquery/Wrappers-JQuery'}!
+Object subclass: #HTMLSnippet
+	instanceVariableNames: 'snippets'
+	package: 'Web-Snippets'!
+!HTMLSnippet commentStamp!
+My sole instance is the registry of html snippets.
+`HTMLSnippet current` is the public singleton instance.
+
+On startup, it scans the document for any html elements
+with `'data-snippet="foo"'` attribute and takes them off the document,
+remembering them in the store under the specified name.
+It also install method #foo into HTMLCanvas dynamically.
+
+Every html snippet should mark a 'caret', a place where contents
+can be inserted, by 'data-snippet="*"' (a special name for caret).
+For example:
+
+`<li data-snippet='menuelement' class='...'><a data-snippet='*'></a></li>`
+
+defines a list element with a link inside; the link itself is marked as a caret.
+
+You can later issue
+
+`html menuelement href: '/foo'; with: 'A foo'`
+
+to insert the whole snippet and directly manipulate the caret, so it renders:
+
+`<li class='...'><a href='/foo'>A foo</a></li>`
+
+For a self-careting tags (not very useful, but you do not need to fill class etc.
+you can use
+
+`<div class='lots of classes' attr1='one' attr2='two' data-snippet='*bar'></div>`
+
+and in code later do:
+
+`html bar with: [ xxx ]`
+
+to render
+
+`<div class='lots of classes' attr1='one' attr2='two'>...added by xxx...</div>`!
+
+!HTMLSnippet methodsFor: 'accessing'!
+
+snippetAt: aString
+	^ self snippets at: aString
+!
+
+snippets
+	^ snippets ifNil: [ snippets := #{} ]
+! !
+
+!HTMLSnippet methodsFor: 'initialization'!
+
+initializeFromJQuery: aJQuery
+	"Finds and takes out all snippets out of aJQuery.
+	Installs it into self."
+	
+	(self snippetsFromJQuery: aJQuery) do: [ :each |
+		self installSnippetFromJQuery: each asJQuery ]
+! !
+
+!HTMLSnippet methodsFor: 'method generation'!
+
+snippetAt: aString compile: anElement
+	"Method generation for the snippet.
+	The selector is aString, the method block uses anElement"
+	
+	ClassBuilder new
+		installMethod: ([ :htmlReceiver | htmlReceiver snippet: anElement ]
+			currySelf asCompiledMethod: aString)
+		forClass: HTMLCanvas
+		protocol: '**snippets'
+! !
+
+!HTMLSnippet methodsFor: 'private'!
+
+snippetsFromJQuery: aJQuery
+	^ (aJQuery find: '[data-snippet]') toArray
+! !
+
+!HTMLSnippet methodsFor: 'snippet installation'!
+
+installSnippetFromJQuery: element
+	| name |
+	name := element attr: 'data-snippet'.
+	name = '*' ifFalse: [
+		('^\*' asRegexp test: name)
+			ifTrue: [
+				name := name allButFirst.
+				element attr: 'data-snippet' put: '*' ]
+			ifFalse: [
+				element removeAttr: 'data-snippet' ].
+		self snippetAt: name install: (element detach get: 0) ]
+!
+
+snippetAt: aString install: anElement
+	self snippets at: aString put: anElement.
+	self snippetAt: aString compile: anElement
+! !
+
+HTMLSnippet class instanceVariableNames: 'current'!
+
+!HTMLSnippet class methodsFor: 'initialization'!
+
+ensureCurrent
+	current ifNil: [
+		current := super new
+			initializeFromJQuery: document asJQuery;
+			yourself ]
+!
+
+initialize
+	super initialize.
+	self isDOMAvailable ifTrue: [
+		self ensureCurrent ]
+! !
+
+!HTMLSnippet class methodsFor: 'instance creation'!
+
+current
+	^ current
+!
+
+isDOMAvailable
+	< return typeof document !!== 'undefined' >
+!
+
+new
+	self shouldNotImplement
+! !
+
+!CharacterArray methodsFor: '*Web-Snippets'!
+
+asSnippet
+	^ HTMLSnippet current snippetAt: self asString
+! !
+
+!HTMLCanvas methodsFor: '*Web-Snippets'!
+
+snippet: anElement
+	"Adds clone of anElement, finds [data-snippet=""*""] subelement
+	and returns TagBrush as if that subelement was just added.
+	
+	Rarely needed to use directly, use `html foo` dynamically installed method
+	for a snippet named foo."
+	
+	| clone caret |
+	
+	clone := anElement asJQuery clone.
+	self with: (TagBrush fromJQuery: clone canvas: self).
+	caret := clone find: '[data-snippet="*"]'.
+	caret toArray ifEmpty: [ caret := clone ].
+	^ TagBrush fromJQuery: (caret removeAttr: 'data-snippet') canvas: self
+! !
+

+ 0 - 412
src/Web.js

@@ -2069,43 +2069,6 @@ messageSends: ["tag:"]
 }),
 $globals.HTMLCanvas);
 
-$core.addMethod(
-$core.method({
-selector: "snippet:",
-protocol: 'accessing',
-fn: function (anElement){
-var self=this;
-var clone,caret;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-clone=$recv($recv(anElement)._asJQuery())._clone();
-$1=$recv($globals.TagBrush)._fromJQuery_canvas_(clone,self);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["fromJQuery:canvas:"]=1;
-//>>excludeEnd("ctx");
-self._with_($1);
-caret=$recv(clone)._find_("[data-snippet=\x22*\x22]");
-$recv($recv(caret)._toArray())._ifEmpty_((function(){
-caret=clone;
-return caret;
-
-}));
-return $recv($globals.TagBrush)._fromJQuery_canvas_($recv(caret)._removeAttr_("data-snippet"),self);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"snippet:",{anElement:anElement,clone:clone,caret:caret},$globals.HTMLCanvas)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["anElement"],
-source: "snippet: anElement\x0a\x09\x22Adds clone of anElement, finds [data-snippet=\x22\x22*\x22\x22] subelement\x0a\x09and returns TagBrush as if that subelement was just added.\x0a\x09\x0a\x09Rarely needed to use directly, use `html foo` dynamically installed method\x0a\x09for a snippet named foo.\x22\x0a\x09\x0a\x09| clone caret |\x0a\x09\x0a\x09clone := anElement asJQuery clone.\x0a\x09self with: (TagBrush fromJQuery: clone canvas: self).\x0a\x09caret := clone find: '[data-snippet=\x22*\x22]'.\x0a\x09caret toArray ifEmpty: [ caret := clone ].\x0a\x09^ TagBrush fromJQuery: (caret removeAttr: 'data-snippet') canvas: self",
-referencedClasses: ["TagBrush"],
-//>>excludeEnd("ide");
-messageSends: ["clone", "asJQuery", "with:", "fromJQuery:canvas:", "find:", "ifEmpty:", "toArray", "removeAttr:"]
-}),
-$globals.HTMLCanvas);
-
 $core.addMethod(
 $core.method({
 selector: "source",
@@ -2713,358 +2676,6 @@ messageSends: ["initializeFromJQuery:", "basicNew", "initialize", "yourself"]
 $globals.HTMLCanvas.klass);
 
 
-$core.addClass('HTMLSnippet', $globals.Object, ['snippets'], 'Web');
-//>>excludeStart("ide", pragmas.excludeIdeData);
-$globals.HTMLSnippet.comment="My sole instance is the registry of html snippets.\x0a`HTMLSnippet current` is the public singleton instance.\x0a\x0aOn startup, it scans the document for any html elements\x0awith `'data-snippet=\x22foo\x22'` attribute and takes them off the document,\x0aremembering them in the store under the specified name.\x0aIt also install method #foo into HTMLCanvas dynamically.\x0a\x0aEvery html snippet should mark a 'caret', a place where contents\x0acan be inserted, by 'data-snippet=\x22*\x22' (a special name for caret).\x0aFor example:\x0a\x0a`<li data-snippet='menuelement' class='...'><a data-snippet='*'></a></li>`\x0a\x0adefines a list element with a link inside; the link itself is marked as a caret.\x0a\x0aYou can later issue\x0a\x0a`html menuelement href: '/foo'; with: 'A foo'`\x0a\x0ato insert the whole snippet and directly manipulate the caret, so it renders:\x0a\x0a`<li class='...'><a href='/foo'>A foo</a></li>`\x0a\x0aFor a self-careting tags (not very useful, but you do not need to fill class etc.\x0ayou can use\x0a\x0a`<div class='lots of classes' attr1='one' attr2='two' data-snippet='*bar'></div>`\x0a\x0aand in code later do:\x0a\x0a`html bar with: [ xxx ]`\x0a\x0ato render\x0a\x0a`<div class='lots of classes' attr1='one' attr2='two'>...added by xxx...</div>`";
-//>>excludeEnd("ide");
-$core.addMethod(
-$core.method({
-selector: "initializeFromJQuery:",
-protocol: 'initialization',
-fn: function (aJQuery){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-$recv(self._snippetsFromJQuery_(aJQuery))._do_((function(each){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-return self._installSnippetFromJQuery_($recv(each)._asJQuery());
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
-//>>excludeEnd("ctx");
-}));
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"initializeFromJQuery:",{aJQuery:aJQuery},$globals.HTMLSnippet)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aJQuery"],
-source: "initializeFromJQuery: aJQuery\x0a\x09\x22Finds and takes out all snippets out of aJQuery.\x0a\x09Installs it into self.\x22\x0a\x09\x0a\x09(self snippetsFromJQuery: aJQuery) do: [ :each |\x0a\x09\x09self installSnippetFromJQuery: each asJQuery ]",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["do:", "snippetsFromJQuery:", "installSnippetFromJQuery:", "asJQuery"]
-}),
-$globals.HTMLSnippet);
-
-$core.addMethod(
-$core.method({
-selector: "installSnippetFromJQuery:",
-protocol: 'snippet installation',
-fn: function (element){
-var self=this;
-var name;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1,$2;
-name=$recv(element)._attr_("data-snippet");
-$1=$recv(name).__eq("*");
-if(!$core.assert($1)){
-$2=$recv("^\x5c*"._asRegexp())._test_(name);
-if($core.assert($2)){
-name=$recv(name)._allButFirst();
-name;
-$recv(element)._attr_put_("data-snippet","*");
-} else {
-$recv(element)._removeAttr_("data-snippet");
-}
-self._snippetAt_install_(name,$recv($recv(element)._detach())._get_((0)));
-}
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"installSnippetFromJQuery:",{element:element,name:name},$globals.HTMLSnippet)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["element"],
-source: "installSnippetFromJQuery: element\x0a\x09| name |\x0a\x09name := element attr: 'data-snippet'.\x0a\x09name = '*' ifFalse: [\x0a\x09\x09('^\x5c*' asRegexp test: name)\x0a\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09name := name allButFirst.\x0a\x09\x09\x09\x09element attr: 'data-snippet' put: '*' ]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09element removeAttr: 'data-snippet' ].\x0a\x09\x09self snippetAt: name install: (element detach get: 0) ]",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["attr:", "ifFalse:", "=", "ifTrue:ifFalse:", "test:", "asRegexp", "allButFirst", "attr:put:", "removeAttr:", "snippetAt:install:", "get:", "detach"]
-}),
-$globals.HTMLSnippet);
-
-$core.addMethod(
-$core.method({
-selector: "snippetAt:",
-protocol: 'accessing',
-fn: function (aString){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-return $recv(self._snippets())._at_(aString);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"snippetAt:",{aString:aString},$globals.HTMLSnippet)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aString"],
-source: "snippetAt: aString\x0a\x09^ self snippets at: aString",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["at:", "snippets"]
-}),
-$globals.HTMLSnippet);
-
-$core.addMethod(
-$core.method({
-selector: "snippetAt:compile:",
-protocol: 'method generation',
-fn: function (aString,anElement){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-$recv($recv($globals.ClassBuilder)._new())._installMethod_forClass_protocol_($recv($recv((function(htmlReceiver){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-return $recv(htmlReceiver)._snippet_(anElement);
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({htmlReceiver:htmlReceiver},$ctx1,1)});
-//>>excludeEnd("ctx");
-}))._currySelf())._asCompiledMethod_(aString),$globals.HTMLCanvas,"**snippets");
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"snippetAt:compile:",{aString:aString,anElement:anElement},$globals.HTMLSnippet)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aString", "anElement"],
-source: "snippetAt: aString compile: anElement\x0a\x09\x22Method generation for the snippet.\x0a\x09The selector is aString, the method block uses anElement\x22\x0a\x09\x0a\x09ClassBuilder new\x0a\x09\x09installMethod: ([ :htmlReceiver | htmlReceiver snippet: anElement ]\x0a\x09\x09\x09currySelf asCompiledMethod: aString)\x0a\x09\x09forClass: HTMLCanvas\x0a\x09\x09protocol: '**snippets'",
-referencedClasses: ["ClassBuilder", "HTMLCanvas"],
-//>>excludeEnd("ide");
-messageSends: ["installMethod:forClass:protocol:", "new", "asCompiledMethod:", "currySelf", "snippet:"]
-}),
-$globals.HTMLSnippet);
-
-$core.addMethod(
-$core.method({
-selector: "snippetAt:install:",
-protocol: 'snippet installation',
-fn: function (aString,anElement){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-$recv(self._snippets())._at_put_(aString,anElement);
-self._snippetAt_compile_(aString,anElement);
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"snippetAt:install:",{aString:aString,anElement:anElement},$globals.HTMLSnippet)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aString", "anElement"],
-source: "snippetAt: aString install: anElement\x0a\x09self snippets at: aString put: anElement.\x0a\x09self snippetAt: aString compile: anElement",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["at:put:", "snippets", "snippetAt:compile:"]
-}),
-$globals.HTMLSnippet);
-
-$core.addMethod(
-$core.method({
-selector: "snippets",
-protocol: 'accessing',
-fn: function (){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1,$receiver;
-$1=self["@snippets"];
-if(($receiver = $1) == null || $receiver.isNil){
-self["@snippets"]=$globals.HashedCollection._newFromPairs_([]);
-return self["@snippets"];
-} else {
-return $1;
-}
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"snippets",{},$globals.HTMLSnippet)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "snippets\x0a\x09^ snippets ifNil: [ snippets := #{} ]",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["ifNil:"]
-}),
-$globals.HTMLSnippet);
-
-$core.addMethod(
-$core.method({
-selector: "snippetsFromJQuery:",
-protocol: 'private',
-fn: function (aJQuery){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-return $recv($recv(aJQuery)._find_("[data-snippet]"))._toArray();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"snippetsFromJQuery:",{aJQuery:aJQuery},$globals.HTMLSnippet)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: ["aJQuery"],
-source: "snippetsFromJQuery: aJQuery\x0a\x09^ (aJQuery find: '[data-snippet]') toArray",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["toArray", "find:"]
-}),
-$globals.HTMLSnippet);
-
-
-$globals.HTMLSnippet.klass.iVarNames = ['current'];
-$core.addMethod(
-$core.method({
-selector: "current",
-protocol: 'instance creation',
-fn: function (){
-var self=this;
-return self["@current"];
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "current\x0a\x09^ current",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.HTMLSnippet.klass);
-
-$core.addMethod(
-$core.method({
-selector: "ensureCurrent",
-protocol: 'initialization',
-fn: function (){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1,$2,$receiver;
-$1=self["@current"];
-if(($receiver = $1) == null || $receiver.isNil){
-$2=(
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = true,
-//>>excludeEnd("ctx");
-($globals.HTMLSnippet.klass.superclass||$boot.nilAsClass).fn.prototype._new.apply($recv(self), []));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = false;
-//>>excludeEnd("ctx");;
-$recv($2)._initializeFromJQuery_($recv(document)._asJQuery());
-self["@current"]=$recv($2)._yourself();
-self["@current"];
-} else {
-$1;
-}
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"ensureCurrent",{},$globals.HTMLSnippet.klass)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "ensureCurrent\x0a\x09current ifNil: [\x0a\x09\x09current := super new\x0a\x09\x09\x09initializeFromJQuery: document asJQuery;\x0a\x09\x09\x09yourself ]",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["ifNil:", "initializeFromJQuery:", "new", "asJQuery", "yourself"]
-}),
-$globals.HTMLSnippet.klass);
-
-$core.addMethod(
-$core.method({
-selector: "initialize",
-protocol: 'initialization',
-fn: function (){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-(
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = true,
-//>>excludeEnd("ctx");
-($globals.HTMLSnippet.klass.superclass||$boot.nilAsClass).fn.prototype._initialize.apply($recv(self), []));
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.supercall = false;
-//>>excludeEnd("ctx");;
-$1=self._isDOMAvailable();
-if($core.assert($1)){
-self._ensureCurrent();
-}
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.HTMLSnippet.klass)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "initialize\x0a\x09super initialize.\x0a\x09self isDOMAvailable ifTrue: [\x0a\x09\x09self ensureCurrent ]",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["initialize", "ifTrue:", "isDOMAvailable", "ensureCurrent"]
-}),
-$globals.HTMLSnippet.klass);
-
-$core.addMethod(
-$core.method({
-selector: "isDOMAvailable",
-protocol: 'instance creation',
-fn: function (){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
- return typeof document !== 'undefined' ;
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"isDOMAvailable",{},$globals.HTMLSnippet.klass)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "isDOMAvailable\x0a\x09< return typeof document !== 'undefined' >",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.HTMLSnippet.klass);
-
-$core.addMethod(
-$core.method({
-selector: "new",
-protocol: 'instance creation',
-fn: function (){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-self._shouldNotImplement();
-return self;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"new",{},$globals.HTMLSnippet.klass)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "new\x0a\x09self shouldNotImplement",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["shouldNotImplement"]
-}),
-$globals.HTMLSnippet.klass);
-
-
 $core.addClass('TagBrush', $globals.Object, ['canvas', 'element'], 'Web');
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.TagBrush.comment="I am a brush for building a single DOM element (which I hold onto).\x0a\x0aAll tags but `<style>` are instances of me (see the `StyleBrush` class).\x0a\x0a## API\x0a\x0a1. Nesting\x0a\x0a    Use `#with:` to nest tags. `#with:` can take aString, `TagBrush` instance, a `Widget` or block closure as parameter.\x0a\x0a    Example: `aTag with: aString with: aCanvas div`\x0a\x0a2. Events\x0a\x0a    The `events` protocol contains all methods related to events (delegating event handling to jQuery).\x0a\x0a    Example: `aTag onClick: [ window alert: 'clicked' ]`\x0a\x0a3. Attributes\x0a\x0a    The `attribute` protocol contains methods for attribute manipulation (delegating to jQuery too).\x0a\x0a    Example: `aTag at: 'value' put: 'hello world'`\x0a\x0a4. Raw access and jQuery\x0a\x0a    The `#element` method can be used to access to JavaScript DOM element object.\x0a\x0a    Example: `aTag element cssStyle`\x0a\x0a    Use `#asJQuery` to access to the receiver converted into a jQuery object.\x0a\x0a    Example: `aTag asJQuery css: 'color' value: 'red'`";
@@ -5056,29 +4667,6 @@ messageSends: ["value:", "onJQuery:"]
 }),
 $globals.BlockClosure);
 
-$core.addMethod(
-$core.method({
-selector: "asSnippet",
-protocol: '*Web',
-fn: function (){
-var self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-return $recv($recv($globals.HTMLSnippet)._current())._snippetAt_(self._asString());
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"asSnippet",{},$globals.CharacterArray)});
-//>>excludeEnd("ctx");
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "asSnippet\x0a\x09^ HTMLSnippet current snippetAt: self asString",
-referencedClasses: ["HTMLSnippet"],
-//>>excludeEnd("ide");
-messageSends: ["snippetAt:", "current", "asString"]
-}),
-$globals.CharacterArray);
-
 $core.addMethod(
 $core.method({
 selector: "appendToBrush:",

+ 0 - 153
src/Web.st

@@ -28,22 +28,6 @@ root
 
 root: aTagBrush
 	root := aTagBrush
-!
-
-snippet: anElement
-	"Adds clone of anElement, finds [data-snippet=""*""] subelement
-	and returns TagBrush as if that subelement was just added.
-	
-	Rarely needed to use directly, use `html foo` dynamically installed method
-	for a snippet named foo."
-	
-	| clone caret |
-	
-	clone := anElement asJQuery clone.
-	self with: (TagBrush fromJQuery: clone canvas: self).
-	caret := clone find: '[data-snippet="*"]'.
-	caret toArray ifEmpty: [ caret := clone ].
-	^ TagBrush fromJQuery: (caret removeAttr: 'data-snippet') canvas: self
 ! !
 
 !HTMLCanvas methodsFor: 'adding'!
@@ -513,137 +497,6 @@ onJQuery: aJQuery
 		yourself
 ! !
 
-Object subclass: #HTMLSnippet
-	instanceVariableNames: 'snippets'
-	package: 'Web'!
-!HTMLSnippet commentStamp!
-My sole instance is the registry of html snippets.
-`HTMLSnippet current` is the public singleton instance.
-
-On startup, it scans the document for any html elements
-with `'data-snippet="foo"'` attribute and takes them off the document,
-remembering them in the store under the specified name.
-It also install method #foo into HTMLCanvas dynamically.
-
-Every html snippet should mark a 'caret', a place where contents
-can be inserted, by 'data-snippet="*"' (a special name for caret).
-For example:
-
-`<li data-snippet='menuelement' class='...'><a data-snippet='*'></a></li>`
-
-defines a list element with a link inside; the link itself is marked as a caret.
-
-You can later issue
-
-`html menuelement href: '/foo'; with: 'A foo'`
-
-to insert the whole snippet and directly manipulate the caret, so it renders:
-
-`<li class='...'><a href='/foo'>A foo</a></li>`
-
-For a self-careting tags (not very useful, but you do not need to fill class etc.
-you can use
-
-`<div class='lots of classes' attr1='one' attr2='two' data-snippet='*bar'></div>`
-
-and in code later do:
-
-`html bar with: [ xxx ]`
-
-to render
-
-`<div class='lots of classes' attr1='one' attr2='two'>...added by xxx...</div>`!
-
-!HTMLSnippet methodsFor: 'accessing'!
-
-snippetAt: aString
-	^ self snippets at: aString
-!
-
-snippets
-	^ snippets ifNil: [ snippets := #{} ]
-! !
-
-!HTMLSnippet methodsFor: 'initialization'!
-
-initializeFromJQuery: aJQuery
-	"Finds and takes out all snippets out of aJQuery.
-	Installs it into self."
-	
-	(self snippetsFromJQuery: aJQuery) do: [ :each |
-		self installSnippetFromJQuery: each asJQuery ]
-! !
-
-!HTMLSnippet methodsFor: 'method generation'!
-
-snippetAt: aString compile: anElement
-	"Method generation for the snippet.
-	The selector is aString, the method block uses anElement"
-	
-	ClassBuilder new
-		installMethod: ([ :htmlReceiver | htmlReceiver snippet: anElement ]
-			currySelf asCompiledMethod: aString)
-		forClass: HTMLCanvas
-		protocol: '**snippets'
-! !
-
-!HTMLSnippet methodsFor: 'private'!
-
-snippetsFromJQuery: aJQuery
-	^ (aJQuery find: '[data-snippet]') toArray
-! !
-
-!HTMLSnippet methodsFor: 'snippet installation'!
-
-installSnippetFromJQuery: element
-	| name |
-	name := element attr: 'data-snippet'.
-	name = '*' ifFalse: [
-		('^\*' asRegexp test: name)
-			ifTrue: [
-				name := name allButFirst.
-				element attr: 'data-snippet' put: '*' ]
-			ifFalse: [
-				element removeAttr: 'data-snippet' ].
-		self snippetAt: name install: (element detach get: 0) ]
-!
-
-snippetAt: aString install: anElement
-	self snippets at: aString put: anElement.
-	self snippetAt: aString compile: anElement
-! !
-
-HTMLSnippet class instanceVariableNames: 'current'!
-
-!HTMLSnippet class methodsFor: 'initialization'!
-
-ensureCurrent
-	current ifNil: [
-		current := super new
-			initializeFromJQuery: document asJQuery;
-			yourself ]
-!
-
-initialize
-	super initialize.
-	self isDOMAvailable ifTrue: [
-		self ensureCurrent ]
-! !
-
-!HTMLSnippet class methodsFor: 'instance creation'!
-
-current
-	^ current
-!
-
-isDOMAvailable
-	< return typeof document !!== 'undefined' >
-!
-
-new
-	self shouldNotImplement
-! !
-
 Object subclass: #TagBrush
 	instanceVariableNames: 'canvas element'
 	package: 'Web'!
@@ -1075,12 +928,6 @@ appendToJQuery: aJQuery
 	self value: (HTMLCanvas onJQuery: aJQuery)
 ! !
 
-!CharacterArray methodsFor: '*Web'!
-
-asSnippet
-	^ HTMLSnippet current snippetAt: self asString
-! !
-
 !Collection methodsFor: '*Web'!
 
 appendToBrush: aTagBrush