DylanMartin

Email: <dmartin AT NO SPAM FOR ME cpan DOT org>

Automated Content

Many peope on the mailing list have asked how to add content to a MoinMoin wiki without pasting it from a browser. This could mean adding data from an automatically generated CSV file to a table, or easily converting an existing document from one format to a page on your wiki, or many other possible applications. The important distinction is, people want to add content to a MoinMoin wiki without 1) using a web browser or 2) using a human.

Here is my technique for solving this problem. First, I format the content into something appropriate for the wiki, then I use the write-text script from the script market to install it in my wiki. This technique requires access to the server running the wiki. I'm sure there are ways to automatically push data to a remote MoinMoin wiki, but this isn't one of them.

My examples assume a unix/linux environment, but they should be easily adaptable to dos/windows. In fact they might just work, but I can't test them.

Formatting Content

I use two main techniques to format my content. The most obvious technique is to convert the content to wiki format. The second technique, is to generate a wiki formatted document with my content in an appropriate container.

Converting to Wiki Format

I use this technique for documents with meaningful formatting. For example, I write a lot of perl code and I document those scripts with POD, perl's simple documentation syntax. Luckily for me there, is pod2wiki. Use your search engine and maybe you can find a formatter for your content.

Generate Containig Wiki

MoinMoin can process several different syntaxes, but it won't detect the format without a little help. See HelpOnProcessingInstructions for details. The basic idea is, you put a line like #FORMAT html at the head of your file to tell MoinMoin to use the html parser. So, including an html file might be as easy as slapping #FORMAT html onto the top of the file, like so:

$ echo '#FORMAT html' > foo.txt 
$ cat content.html >> foo.txt

A very useful format that MoinMoin understands is the Comma Separated Value format, or CSV. MoinMoin will take CSV and format it into a table. This is powerful because most database and spreadsheets can dump CSV data, plus it's a really easy format to use yourself. A page with only a table might not be what you want, but luckily you can specify a parser for {{{ }}} blocks. E.G.

{{{#!CSV
foo,bar,baz
bleep,bloop,blop
kaping,kaplank,kaplunk
}}}

foo bar baz
bleep bloop blop
kaping kaplank kaplunk

This means you can make pages like this:

$ echo "== A Table Of Nonsense ==" > foo.txt
$ echo "{{{#!CSV" >> foo.txt
$ cat content.csv >> foo.txt
$ echo "}}}" >> foo.txt
$ echo "----" >> foo.txt
$ echo "CategoryNonsense" >> foo.txt

In the real world, you'd probably write up a wiki-formatted header and footer and then concatenate them with your CSV in between, rather than use a series of "echo" commands.

Hybrid

I use this a lot. I'll use pod2wiki to generate wiki, and then slap a Category on the end, like so:

$ pod2wiki --style moinmoin < content.pod > foo.wiki
$ echo "----" >> foo.wiki
$ echo "CategoryDocs CategoryManual" >> foo.wiki

Adding Content

I use a script write-text.py which is a hacked version of append-text.py.

In short, you download and install it, then run it like so:

$ write-text.py '~dmartin/wiki/' NewContent newcontent.wiki

For more details, the script contains plain text documentation, so download it and read it.

Putting it Together

Here's an example. I have a perl file, called woot.pl containing POD documentation and I want to put that documentation into my MoinMoin wiki at "Manuals/Woot".

$ pod2wiki --style moinmoin < woot.pl > woot.wiki
$ echo "----" >> woot.wiki
$ echo "CategoryDocs CategoryManual" >> woot.wiki
$ write-text.py '~dmartin/wiki/' Manuals/Woot woot.wiki

In reality, I have a script that does this to a number of files. And here it is: write-to-wiki.sh


CategoryHomepage

MoinMoin: DylanMartin (last edited 2008-12-15 19:06:10 by DylanMartin)