I've implemented a MoinMoin macro that parses, formats, and
delivers a reStructuredText file from the local file system.

Why you might care:

- You want to incorporate reST documents into your MoinMoin Wiki.

- You do not want to do copy and paste for each document.

- You love TTW (through the Web) editing, *but* you want to use
  your favorite editor for writing and modifying some of your
  documents.

- When you modify your reST documents on the file system, you want
  those changes automatically reflected in your Wiki.

I've attached the code below.

There is a bit of usage information in the __doc__ string at
the top of the file.

If anyone has suggestions about how I could improve it or could
make it more in the MoinMoin way, please let me know.

Installation and setup:

- Install it in data/plugin/macro.

- Define the variable IncludeExternalRstFileRoot in your config.

Questions:

- I defined IncludeExternalRstFileRoot in a local config file 
  wikiconfig_local.py.  Is that the correct place to put it?

- It works, but caching might make it more speedy.  Can anyone
  tell me where to look to learn how to add support for caching.  I
  found http://moinmo.in/MoinMoinIdeas/WikiApplicationServerPage,
  but that looks like futures sort of stuff.
  
====================================================
Code follows:
====================================================
# IncludeExternalRstFile.py

"""
IncludeExternalRstFile macro

Read (external) file; parse the contents as reST (reStructuredText);
and format it.

Installation:

- Put this file in data/plugin/macro.

- Add a variable whose name is specified by FileRootAttr to
  your MoinMoin config.

Usage -- Define a Web page whose only content is something
like the following::

    <<IncludeExternalRstFile(an_rst_file.txt)>>

where an_rst_file.txt is a file containing reStructuredText
located under the directory specified by FileRootAttr.

Author: Dave Kuhlman <http://www.rexx.com/~dkuhlman>
"""

from wikiconfig import Config
from MoinMoin.parser.text_rst import Parser
import string
import os


# This variable must be defined in the MoinMoin config object.
FileRootAttr = 'IncludeExternalRstFileRoot'


def execute(macro, args):
    if string.find(args, '..') != -1:
        result = '\*\*\* error.  Bad argument.  Should be file path/name.'
    elif not hasattr(Config, FileRootAttr):
        result = '\*\*\* error.  Must set config variable "%s".' % 
(FileRootAttr, )
    else:
        try:
            infilename = '%s%s%s' % (
                getattr(Config, FileRootAttr), os.sep, args,)
            infile = open(infilename, "r")
        except IOError:
            result = '\*\*\* error. Can not open file: %s' % (infilename, )
        else:   
            result = infile.read()
            infile.close()
    parser = Parser(result, macro.request)
    parser.format(macro.formatter)
    return ' '



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Moin-user mailing list
Moin-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/moin-user

Reply via email to