[Grok-dev] checked in: megrok.resourcelibrary

Martijn Faassen faassen at startifact.com
Wed Aug 6 12:34:46 EDT 2008


Hi there,

I just checked in a package called megrok.resourcelibrary. It wraps 
zc.resourcelibrary and all the real functionality is in that library, 
this just grokifies it. In essence megrok.resourcelibrary lets you set 
up your own new 'static' directories.

What you can do with this is the following:

import megrok.resourcelibrary

class MyResources(megrok.resourcelibrary.ResourceLibrary):
     megrok.resourcelibrary.directory('some_directory')

Your resources will then be published under:

http://localhost/@@/myresources

The library allows you to declare you actually need some resources in 
the head section of a HTML page whenever you use them:

class MyResources(megrok.resourcelibrary.ResourceLibrary):
    megrok.resourcelibrary.directory('some_directory')
    megrok.resourcelibrary.include('foo.js')
    megrok.resourcelibrary.include('bar.css')

This will make 'foo.js' and 'bar.css' whenever you use this resource 
library in a page. You can declare this requirement like this in a ZPT:

   <tal:block replace="resource_library: myresources" />

or like this in Python code that is used to display the page (such as in 
a widget that needs some javascript to be included):

   MyResources.need()

There are some other features, some of which are undertested, such as 
putting resources in a particular layer. There's also a feature that I 
did try to test but doesn't work yet, protecting resources behind 
permissions.

People are welcome to give this a spin, add more code/tests and write 
tutorials. :)

Regards,

Martijn



More information about the Grok-dev mailing list