SlideShare a Scribd company logo
1 of 31
Download to read offline
Bending KSS to your will
What KSS is about?




Making Ajax apps without writing Javascript
Subject of this talk




Extending KSS, both client and server side
Reasons for extending
    KSS might not be feature complete
●


    You have existing Javascript code
●


    Your project needs something special
●
Extending means
    Creating a plugin
●


        Client side (Javascript)
    –

             Actions
         ●


             Value providers
         ●


             Events
         ●



        Server side (Python)
    –

             Command sets
         ●
KSS terminologie

         event
                          action
#selector:click {
    action-client: do-stuff;
    do-stuff: read-var(...);
}
                       value provider
Command sets
  from kss.core import kssaction, KSSView

    class CanvasView(KSSView):

        @kssaction
        def drawRectangle(self, size):
            ksscore = self.getCommandSet('core')
            selector = ksscore.getHtmlIdSelector(
                                      'canvas-commandset')

             self.getCommandSet('demoplugin').canvasRect(
                             selector, 10, 10, size, size)

commandset
Get your gear
    Requirements
●


        Plone 3
    –

        Paster (PasteScript)
    –

        kss.templates
    –
kss.templates?
    kss_plugin
●


    kss_zope_plugin
●
Using kss.templates
$ ./bin/paster create -t kss_zope_plugin
Selected and implied templates:
kss.templates#kss_plugin           KSS plugin template
kss.templates#kss_zope_plugin      KSS Zope plugin template
Enter project name: KSSDemoPlugin
Variables:
egg:         KSSDemoPlugin
package:     kssdemoplugin
project:     KSSDemoPlugin
Enter namespace (The namespace for your plugin (something
like `my-namespace`)) ['']: demoplugin
Creating template kss_plugin
...
Running /usr/bin/python2.4 setup.py egg_info
Look at all the goodies
    KSSDemoPlugin/           kssplugindemo/
●                        ●


        README.txt                  README.txt
    –                           ●


                                    __init__.py
        setup.py
                                ●
    –
                                    commands.py
                                ●

        kssplugindemo/
    –
                                    configure.zcml
                                ●


                                    interfaces.py
                                ●


                                    javascript/plugin.js
                                ●


                                    etc.
                                ●
Starting with Javascript
    javascript/plugin.js
●


    3 sections
●


        Action
    –

        Value provider
    –

        Event
    –
Action
        Demo
    ●
Action (configure.zcml)
<!-- snip -->
<kss:action
    name=quot;demoplugin-canvasRectquot;
    jsfile=quot;javascript/plugin.jsquot;
    command_factory=quot;selectorquot;
    params_mandatory=quot;x y width heightquot;
    params_optional=quot;fillStylequot;
    />
Action (plugin.js)
kukit.actionsGlobalRegistry.register('demoplugin-canvasRect',
function (oper) {
;;; oper.componentName = '[demoplugin-canvasRect] action';
    oper.evaluateParameters(['x', 'y', 'width', 'height'],
                            {'fillStyle': 'rgb(0, 255, 0)'});
    oper.evalInt('x');
    oper.evalInt('y');
    oper.evalInt('width');
    oper.evalInt('height');

      var x = oper.parms.x;
      var y = oper.parms.y;

      var ctx = oper.node.getContext(quot;2dquot;);

      ctx.fillStyle = oper.parms.fillStyle;
      ctx.fillRect(x, y, oper.parms.width, oper.parms.height);
});
kukit.commandsGlobalRegistry.registerFromAction(
    'demoplugin-canvasRect', kukit.cr.makeSelectorCommand);
Action (plone-demo-plugin.kss)
#canvas:load {
    action-client: demoplugin-canvasRect;
    demoplugin-canvasRect-x: 10;
    demoplugin-canvasRect-y: 10;
    demoplugin-canvasRect-width: 200;
    demoplugin-canvasRect-height: 200;
    demoplugin-canvasRect-fillStyle: quot;rgb(0, 255, 0)quot;;
}
Value provider
            Demo
        ●
