Author: reebalazs
Date: Sat Sep 15 11:09:30 2007
New Revision: 46612

Modified:
   
kukit/kss.base/trunk/kss/base/templates/plugin/+package+/javascript/plugin.js_tmpl
Log:
Enhancements on plugin.js in the plugin skeleton

Modified: 
kukit/kss.base/trunk/kss/base/templates/plugin/+package+/javascript/plugin.js_tmpl
==============================================================================
--- 
kukit/kss.base/trunk/kss/base/templates/plugin/+package+/javascript/plugin.js_tmpl
  (original)
+++ 
kukit/kss.base/trunk/kss/base/templates/plugin/+package+/javascript/plugin.js_tmpl
  Sat Sep 15 11:09:30 2007
@@ -6,23 +6,22 @@
 
 Lines beginning with `;;;` are automatically stripped when served in
 production mode. Put these in front of lines with code like assertions
-statements or logging calls.
+statements or logging calls. (But never put ;;; embedded inside multiline
+(), [] or {} constructs like an "if" condition or a "switch" statement.)
 
 */
 
-
-// Create the namespace for ${package}
-if (typeof(${pacakge}) == 'undefined') {
-    var ${package} = {};
-}
-
+// CLOSURE for plugin ${namespace}
+// The closure makes all the embedded code private.
+function () {
+// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
 
 //-----------------------------------------------------------
 //                   Action example
 //-----------------------------------------------------------
-${package}.actionsGlobalRegistry.register('exampleAction', function (oper) {
+kukit.actionsGlobalRegistry.register('${namespace}-exampleAction', function 
(oper) {
     // The following is used for logging
-;;; oper.componentName = '[exampleAction] action';
+;;; oper.componentName = '[${namespace}-exampleAction] action';
     
     // Validate the parameters to this action, you can add multiple
     // required or optional parameters. Optional parameters will be
@@ -30,6 +29,10 @@
     oper.evaluateParameters(['requiredParameter'], 
                             {'optionalParameter': 'default'});
 
+    // optionally, you can check if a parameter is of a given data type,
+    // and convert to it.
+    oper.evalBool('requiredParameter');
+
     // You can get at the node for which this action is executed like
     // this. An action is always invoked on a single node. Even when
     // it applies to multiple nodes (then it will be invoked multiple
@@ -41,55 +44,75 @@
 
     // Add your specific action code here
 });
-kukit.commandsGlobalRegistry.registerFromAction(
-    'exampleAction', kukit.cr.makeSelectorCommand);
+// The line above registers the action under the name
+// `${namespace}-exampleAction`. 
 
+kukit.commandsGlobalRegistry.registerFromAction(
+    '${namespace}-exampleAction', kukit.cr.makeSelectorCommand);
+// The line above also defines the action as a command
+// with selectors. To make a global command that executes
+// without a selector, exactly once, use makeGlobalCommand.
+// It is a good idea to always make an action into a command as well.
 
 //-----------------------------------------------------------
 //                      Value provider
 //-----------------------------------------------------------
-${package}.ExampleProvider = function() {};
-${package}.ExampleProvider.prototype = {
+var ExampleProvider = function() {};
+ExampleProvider.prototype = {
     // The check function is executed during the parsing of KSS. Use
     // this to make sure the arguments are correct.
-    check: function(args) {
-        // An example of what you could check is the argument length
+    // Use ;;; in the beginning of each line in check.
+;;; check: function(args) {
+;;; // An example of what you could check is the argument length
 ;;;     if (args.length != 2) {
-            // Raise an error in case something is wrong
+;;;         // Raise an error in case something is wrong
 ;;;         throw new Error('exampleProvider provider needs 2 arguments [one, 
two]');
 ;;;     }
-    },
+;;; },
     eval: function(args, node) {
         // Return the value which for this provider
         return 'example';
     }
 };
 kukit.pprovidersGlobalRegistry.register(
-    'exampleProvider', ${package}.ExampleProvider);
+    '${namespace}-exampleProvider', ExampleProvider);
 // The line above registers the value provider under the name
-// `exampleProvider`
+// `${namespace}-exampleProvider`
 
 
 
 //-----------------------------------------------------------
-//                      Value provider
+//              Simple event binder for stateful events
 //-----------------------------------------------------------
-${package}.ExampleEventBinder = function() {
+
+var ExampleEventBinder = function() {
     // Add your initialization stuff here
     this.exampleVar = {};
 };
-
-${package}.ExampleEventBinder.prototype.__bind__ =
+ExampleEventBinder.prototype.__bind__ =
     function(name, func_to_bind, oper) {
     // The following is used for logging
-;;; oper.componentName = 'example event binding';
+;;; oper.componentName = '[${namespace}-example] event binding';
 
     // Validate the parameters to this action, you can add multiple
     // required or optional parameters. Optional parameters will be
     // initialized with a default when not passed.
     oper.evaluateParameters(['delay'], {'repeat': 'true'});
 
+    // optionally, you can check if a parameter is of a given data type,
+    // and convert to it.
+    oper.evalInt('delay');
+    oper.evalBool('repeat');
+
+    // Add your specific event code here
 };
 
-kukit.eventsGlobalRegistry.register(null, 'exampleEvent',
-    ${package}.ExampleEventBinder, '__bind__', null);
+kukit.eventsGlobalRegistry.register('${namespace}', 'exampleEvent',
+    ExampleEventBinder, '__bind__', null);
+// The above line registers the ${namespace}-exampleEvent
+// with the binder method __bind__.
+
+
+// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+}();
+// END CLOSURE plugin ${namespace}
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to