Extending EvalLibrary over the wikiPages

4 views
Skip to first unread message

Carles F.

unread,
Jul 17, 2009, 11:25:06 AM7/17/09
to wikidpad-devel
Hi All!

I am trying to place wiki-specific python functions into the wiki
Pages. This functions usually are placed in EvalLibrary.py inside the
user_extensions folder; but this this method is not portable and
EvalLibrary ends full of rarely used functions.

So my idea was implementing this:

<%
import StatisticsModule
StatisticsModule.compute()
%>

where the WikiPage StatisticsModule actually contains the code for
"compute".

So far I implemented this:

<%
import sys
import os
import imp

class WikiImporter(object):
pwiki = None
content = None
def find_module(self, fullname, path=None):
if self.pwiki.wikiData.isDefinedWikiWord(fullname):
return self
return None
def load_module(self, fullname):
if fullname in sys.modules:
return sys.modules[fullname]
mod = imp.new_module(fullname)
mod.__loader__ = self
sys.modules[fullname] = mod
mod.__file__ = "WikiModule "+fullname
code = self.pwiki.wikiData.getContent(fullname)
exec code in mod.__dict__
return mod

importer = WikiImporter()
importer.pwiki = pwiki
sys.meta_path = [importer]
%>

After executing this inside wikidpad The previous example works.

Now time for the questions:
I don't know how to execute this automatically before evaluating any
WikiPage.
Is it possible to implement this as a plugin?
If not, may be this could be integrate natively on future versions of
Wikidpad.

Thanks a lot for this incredible program!
Reply all
Reply to author
Forward
0 new messages