Value provider (configure.zcml)
<!-- snip -->
<kss:paramprovider
       name=quot;demoplugin-randomquot;
       jsfile=quot;javascript/plugin.jsquot;
       />
Value provider (plugin.js)
var RandomProvider = function() {};
RandomProvider.prototype = {
;;; check: function(args) {
;;;     if (args.length < 1) {
;;;         throw new Error(
                'demoplugin-random needs at least 1 argument [max]');
;;;     }
;;; },
    eval: function(args, node) {
        if(args.length == 2){
            var min = args[0];
            var max = args[1];
        } else {
            var min = 0;
            var max = args[0];
        }
        var range = max – min;
        var rand = (Math.random() * range) + min;
        return rand;
    }
};
kukit.pprovidersGlobalRegistry.register(
    'demoplugin-random', RandomProvider);
Value provider (plone-demo-plugin.kss)
#canvas:timeout {
    evt-timeout-delay: 1;
    evt-timeout-repeat: True;


    action-client: demoplugin-canvasRect;
    demoplugin-canvasRect-x: demoplugin-random(300);
    demoplugin-canvasRect-y: demoplugin-random(300);
    demoplugin-canvasRect-width: demoplugin-random(10, 30);
    demoplugin-canvasRect-height: demoplugin-random(10, 30);
    demoplugin-canvasRect-fillStyle: demoplugin-randomColor();
}
Event
        Demo
    ●
Event (configure.zcml)
<!-- snip -->
<kss:eventtype
    name=quot;demoplugin-movementquot;
    jsfile=quot;javascript/plugin.jsquot;
    />
Event – part 1 (plone-demo-plugin.kss)
var MovementEventBinder = function() {
     this.x = 0;
     this.y = 0;
};
Event – part 2 (plugin.js)
MovementEventBinder.prototype.__bind__ = function(name, func_to_bind, oper) {
;;; oper.componentName = '[demoplugin-movement] event binding';
    var keyMovement = {
        37: [-1, 0], // left
        38: [0, -1], // up
        39: [1, 0], // right
        40: [0, 1] // down
    };

     oper.completeParms([], {'x': '0', 'y': '0', 'speed': '1'}, 'movement event binding');
     oper.evalInt('x');
     oper.evalInt('y');
     oper.evalInt('speed');

     var self = this;
     var speed = oper.parms.speed;

     var f = oper.makeExecuteActionsHook();

     func = function(e) {
         var keyCode = e.keyCode.toString();
         if(typeof(keyMovement[keyCode]) == 'undefined'){
             return;
         }
         self.x += keyMovement[keyCode][0] * speed;
         self.y += keyMovement[keyCode][1] * speed;

        f({defaultParameters: {'x': self.x, 'y': self.y}});
     };
     kukit.ut.registerEventListener(document, 'keydown', func);
};

kukit.eventsGlobalRegistry.register('demoplugin', 'movement',
    MovementEventBinder, '__bind__', null);
Event (plone-demo-plugin.kss)
#canvas:demoplugin-movement {
    action-client: demoplugin-canvasRect;
    evt-demoplugin-movement-speed: 10;
    demoplugin-canvasRect-x: pass(x);
    demoplugin-canvasRect-y: pass(y);
    demoplugin-canvasRect-width: 10;
    demoplugin-canvasRect-height: 10;
    demoplugin-canvasRect-fillStyle: quot;rgb(255, 0, 255)quot;;
}
Commandset
          Demo
      ●
Commandset (configure.zcml)
<!-- snip -->
<kss:commandset
     name=quot;demopluginquot;
     for=quot;kss.core.interfaces.IKSSViewquot;
     class=quot;.commands.KSSDemoPluginCommandsquot;
     provides=quot;.interfaces.IKSSDemoPluginCommandsquot;
     />
Commandset (commands.py)
from kss.core.kssview import CommandSet

