[KSS-checkins] r50319 - in kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes: . doc kukit
reebalazs at codespeak.net
reebalazs at codespeak.net
Fri Jan 4 17:57:25 CET 2008
Author: reebalazs
Date: Fri Jan 4 17:57:24 2008
New Revision: 50319
Modified:
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/ (props changed)
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/doc/HISTORY.txt
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/forms.js
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/oper.js
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/providerreg.js
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/resourcedata.js
kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/selectorreg.js
Log:
Refactor value provider evaluation, make 1 registry out of 3.
Remove deprecated form(), currentForm() providers in normal parameters.
(It would take some more code to make them working but
since they are deprecated long ago, I just removed them.)
Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/doc/HISTORY.txt
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/doc/HISTORY.txt (original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/doc/HISTORY.txt Fri Jan 4 17:57:24 2008
@@ -6,6 +6,19 @@
- ...
+ - refactor the value provider registry to use
+ a single registry in place of 3.
+ This will enable to define value
+ providers that recieve non-string parameters
+ like a node selection.
+
+ Remove previously deprecated form() and
+ currentForm() value providers from normal
+ action parameters (remark: they should
+ be used with kssSelector.)
+ They now give a parsing error.
+ [ree]
+
- Fix multiple selection form fields
marshalling on Safari
(fixes #22 in kssproject)
Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/forms.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/forms.js (original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/forms.js Fri Jan 4 17:57:24 2008
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2005-2007
+* Copyright (c) 2005-2008
* Authors: KSS Project Contributors (see doc/CREDITS.txt)
*
* This program is free software; you can redistribute it and/or modify
@@ -307,14 +307,14 @@
this.fieldUpdateRegistry = new _FieldUpdateRegistry();
-// Registry of the pprovider functions for kssSubmitForm
-
-fo.pproviderFormRegistry = new kukit.pr.ValueProviderRegistry();
-
-// form, currentForm will provide identical functions to those
-// in normal parameters
-// except they return a tuple list, not a dictionary.
+//
+// form, currentForm will fetch an entire form for marshalling.
// This is needed because duplications and order must be preserved.
+// The returnType of them will be registered as "formquery". This
+// represents a list of (key, value) tuples that need to be marshalled.
+// This assures to preserve order of keys, which is important
+// for multi-values.
+//
/*
*
@@ -335,7 +335,7 @@
return fo.getAllFormVars(locator, collector);
}
};
-fo.pproviderFormRegistry.register('form', _FormValueProvider);
+kukit.pprovidersGlobalRegistry.register('form', _FormValueProvider, 'formquery');
/*
*
@@ -355,12 +355,7 @@
return fo.getAllFormVars(locator, collector);
}
};
-fo.pproviderFormRegistry.register('currentForm', _CurrentFormValueProvider);
-
-// If a string is given, that will look like a form lookup,
-// ie. identical to form
-fo.pproviderFormRegistry.register('', _FormValueProvider);
-
+kukit.pprovidersGlobalRegistry.register('currentForm', _CurrentFormValueProvider, 'formquery');
/* BBB. To be deprecated on 2008-06-15 */
Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js (original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/kssparser.js Fri Jan 4 17:57:24 2008
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2005-2007
+* Copyright (c) 2005-2008
* Authors: KSS Project Contributors (see doc/CREDITS.txt)
*
* This program is free software; you can redistribute it and/or modify
@@ -266,12 +266,6 @@
}
kukit.kssp.Block.prototype.addActionParameter = function(action, key, value) {
- var ppRegistries = {
- '': kukit.pprovidersGlobalRegistry,
- 'kssSelector': kukit.sr.pproviderSelRegistry,
- 'kssSubmitForm': kukit.fo.pproviderFormRegistry
- };
-
// <ACTIONNAME>-<KEY>: <VALUE>
// default-<KEY>: <VALUE>
//
@@ -282,22 +276,42 @@
// This will also set the value providers on the value
// (from check).
//
- // Figure out which registry to use.
- var registry = ppRegistries[key];
- if (typeof(registry) == 'undefined') {
- // use default pproviders
- registry = ppRegistries[''];
- }
- //
try {
// Check also sets the value provider on the value.
- value.check(registry);
+ value.check();
} catch(e) {
;;; kukit.E = 'Error in value : ' + e + '.';
this.emitError(kukit.E);
}
+;;; // Check return type
+;;; // strings are currently unwrapped and will have
+;;; // returnType == undefined, so we check for that.
+;;; var returnType = value.pprovider.returnType;
+;;; if (key == 'kssSelector') {
+;;; // for kssSelector, string or formquery expected
+;;; if (returnType && returnType != 'string' && returnType != 'selection') {
+;;; kukit.E = 'Expected string or a selection result and got [' + returnType;
+;;; kukit.E += '] in the kss action parameter [kssSelector].';
+;;; this.emitError(kukit.E);
+;;; }
+;;; } else if (key == 'kssSubmitForm') {
+;;; // for kssSelector, string or formquery expected
+;;; if (returnType && returnType != 'string' && returnType != 'formquery') {
+;;; kukit.E = 'Expected string or a formquery result and got [' + returnType;
+;;; kukit.E += '] in the kss action parameter [kssSubmitForm].';
+;;; this.emitError(kukit.E);
+;;; }
+;;; } else {
+;;; // for all other cases, string is expected
+;;; if (returnType && returnType != 'string') {
+;;; kukit.E = 'Expected string and got [' + returnType;
+;;; kukit.E += '] in the action parameter [' + key + '].';
+;;; this.emitError(kukit.E);
+;;; }
+;;; }
+ // store the value
action.parms[key] = value;
-}
+};
kukit.kssp.Block.prototype.addDeclaration = function(key, value) {
// p.s. value is here a KssXxParm. In most cases we check and unwrap it.
Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/oper.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/oper.js (original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/oper.js Fri Jan 4 17:57:24 2008
@@ -204,18 +204,27 @@
};
kukit.op.Oper.prototype.executeServerAction = function(name) {
-;;; for (key in this.kssParms) {
-;;; if (key == 'kssUrl') {
-;;; // Value will be evaluated.
-;;; } else if (key == 'kssSubmitForm') {
+ for (key in this.kssParms) {
+ if (key == 'kssSubmitForm') {
+ // Value has been evaluated at this point.
+ var formQuery = this.kssParms[key];
+ // If a string is returned: this is to support
+ // kssSubmitForm: "formname";
+ // in this case this is evaluated as form("formname").
+ if (typeof(formQuery) == 'string') {
+ var locator = new kukit.fo.NamedFormLocator(formQuery);
+ var collector = new kukit.ut.TupleCollector();
+ formQuery = kukit.fo.getAllFormVars(locator, collector);
+ }
+;;; } else if (key == 'kssUrl') {
;;; // Value will be evaluated.
;;; } else {
;;; kukit.E = 'Wrong parameter : [' + key + '] starts with "kss";';
;;; kukit.E += ' normal parms (that do not start with kss)';
;;; kukit.E += ' only are allowed in action-server keys.';
;;; throw new Error(kukit.E);
-;;; }
-;;; }
+ }
+ }
// oper will be accessible to some commands that execute in return
var sa = new kukit.sa.ServerAction(name, this);
};
Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/providerreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/providerreg.js (original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/providerreg.js Fri Jan 4 17:57:24 2008
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2005-2007
+* Copyright (c) 2005-2008
* Authors: KSS Project Contributors (see doc/CREDITS.txt)
*
* This program is free software; you can redistribute it and/or modify
@@ -29,7 +29,7 @@
this.content = {};
};
-kukit.pr.ValueProviderRegistry.prototype.register = function(name, func) {
+kukit.pr.ValueProviderRegistry.prototype.register = function(name, func, returnType) {
if (typeof(func) == 'undefined') {
;;; kukit.E = 'func argument is mandatory when registering a parameter'
;;; kukit.E += ' provider [ValueProviderRegistry.register].';
@@ -43,6 +43,11 @@
;;; return;
;;; }
this.content[name] = func;
+ // Handle return type
+ // XXX Store it on the func's prototype.
+ // This is a temporary solution, the service-layer
+ // branch offers a proper way to do this.
+ func.prototype.returnType = returnType;
};
kukit.pr.ValueProviderRegistry.prototype.exists = function(name) {
@@ -165,43 +170,6 @@
kukit.pprovidersGlobalRegistry.register('currentFormVarFromKssAttr',
kukit.pr.CurrentFormVarFromKssAttrPP);
-
-/* BBB. To be deprecated at 2007-08-15 */
-kukit.pr.FormPP = function() {};
-kukit.pr.FormPP.prototype = {
- check: function(args) {
-;;; if (args.length != 1) {
-;;; throw new Error('form method needs 1 arguments [formname]');
-;;; }
-;;; var msg = 'Deprecated the [form(formname)] parameter provider,';
-;;; msg += ' use [xxx-kssSubmitForm: form(formname)] instead !';
-;;; kukit.logWarning(msg);
- },
- eval: function(args, node) {
- return kukit.fo.getAllFormVars(new kukit.fo.NamedFormLocator(args[0]),
- new kukit.ut.DictCollector());
- }
-};
-kukit.pprovidersGlobalRegistry.register('form', kukit.pr.FormPP);
-
-/* BBB. To be deprecated at 2007-08-15 */
-kukit.pr.CurrentFormPP = function() {};
-kukit.pr.CurrentFormPP.prototype = {
- check: function(args) {
-;;; if (args.length != 0) {
-;;; throw new Error('currentForm method needs no argument');
-;;; }
-;;; var msg = 'Deprecated the [currentForm()] parameter provider,';
-;;; msg += ' use [xxx-kssSubmitForm: currentForm()] instead !';
-;;; kukit.logWarning(msg);
- },
- eval: function(args, node) {
- return kukit.fo.getAllFormVars(new kukit.fo.CurrentFormLocator(node),
- new kukit.ut.DictCollector());
- }
-};
-kukit.pprovidersGlobalRegistry.register('currentForm', kukit.pr.CurrentFormPP);
-
kukit.pr.NodeAttrPP = function() {};
kukit.pr.NodeAttrPP.prototype = {
check: function(args) {
Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/resourcedata.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/resourcedata.js (original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/resourcedata.js Fri Jan 4 17:57:24 2008
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2005-2007
+* Copyright (c) 2005-2008
* Authors: KSS Project Contributors (see doc/CREDITS.txt)
*
* This program is free software; you can redistribute it and/or modify
@@ -154,9 +154,9 @@
kukit.rd.KssTextValue.prototype.isMethod = false;
-kukit.rd.KssTextValue.prototype.check = function(registry) {
+kukit.rd.KssTextValue.prototype.check = function() {
// use the IdentityPP provider.
- this.pprovider = new (registry.get(''))();
+ this.pprovider = new (kukit.pprovidersGlobalRegistry.get(''))();
};
kukit.rd.KssTextValue.prototype.evaluate =
@@ -179,22 +179,44 @@
kukit.rd.KssMethodValue.prototype.isMethod = true;
-kukit.rd.KssMethodValue.prototype.check = function(registry) {
+kukit.rd.KssMethodValue.prototype.check = function() {
// Check syntax
- var f = registry.get(this.methodName);
+ var f = kukit.pprovidersGlobalRegistry.get(this.methodName);
this.pprovider = new f();
+;;; //Check the provider first.
+;;; this.pprovider.check(this.args);
+ // After checking the provider, we check the args recursively.
for(i=0; i < this.args.length; i++){
// XXX We treat text values separetly because
// they are now currently wrapped as KssTextValue
// (as they should). TODO
var arg = this.args[i];
+ // XXX this is a check for a MethodValue, since
+ // all text arguments are strings. -- this is fixed
+ // on the service-layer branch
if(arg.check){
- // With the recursion we always use the global
- // provider registry
- arg.check(kukit.pprovidersGlobalRegistry);
+ arg.check();
+;;; // The page provider should have checked if the parameters
+;;; // return the appropriate value type. If it has done
+;;; // this check, it has set checkedArgTypes.
+;;; // If a provider expects all strings
+;;; // (like most value providers), it simply leaves this flag
+;;; // intact, and we do the check here.
+;;; if (! this.checkedArgTypes) {
+;;; // We expect a string to each position.
+;;; // By default, returnType is "string" so we also
+;;; // check undefined.
+;;; var returnType = arg.pprovider.returnType;
+;;; if (returnType && returnType != 'string') {
+;;; kukit.E = 'Expected string value and got [' + returnType;
+;;; kukit.E += '] in argument #[' + (i + 1) + '] of provider [';
+;;; kukit.E += this.methodName + '].';
+;;; throw new Error(kukit.E);
+;;; }
+;;; }
+
}
}
-;;; this.pprovider.check(this.args);
};
kukit.rd.KssMethodValue.prototype.evaluate =
@@ -599,6 +621,17 @@
}
};
+// The evaluation of string is handled specially
+// in case of some parameter names.
+//
+// kssSelector string "foo" evaluates as css("foo")
+// kssSubmitForm string "foo" evaluates as form("foo")
+//
+kukit.rd.Action.prototype.defaultStringHandling = {
+ 'kssSelector': 'css',
+ 'kssSubmitForm': 'form'
+};
+
kukit.rd.Action.prototype.makeActionOper = function(oper) {
// Fill the completed action parms, based on the node
// The kssXxx parms, reserved for the action, are
@@ -610,16 +643,30 @@
if (typeof(oper.defaultParameters) == 'undefined') {
oper.defaultParameters = {};
}
+ // Evaluate all parameters.
for (var key in this.parms) {
- var kssvalue = this.parms[key];
+ // Evaluate the value of the parameter.
+ var value = this.parms[key].evaluate(oper.node,
+ oper.defaultParameters);
+ // Final handling of special cases.
+ // This is needed in case we have a string, and we
+ // look up the provider we need from the defaultStringHandling table.
+ var providerName = this.defaultStringHandling[key];
+ if (providerName && typeof(value) == 'string') {
+ // Use the value provider. This means the string is
+ // a shortcut and this provider is applied.
+ var providerClass = kukit.pprovidersGlobalRegistry.get(providerName);
+ var provider = new providerClass();
+ // check is not needed now... we evaluate it right away
+ value = provider.eval([value], oper.node, oper.defaultParameters);
+ }
+ // Store it, depending if it's a kss or normal parameter.
if (key.match(/^kss/)) {
// kssXxx parms are separated to kssParms.
- kssParms[key] = kssvalue.evaluate(oper.node,
- oper.defaultParameters);
+ kssParms[key] = value;
} else {
// evaluate the method parms into parms
- parms[key] = kssvalue.evaluate(oper.node,
- oper.defaultParameters);
+ parms[key] = value;
}
}
var anOper = oper.clone({
Modified: kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/selectorreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/selectorreg.js (original)
+++ kukit/kukit.js/branch/ree-1.4-markup-and-syntax-changes/kukit/selectorreg.js Fri Jan 4 17:57:24 2008
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2005-2007
+* Copyright (c) 2005-2008
* Authors: KSS Project Contributors (see doc/CREDITS.txt)
*
* This program is free software; you can redistribute it and/or modify
@@ -19,11 +19,6 @@
kukit.sr = {};
-// Registry of the pprovider functions for selecting
-
-kukit.sr.pproviderSelRegistry = new kukit.pr.ValueProviderRegistry();
-
-
// this will provide an arbitrary selector, and is designed to
// be used with the makeAnyPP factory function.
kukit.sr.AnyPP = function() {};
@@ -43,8 +38,6 @@
}
};
-kukit.sr.pproviderSelRegistry.register('', kukit.sr.AnyPP);
-
kukit.sr.makeAnyPP = function(selector_type) {
var pp = function () {};
pp.prototype.eval = kukit.sr.AnyPP.prototype.eval;
@@ -72,7 +65,7 @@
return nodes;
}
};
-kukit.sr.pproviderSelRegistry.register('passnode', kukit.sr.PassnodePP);
+kukit.pprovidersGlobalRegistry.register('passnode', kukit.sr.PassnodePP, 'selection');
/*
@@ -103,7 +96,8 @@
this.mapping[name] = func;
// Also register the selector param provider
var pp = kukit.sr.makeAnyPP(name);
- kukit.sr.pproviderSelRegistry.register(name, pp);
+ // register them with returnType = 'nodes'
+ kukit.pprovidersGlobalRegistry.register(name, pp, 'selection');
};
kukit.sr.SelectorTypeRegistry.prototype.get = function(name) {
More information about the Kukit-checkins
mailing list