Greetings all,
Now that NK4 is available for us all, we can now start converting. I figured I might as well give the kick-off with a simple
HOWTO. How to serve a javascript framework in NK4. I chose ExtJS to create the example, but I''ve tested it for other frameworks
as well.
Here we go ...
Step 1. Setting upMy modules are in the
projectmodules subdirectory which is on the same level in the directory structure as the
modules subdirectory. Underneath it I created my application directory :
urn.org.colruytit.servsupp.extjsStep 2. module.xmlSince this does basically all of the work I provide it verbatim. Please change according to your own naming conventions where
necessary :
<moduleversion="2.0"> <meta> <identity> <uri>urn:org:colruytit:servsupp:extjs</uri> <version>3.0.0</version> </identity> <info> <name>ExtJS</name> <description>ExtJS Javascript Library</description> </info> </meta> <system> <dynamic /> </system> <rootspaceuri="urn:org:colruytit:servsupp:extjs:application" name="ExtJS Javascript Library Public Space" public="true"> <import> <uri>urn:org:colruytit:servsupp:extjs:dynamic-import</uri> </import> <mapper> <config> <endpoint> <grammar> <!----> <!----> <groupname="path">res:/ExtJS/
<regex>ext-[0-9].[0-9].[0-9]/</regex> <regextype="anything" /> </group> </grammar> <request> <identifier>arg:path</identifier> </request> </endpoint> </config> <space> <fileset> <regex>res:/ExtJS/.*</regex> </fileset> </space> </mapper> </rootspace> <rootspaceuri="urn:org:colruytit:servsupp:extjs:test" name="ExtJS Javascript Library Test" public="true"> <import> <uri>urn:org:colruytit:servsupp:extjs:dynamic-import</uri> </import> <mapper> <config> <endpoint> <!----> <!----> <!----> <grammar>res:/ExtJS/test</grammar> <request> <identifier>res:/resources/test.html</identifier> </request> </endpoint> <endpoint> <grammar>res:/ExtJS/ <groupname="jsfile"> <regex>test_.*.js$</regex> </group> </grammar> <request> <identifier>res:/resources/[[arg:jsfile]]</identifier> </request> </endpoint> </config> <space> <fileset> <regex>res:/resources/.*</regex> </fileset> <import> <private /> <uri>urn:org:netkernel:lang:xrl</uri> </import> </space> </mapper> </rootspace> <rootspaceuri="urn:org:colruytit:servsupp:extjs:dynamic-import"> <fileset> <glob>etc/system/SimpleDynamicImportHook.xml</glob> </fileset> </rootspace> </module>
|
Three rootspaces. I''m not going to discuss the last one, check out the tutorials to find out about the SimpleDynamicImportHook.
The first rootspace defines the framework directories. You can address them as res:/ExtJS/ext-<version>/*. The second rootspace
defines a small test application that can be used as res:/ExtJS/test. It''s purpose is to test if the framework is up and
running.
Step 3. The restSo, here''s how my directory structure looks when everything is in place :
projectmodules
projectmodules/module.xml
projectmodules/etc/system/SimpleDynamicImportHook.xml
projectmodules/ExtJS
projectmodules/ExtJS/ext-3.0.0/ <-- dump the framework version 3.0.0 in here
projectmodules/resources
projectmodules/resources/test.html
projectmodules/resources/test_application.js
projectmodules/resources/test_initializer.js
You can imagine that if you want to have version 2.2.1 of ExtJS as well, you just create another directory
projectmodules/ExtJS/ext-2.2.1/
and dump the framework version 2.2.1 in there.
Step 4. Showing OffJust so you can reproduce everything, here''s the code of the relevant files :
test.html
<html> <head> <metahttp-equiv="Content-Type" content="text/html; charset=utf-8" /> <linkhref="/ExtJS/ext-3.0.0/resources/css/ext-all-notheme.css" rel="stylesheet" type="text/css" /> <linkhref="/ExtJS/ext-3.0.0/resources/css/xtheme-blue.css" rel="stylesheet" type="text/css" /> <scripttype="text/javascript" src="/ExtJS/ext-3.0.0/adapter/ext/ext-base.js"> <!----></script> <scripttype="text/javascript" src="/ExtJS/ext-3.0.0/ext-all-debug.js"> <!----></script> <scripttype="text/javascript" src="/ExtJS/ext-3.0.0/plugins/uxmedia.js"> <!----></script> <scripttype="text/javascript" src="/ExtJS/test_application.js"> <!----></script> <scripttype="text/javascript" src="/ExtJS/test_initializer.js"> <!----></script> </head> <body /> </html>
|
test_initializer.js
Ext.onReady(test.app.init, test.app);
|
test_application.js
/*--- Application ---*/
Ext.BLANK_IMAGE_URL = ''/ExtJS/ext-3.0.0/resources/images/default/s.gif''; Ext.namespace(''test'');
test.app = function() { // private space
// public space return { init: function() { Ext.Msg.alert(''ExtJS 3.0.0'', ''Framework has been installed correctly''); } };
}();
|
Step 5. UsageIf you now want to use the ExtJS framework in another application, you import it in the relevant space, just like this :
<space> <import> <private /> <uri>urn:org:colruytit:servsupp:extjs</uri> </import> </space>
|
And you can then use the exact same specifications as in the test.html example above.
Enjoy,
Tom
P.S. Serving your own Javascript Framework is often considered ''not done'' and ''only for testing purposes''. I just want
to
remark that NetKernel caches extremely well ... and further rest my case.
[/b]