class KSSDemoPluginCommands(CommandSet):
    def canvasRect(self, selector, x, y,
                   width, height, fillStyle=None):
        command = self.commands.addCommand(
                         'demoplugin-canvasRect', selector)
        command.addParam('x', str(int(x)))
        command.addParam('y', str(int(y)))
        command.addParam('width', str(int(width)))
        command.addParam('height', str(int(height)))

        if fillStyle is not None:
            command.addParam('fillStyle', fillStyle)
Commandset (plone-demo-plugin.kss)
#canvas-commandset:load {
    action-server: drawRectangle;
    drawRectangle-size: 200;
}
Using the commandset (plonedemo/canvas.py)
from kss.core import kssaction, KSSView

class CanvasView(KSSView):
    @kssaction
    def drawRectangle(self, size):
        ksscore = self.getCommandSet('core')
        selector = ksscore.getHtmlIdSelector(
                              'canvas-commandset')

        self.getCommandSet('demoplugin').canvasRect(
                           selector, 10, 10, size, size)
Wrap up
    Creating plugins not that hard
●


    More docs on: http://kssproject.org
●


    Remember:
●


        KSS is about not having to write Javascript!
    –

More Related Content

What's hot

Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
Michael Lehmann
 
Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMR
Shinji Tanaka
 

What's hot (20)

FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Scalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureScalable Angular 2 Application Architecture
Scalable Angular 2 Application Architecture
 
ES6, 잘 쓰고 계시죠?
ES6, 잘 쓰고 계시죠?ES6, 잘 쓰고 계시죠?
ES6, 잘 쓰고 계시죠?
 
Introducing perf budgets on CI with puppeteer - perf.now()
Introducing perf budgets on CI with puppeteer - perf.now()Introducing perf budgets on CI with puppeteer - perf.now()
Introducing perf budgets on CI with puppeteer - perf.now()
 
Bangun datar dan bangun ruang
Bangun datar dan bangun ruangBangun datar dan bangun ruang
Bangun datar dan bangun ruang
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101
 
Spring data iii
Spring data iiiSpring data iii
Spring data iii
 
Interactive subway map
Interactive subway mapInteractive subway map
Interactive subway map
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret Sauce
 
Cooking Up Drama
Cooking Up DramaCooking Up Drama
Cooking Up Drama
 
Cooking Up Drama - ChefConf 2015
Cooking Up Drama - ChefConf 2015 Cooking Up Drama - ChefConf 2015
Cooking Up Drama - ChefConf 2015
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & Jetpack
 
Nodejs mongoose
Nodejs mongooseNodejs mongoose
Nodejs mongoose
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
Creating Reusable Puppet Profiles
Creating Reusable Puppet ProfilesCreating Reusable Puppet Profiles
Creating Reusable Puppet Profiles
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
 
Lightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMRLightweight wrapper for Hive on Amazon EMR
Lightweight wrapper for Hive on Amazon EMR
 

Viewers also liked

Brent Lambert Plone In Education A Case Study Of The Use Of Plone And Educa...
Brent Lambert   Plone In Education A Case Study Of The Use Of Plone And Educa...Brent Lambert   Plone In Education A Case Study Of The Use Of Plone And Educa...
Brent Lambert Plone In Education A Case Study Of The Use Of Plone And Educa...
Vincenzo Barone
 

Viewers also liked (7)

Jean Paul Ladage Managing Enterprise Content With Plone
Jean Paul Ladage   Managing Enterprise Content With PloneJean Paul Ladage   Managing Enterprise Content With Plone
Jean Paul Ladage Managing Enterprise Content With Plone
 
Brent Lambert Plone In Education A Case Study Of The Use Of Plone And Educa...
Brent Lambert   Plone In Education A Case Study Of The Use Of Plone And Educa...Brent Lambert   Plone In Education A Case Study Of The Use Of Plone And Educa...
Brent Lambert Plone In Education A Case Study Of The Use Of Plone And Educa...
 
