Hi, all! i think this is the coolest stupid fossil trick yet...
Those who know a bit about requirejs (http://requirejs.org/) might find it interesting to know that we can now use a similar mechanism to load arbitrary resources from a fossil database. A short demo: // Import our requirejs workalike: const R = s2.import('toys/require.s2'); // Some shared state for the various plugins we'll install... const fslState = { f: Fossil.Context.new().openCheckout() }; /** require() plugin: wiki!PageName */ R.configs.wiki = { isVirtual: true, load: function(name,opt){ affirm F.db && F.db.repo; return F.loadManifest(F.db.selectValue(sql.applyFormat(name))); }.importSymbols({ F: fslState.f, sql: <<<___ SELECT x.rid FROM tag t, tagxref x WHERE x.tagid=t.tagid AND t.tagname='wiki-%1$q' ORDER BY mtime DESC LIMIT 1 ___ }) }; /** require() plugin: blob!SYMBOLIC_NAME|rid:RID */ R.configs.blob = { isVirtual: true, load: function(sym,opt){ return F.loadBlob(sym) }.importSymbols({F: fslState.f}) }; // Now use it like requirejs: R(// Resources to load: ['wiki!home', 'text!require-demo.s2', 'blob!rid:1'], // Callback to pass the resources to: function(page, thisScript, rid1){ print(__FLC, typename page, typename thisScript, typename rid1); print("Wiki page", page.L,"is", page.W.lengthBytes(),"bytes long."); print("This script is",thisScript.lengthBytes(),"bytes long."); print("RID 1 is",rid1.length(),"bytes long."); }); That all results in something like: [stephan@host:~/cvs/fossil/libfossil/s2]$ ./s2sh require-demo.s2 require-demo.s2:43:12 object string buffer Wiki page home is 8640 bytes long. This script is 1225 bytes long. RID 1 is 168 bytes long. i expect to be making heavy use of this in the new/ongoing CGI layer. Happy Hacking! -- ----- stephan beal http://wanderinghorse.net/home/stephan/ http://gplus.to/sgbeal "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
_______________________________________________ fossil-users mailing list fossil-users@lists.fossil-scm.org http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users