From 7ba97c61ad91c0fe21565b3b81752ec07da4668f Mon Sep 17 00:00:00 2001 From: David Huynh Date: Tue, 15 Jun 2010 23:21:08 +0000 Subject: [PATCH] More work on the sample extension git-svn-id: http://google-refine.googlecode.com/svn/trunk@974 7d457c2a-affb-35e4-300a-418c747d4874 --- .../module/MOD-INF/controller.js | 46 +++++++++++++++++++ .../module/MOD-INF/module.properties | 3 ++ extensions/sample-extension/module/index.vt | 21 +++++++++ extensions/sample-extension/module/macros.vm | 14 ++++++ .../module/scripts/project-injection.js | 3 ++ .../module/styles/project-injection.less | 5 ++ main/webapp/WEB-INF/butterfly.properties | 3 ++ main/webapp/WEB-INF/modules.properties | 5 ++ 8 files changed, 100 insertions(+) create mode 100644 extensions/sample-extension/module/MOD-INF/controller.js create mode 100644 extensions/sample-extension/module/MOD-INF/module.properties create mode 100644 extensions/sample-extension/module/index.vt create mode 100644 extensions/sample-extension/module/macros.vm create mode 100644 extensions/sample-extension/module/scripts/project-injection.js create mode 100644 extensions/sample-extension/module/styles/project-injection.less diff --git a/extensions/sample-extension/module/MOD-INF/controller.js b/extensions/sample-extension/module/MOD-INF/controller.js new file mode 100644 index 000000000..5a3b375e3 --- /dev/null +++ b/extensions/sample-extension/module/MOD-INF/controller.js @@ -0,0 +1,46 @@ +var html = "text/html"; +var encoding = "UTF-8"; +var ClientSideResourceManager = Packages.com.metaweb.gridworks.ClientSideResourceManager; + +/* + * Function invoked to initialize the extension. + */ +/* +function init() { + # Packages.java.lang.System.err.println("Initializing sample extension"); + # Packages.java.lang.System.err.println(module.getMountPoint()); + + // Script files to inject into /project page + ClientSideResourceManager.addPaths( + "project/scripts", + module, + [ + "scripts/project-injection.js" + ] + ); + + // Style files to inject into /project page + ClientSideResourceManager.addPaths( + "project/styles", + module, + [ + "styles/project-injection.less" + ] + ); +} +*/ + +/* + * Function invoked to handle each request in a custom way. + */ +function process(path, request, response) { + // Analyze path and handle this request yourself. + + if (path == "/" || path == "") { + send(request, response, "index.vt", context); + } +} + +function send(request, response, template, context) { + butterfly.sendTextFromTemplate(request, response, context, template, encoding, html); +} diff --git a/extensions/sample-extension/module/MOD-INF/module.properties b/extensions/sample-extension/module/MOD-INF/module.properties new file mode 100644 index 000000000..e442fa6e2 --- /dev/null +++ b/extensions/sample-extension/module/MOD-INF/module.properties @@ -0,0 +1,3 @@ +description = Gridworks Sample Extension + +templating.macros = macros.vm diff --git a/extensions/sample-extension/module/index.vt b/extensions/sample-extension/module/index.vt new file mode 100644 index 000000000..f28cae582 --- /dev/null +++ b/extensions/sample-extension/module/index.vt @@ -0,0 +1,21 @@ +#* + * Access this page at the URL /extensions/sample/ + *# + + + Sample Extension + + +

Sample Extension

+ +

If an extension needs its own page, then this is such an example. + However, mostly, extensions only need to inject their own scripts + and styles into the /project page. +

+ +

Here is a sample list using a veloci-macro:

+ + #set( $greatlakes = ["Superior","Michigan","Huron","Erie","Ontario"] ) + #makeAList( $greatlakes ) + + \ No newline at end of file diff --git a/extensions/sample-extension/module/macros.vm b/extensions/sample-extension/module/macros.vm new file mode 100644 index 000000000..18a83bfce --- /dev/null +++ b/extensions/sample-extension/module/macros.vm @@ -0,0 +1,14 @@ +#* + This file contains common velocity macros used in all .vt files. + For Velocity documentation, see: + + http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html +*# + +#macro( makeAList $list ) + +#end \ No newline at end of file diff --git a/extensions/sample-extension/module/scripts/project-injection.js b/extensions/sample-extension/module/scripts/project-injection.js new file mode 100644 index 000000000..157499d9b --- /dev/null +++ b/extensions/sample-extension/module/scripts/project-injection.js @@ -0,0 +1,3 @@ +// This file is added to the /project page + +var SampleExtension = {}; \ No newline at end of file diff --git a/extensions/sample-extension/module/styles/project-injection.less b/extensions/sample-extension/module/styles/project-injection.less new file mode 100644 index 000000000..3e4ad2908 --- /dev/null +++ b/extensions/sample-extension/module/styles/project-injection.less @@ -0,0 +1,5 @@ +// LESS styles +// For documentation, see http://lesscss.org/ + +@color: blue; + diff --git a/main/webapp/WEB-INF/butterfly.properties b/main/webapp/WEB-INF/butterfly.properties index c2c9cf60e..7b8ae069d 100644 --- a/main/webapp/WEB-INF/butterfly.properties +++ b/main/webapp/WEB-INF/butterfly.properties @@ -21,6 +21,9 @@ butterfly.url = / butterfly.modules.path = modules butterfly.modules.path = ../../extensions/ + # Add more paths here if your extensions live elsewhere. + # Relative paths are relative to gridworks/main/webapp/ + butterfly.modules.wirings = WEB-INF/modules.properties # ---------- Clustering ---- diff --git a/main/webapp/WEB-INF/modules.properties b/main/webapp/WEB-INF/modules.properties index 1b05a14bb..54e21e2d6 100644 --- a/main/webapp/WEB-INF/modules.properties +++ b/main/webapp/WEB-INF/modules.properties @@ -4,4 +4,9 @@ core = / +# Sample extension's wirings +# client-side resources of this module will be accessible under this URL path +sample-extension = /extensions/sample/ + jython = /extensions/jython/ +