Darci Hanning Top Ten Ways To Get Involved With The Plone Community
Darci Hanning   Top Ten Ways To Get Involved With The Plone CommunityDarci Hanning   Top Ten Ways To Get Involved With The Plone Community
Darci Hanning Top Ten Ways To Get Involved With The Plone Community
 
Francesco Ciriaci Get Plone To Business!
Francesco Ciriaci   Get Plone To Business!Francesco Ciriaci   Get Plone To Business!
Francesco Ciriaci Get Plone To Business!
 
Building a humane CMS for Plone: updated tutorial
Building a humane CMS for Plone: updated tutorialBuilding a humane CMS for Plone: updated tutorial
Building a humane CMS for Plone: updated tutorial
 
Vincenzo Di Somma Why Should You Learn More About Workflow In Plone
Vincenzo Di Somma   Why Should You Learn More About Workflow In PloneVincenzo Di Somma   Why Should You Learn More About Workflow In Plone
Vincenzo Di Somma Why Should You Learn More About Workflow In Plone
 
Paul Everitt Community And Foundation Plones Past, Present, Future
Paul Everitt   Community And Foundation   Plones Past, Present, Future Paul Everitt   Community And Foundation   Plones Past, Present, Future
Paul Everitt Community And Foundation Plones Past, Present, Future
 

Similar to Jeroen Vloothuis Bend Kss To Your Will

Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
gerbille
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Paulo Ragonha
 

Similar to Jeroen Vloothuis Bend Kss To Your Will (20)

Reliable Javascript
Reliable Javascript Reliable Javascript
Reliable Javascript
 
Workflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.jsWorkflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.js
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
(BDT401) Big Data Orchestra - Harmony within Data Analysis Tools | AWS re:Inv...
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
 
Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Continuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScriptContinuous Integration for front-end JavaScript
Continuous Integration for front-end JavaScript
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
A few good JavaScript development tools
A few good JavaScript development toolsA few good JavaScript development tools
A few good JavaScript development tools
 
Guide to Node.js: Basic to Advanced
Guide to Node.js: Basic to AdvancedGuide to Node.js: Basic to Advanced
Guide to Node.js: Basic to Advanced
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"Artem Yavorsky "99 ways to take away your ugly polyfills"
Artem Yavorsky "99 ways to take away your ugly polyfills"
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 

More from Vincenzo Barone

Alec Mitchell Relationship Building Defining And Querying Complex Relatio...
Alec Mitchell   Relationship Building   Defining And Querying Complex Relatio...Alec Mitchell   Relationship Building   Defining And Querying Complex Relatio...
Alec Mitchell Relationship Building Defining And Querying Complex Relatio...
Vincenzo Barone
 

More from Vincenzo Barone (20)

Sally Kleinfeldt - Plone Application Development Patterns
Sally Kleinfeldt - Plone Application Development PatternsSally Kleinfeldt - Plone Application Development Patterns
Sally Kleinfeldt - Plone Application Development Patterns
 
Where's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind PloneWhere's the source, Luke? : How to find and debug the code behind Plone
Where's the source, Luke? : How to find and debug the code behind Plone
 
ItalianSkin: an improvement in the accessibility of the Plone interface in or...
ItalianSkin: an improvement in the accessibility of the Plone interface in or...ItalianSkin: an improvement in the accessibility of the Plone interface in or...
ItalianSkin: an improvement in the accessibility of the Plone interface in or...
 
How to market Plone the Web2.0 way
How to market Plone the Web2.0 wayHow to market Plone the Web2.0 way
How to market Plone the Web2.0 way
 
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
Lennart Regebro   What Zope Did Wrong (And What To Do Instead)Lennart Regebro   What Zope Did Wrong (And What To Do Instead)
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
 
Wichert Akkerman Plone Deployment Practices The Plone.Org Setup
Wichert Akkerman   Plone Deployment Practices   The Plone.Org SetupWichert Akkerman   Plone Deployment Practices   The Plone.Org Setup
Wichert Akkerman Plone Deployment Practices The Plone.Org Setup
 
Philipp Von Weitershausen Untested Code Is Broken Code
Philipp Von Weitershausen   Untested Code Is Broken CodePhilipp Von Weitershausen   Untested Code Is Broken Code
Philipp Von Weitershausen Untested Code Is Broken Code
 
Duco Dokter - Plone for the enterprise market: technical musing on caching, C...
Duco Dokter - Plone for the enterprise market: technical musing on caching, C...Duco Dokter - Plone for the enterprise market: technical musing on caching, C...
Duco Dokter - Plone for the enterprise market: technical musing on caching, C...
 
Rocky Burt Subtyping Unleashed
Rocky Burt   Subtyping UnleashedRocky Burt   Subtyping Unleashed
Rocky Burt Subtyping Unleashed
 
Alec Mitchell Relationship Building Defining And Querying Complex Relatio...
Alec Mitchell   Relationship Building   Defining And Querying Complex Relatio...Alec Mitchell   Relationship Building   Defining And Querying Complex Relatio...
Alec Mitchell Relationship Building Defining And Querying Complex Relatio...
 
Wageindicator Foundation: a Case Study
Wageindicator Foundation: a Case StudyWageindicator Foundation: a Case Study
Wageindicator Foundation: a Case Study
 
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product DevelopmentTom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
 
Xavier Heymans Plone Gov Plone In The Public Sector. Panel Presenting The...
Xavier Heymans   Plone Gov   Plone In The Public Sector. Panel Presenting The...Xavier Heymans   Plone Gov   Plone In The Public Sector. Panel Presenting The...
Xavier Heymans Plone Gov Plone In The Public Sector. Panel Presenting The...
 
Wichert Akkerman - Plone.Org Infrastructure
Wichert Akkerman - Plone.Org InfrastructureWichert Akkerman - Plone.Org Infrastructure
Wichert Akkerman - Plone.Org Infrastructure
 
Philipp Von Weitershausen Plone Age Mammoths, Sabers And Caveen Cant The...
Philipp Von Weitershausen   Plone Age  Mammoths, Sabers And Caveen   Cant The...Philipp Von Weitershausen   Plone Age  Mammoths, Sabers And Caveen   Cant The...
Philipp Von Weitershausen Plone Age Mammoths, Sabers And Caveen Cant The...
 
Denis Mishunov Making Plone Theme 10 Most Wanted Tips
Denis Mishunov   Making Plone Theme   10 Most Wanted Tips Denis Mishunov   Making Plone Theme   10 Most Wanted Tips
Denis Mishunov Making Plone Theme 10 Most Wanted Tips
 
Duncan Booth Kupu, Past Present And Future
Duncan Booth   Kupu, Past Present And FutureDuncan Booth   Kupu, Past Present And Future
Duncan Booth Kupu, Past Present And Future
 
Jared Whitlock Open Source In The Enterprise Plone @ Novell
Jared Whitlock   Open Source In The Enterprise    Plone @ NovellJared Whitlock   Open Source In The Enterprise    Plone @ Novell
Jared Whitlock Open Source In The Enterprise Plone @ Novell
 
Thomas Moroz Open Source And The Open Society Using Plone To Build Commun...
Thomas Moroz   Open Source And The Open Society   Using Plone To Build Commun...Thomas Moroz   Open Source And The Open Society   Using Plone To Build Commun...
Thomas Moroz Open Source And The Open Society Using Plone To Build Commun...
 
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
Lennart Regebro   What Zope Did Wrong (And What To Do Instead)Lennart Regebro   What Zope Did Wrong (And What To Do Instead)
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Jeroen Vloothuis Bend Kss To Your Will

  • 1. Bending KSS to your will
  • 2. What KSS is about? Making Ajax apps without writing Javascript
  • 3. Subject of this talk Extending KSS, both client and server side
  • 4. Reasons for extending KSS might not be feature complete ● You have existing Javascript code ● Your project needs something special ●
  • 5. Extending means Creating a plugin ● Client side (Javascript) – Actions ● Value providers ● Events ● Server side (Python) – Command sets ●
  • 6. KSS terminologie event action #selector:click { action-client: do-stuff; do-stuff: read-var(...); } value provider
  • 7. Command sets from kss.core import kssaction, KSSView class CanvasView(KSSView): @kssaction def drawRectangle(self, size): ksscore = self.getCommandSet('core') selector = ksscore.getHtmlIdSelector( 'canvas-commandset') self.getCommandSet('demoplugin').canvasRect( selector, 10, 10, size, size) commandset
  • 8. Get your gear Requirements ● Plone 3 – Paster (PasteScript) – kss.templates –
  • 9. kss.templates? kss_plugin ● kss_zope_plugin ●
  • 10. Using kss.templates $ ./bin/paster create -t kss_zope_plugin Selected and implied templates: kss.templates#kss_plugin KSS plugin template kss.templates#kss_zope_plugin KSS Zope plugin template Enter project name: KSSDemoPlugin Variables: egg: KSSDemoPlugin package: kssdemoplugin project: KSSDemoPlugin Enter namespace (The namespace for your plugin (something like `my-namespace`)) ['']: demoplugin Creating template kss_plugin ... Running /usr/bin/python2.4 setup.py egg_info
  • 11. Look at all the goodies KSSDemoPlugin/ kssplugindemo/ ● ● README.txt README.txt – ● __init__.py setup.py ● – commands.py ● kssplugindemo/ – configure.zcml ● interfaces.py ● javascript/plugin.js ● etc. ●
  • 12. Starting with Javascript javascript/plugin.js ● 3 sections ● Action – Value provider – Event –
  • 13. Action Demo ●
  • 14. Action (configure.zcml) <!-- snip --> <kss:action name=quot;demoplugin-canvasRectquot; jsfile=quot;javascript/plugin.jsquot; command_factory=quot;selectorquot; params_mandatory=quot;x y width heightquot; params_optional=quot;fillStylequot; />
  • 15. Action (plugin.js) kukit.actionsGlobalRegistry.register('demoplugin-canvasRect', function (oper) { ;;; oper.componentName = '[demoplugin-canvasRect] action'; oper.evaluateParameters(['x', 'y', 'width', 'height'], {'fillStyle': 'rgb(0, 255, 0)'}); oper.evalInt('x'); oper.evalInt('y'); oper.evalInt('width'); oper.evalInt('height'); var x = oper.parms.x; var y = oper.parms.y; var ctx = oper.node.getContext(quot;2dquot;); ctx.fillStyle = oper.parms.fillStyle; ctx.fillRect(x, y, oper.parms.width, oper.parms.height); }); kukit.commandsGlobalRegistry.registerFromAction( 'demoplugin-canvasRect', kukit.cr.makeSelectorCommand);
  • 16. Action (plone-demo-plugin.kss) #canvas:load { action-client: demoplugin-canvasRect; demoplugin-canvasRect-x: 10; demoplugin-canvasRect-y: 10; demoplugin-canvasRect-width: 200; demoplugin-canvasRect-height: 200; demoplugin-canvasRect-fillStyle: quot;rgb(0, 255, 0)quot;; }
  • 17. Value provider Demo ●
  • 18. Value provider (configure.zcml) <!-- snip --> <kss:paramprovider name=quot;demoplugin-randomquot; jsfile=quot;javascript/plugin.jsquot; />
  • 19. Value provider (plugin.js) var RandomProvider = function() {}; RandomProvider.prototype = { ;;; check: function(args) { ;;; if (args.length < 1) { ;;; throw new Error( 'demoplugin-random needs at least 1 argument [max]'); ;;; } ;;; }, eval: function(args, node) { if(args.length == 2){ var min = args[0]; var max = args[1]; } else { var min = 0; var max = args[0]; } var range = max – min; var rand = (Math.random() * range) + min; return rand; } }; kukit.pprovidersGlobalRegistry.register( 'demoplugin-random', RandomProvider);
  • 20. Value provider (plone-demo-plugin.kss) #canvas:timeout { evt-timeout-delay: 1; evt-timeout-repeat: True; action-client: demoplugin-canvasRect; demoplugin-canvasRect-x: demoplugin-random(300); demoplugin-canvasRect-y: demoplugin-random(300); demoplugin-canvasRect-width: demoplugin-random(10, 30); demoplugin-canvasRect-height: demoplugin-random(10, 30); demoplugin-canvasRect-fillStyle: demoplugin-randomColor(); }
  • 21. Event Demo ●
  • 22. Event (configure.zcml) <!-- snip --> <kss:eventtype name=quot;demoplugin-movementquot; jsfile=quot;javascript/plugin.jsquot; />
  • 23. Event – part 1 (plone-demo-plugin.kss) var MovementEventBinder = function() { this.x = 0; this.y = 0; };
  • 24. Event – part 2 (plugin.js) MovementEventBinder.prototype.__bind__ = function(name, func_to_bind, oper) { ;;; oper.componentName = '[demoplugin-movement] event binding'; var keyMovement = { 37: [-1, 0], // left 38: [0, -1], // up 39: [1, 0], // right 40: [0, 1] // down }; oper.completeParms([], {'x': '0', 'y': '0', 'speed': '1'}, 'movement event binding'); oper.evalInt('x'); oper.evalInt('y'); oper.evalInt('speed'); var self = this; var speed = oper.parms.speed; var f = oper.makeExecuteActionsHook(); func = function(e) { var keyCode = e.keyCode.toString(); if(typeof(keyMovement[keyCode]) == 'undefined'){ return; } self.x += keyMovement[keyCode][0] * speed; self.y += keyMovement[keyCode][1] * speed; f({defaultParameters: {'x': self.x, 'y': self.y}}); }; kukit.ut.registerEventListener(document, 'keydown', func); }; kukit.eventsGlobalRegistry.register('demoplugin', 'movement', MovementEventBinder, '__bind__', null);
  • 25. Event (plone-demo-plugin.kss) #canvas:demoplugin-movement { action-client: demoplugin-canvasRect; evt-demoplugin-movement-speed: 10; demoplugin-canvasRect-x: pass(x); demoplugin-canvasRect-y: pass(y); demoplugin-canvasRect-width: 10; demoplugin-canvasRect-height: 10; demoplugin-canvasRect-fillStyle: quot;rgb(255, 0, 255)quot;; }
  • 26. Commandset Demo ●
  • 27. Commandset (configure.zcml) <!-- snip --> <kss:commandset name=quot;demopluginquot; for=quot;kss.core.interfaces.IKSSViewquot; class=quot;.commands.KSSDemoPluginCommandsquot; provides=quot;.interfaces.IKSSDemoPluginCommandsquot; />
  • 28. Commandset (commands.py) from kss.core.kssview import CommandSet class KSSDemoPluginCommands(CommandSet): def canvasRect(self, selector, x, y, width, height, fillStyle=None): command = self.commands.addCommand( 'demoplugin-canvasRect', selector) command.addParam('x', str(int(x))) command.addParam('y', str(int(y))) command.addParam('width', str(int(width))) command.addParam('height', str(int(height))) if fillStyle is not None: command.addParam('fillStyle', fillStyle)
  • 29. Commandset (plone-demo-plugin.kss) #canvas-commandset:load { action-server: drawRectangle; drawRectangle-size: 200; }
  • 30. Using the commandset (plonedemo/canvas.py) from kss.core import kssaction, KSSView class CanvasView(KSSView): @kssaction def drawRectangle(self, size): ksscore = self.getCommandSet('core') selector = ksscore.getHtmlIdSelector( 'canvas-commandset') self.getCommandSet('demoplugin').canvasRect( selector, 10, 10, size, size)
  • 31. Wrap up Creating plugins not that hard ● More docs on: http://kssproject.org ● Remember: ● KSS is about not having to write Javascript! –