bengillies.net

a blog by Ben Gillies

Bookmarking and TiddlySpace

For a while now, Osmosoft has been working on a project called TiddlySpace, which is a collaborative environment built on top of TiddlyWeb and TiddlyWebWiki. Before we go any further, you should go and try it out now as it's really cool. I'll just wait here till you get back...













One of the more interesting aspects of TiddlySpace is the way you can add new functionality to your space by including other spaces within it. With that in mind, I've created a new space at http://bookmarks.tiddlyspace.com that lets you bookmark other websites (in a delicious sort of way) and store information about them inside your own space. The benefit of this of course, is that all your sites get stored inside a TiddlyWiki, where you can operate on them further, link to them, tag them (or even transclude parts of them if you like) instead of locking them away inside a service that you don't control (you can of course download your TiddlyWiki and take it with you).

This is achieved through a bookmarklet that loads up your space inside an iframe directly on the website of your choosing, and then uses some funky HTML5 cross document messaging (with postMessage) to send over some important details (url, description, title, etc).

The really cool thing about this is that TiddlySpace means you can get it straight away: all you need to do is include the bookmarksplugin space inside your own, and then call the <<bookmarklet>> macro somewhere to generate your bookmarklet.

All this of course means that I can keep my post really short, and let the space itself do the talking.


If you're interested in the source code, you can find it in my contributors directory at http://svn.tiddlywiki.org/Trunk/contributors/BenGillies/TiddlyWeb/Plugins/Bookmarklet
(NB - I should point out here that this will work in any default TiddlyWeb install, though not in standalone TiddlyWiki).

Binary Tiddlers and You

I want to take this opportunity to talk about the current state of binary tiddlers within TiddlyWeb, how you can use them, and to introduce some new stuff that I've been working on.

There are currently a few ways of dealing with binary tiddlers in TiddlyWeb/TiddlyWiki. If we first take a look at TiddlyWiki, we can see that binary tiddlers can be loaded in the form of base64 encoded data: URIs (see TiddlyPictoWiki for a good example of this). Indeed, the upcoming TiddlyWiki5 fully supports all of this natively (among other things).

Of course TiddlyWeb also supports binary tiddlers (setting the tiddler.type attribute determines this), with the difficulty being how to get the data into the store in the first place. For this, natively, your only real option is is to PUT it using curl and the RESTful API (more on another native option below). This works for the most part, though I wouldn't call it particularly user friendly. There is also my form plugin (see POSTing to TiddlyWeb), which I'll go into greater detail about later on.

Finally, you can use twanager, and a small plugin for importing binary content that I wrote called tiddlywebplugins.bimport. I should note first that I wrote this a few months ago and some of the functionality has since been integrated with TiddlyWeb core (specifically, the twanager command twimport) so most of this also applies to that command. The main benefit of using bimport however, is that you can guarantee that the file you're importing will always be stored as binary (javascript files or TiddlyWiki files might be a good use case). So, to install:
sudo pip install -U tiddlywebplugins.bimport

and then add 'tiddlywebplugins.bimport' to you tiddlywebconfig.py file. You can then import binary files with:
twanager bimport <bag_name> <tiddler_name> <URI>

where the URI can be anything (eg - a file: URI). Alternatively, the twimport command can be run as:
twanager twimport <bag_name> <URI>

with anything not recognised as a valid type for TiddlyWeb to use being stored as binary content. What this means is that an image will import fine, but a Javascript file, will get tagged "systemConfig" and lose its mime type. If you don't want this to happen, you should use bimport. Otherwise, twimport is probably easier (as you don't have to install an extra plugin).

Uploading via the Web


A while ago I wrote a blog entry entitled POSTing to TiddlyWeb which mentioned that you could use it to upload files to a TiddlyWeb bag or recipe. I've recently updated this to support tagging binary tiddlers, and have released it to pypi. You can install it by running:
sudo pip install -U tiddlywebplugins.form

from a command line. If you were using the old version, you should probably update as the new version supports better handling of tiddler titles, in that you can now override the title of a binary file being uploaded, and the aforementioned tagging of binary content (so that you can tag for example, an image, or a pdf).

I've also created a TiddlyWiki plugin to use with it. You can find it in my SVN repository at http://svn.tiddlywiki.org/Trunk/contributors/BenGillies/TiddlyWeb/Plugins/Binary/tiddlers/BinaryUploadPlugin.js, and can import it into your TiddlyWeb store with:
twanager twimport <bag_name> http://svn.tiddlywiki.org/Trunk/contributors/BenGillies/TiddlyWeb/Plugins/Binary/tiddlers/split.recipe

To use it, simply add:
<<binaryUpload bag:bag_name edit:tags edit:title tags:default_tags>>

where bag:bag_name is optional and allows you to specify a different bag to the one you're currently in, edit:tags and edit:title are also optional, and allow you to add a title or tags, and tags:default_tags allows you to set some default tags if you have the edit:tags option on.

I believe that binary tiddlers now have a fairly good story in TiddlyWeb, and am quite looking forward to seeing potential applications that surface.

CGI and TiddlyWeb 1.0

Now that TiddlyWeb has hit the 1.0 milestone, I figured it was about time to blog the latest and greatest way to get it running using cgi. I've simplified the instructions somewhat so that, apart from editing a few config files, and changing the paths to your specific paths, you should be able to copy/paste most of it.

Just one final note before we get going, these instructions are for Linux/*nix systems only, so they should work on most versions of Linux, Mac OSX, BSD, etc. If you are using a Windows system, you probably want the Installing TiddlyWeb on Windows instructions.

Installation


Download virtualenv-x.x.x.tar.gz (replace x.x.x with the latest version number) from http://pypi.python.org/pypi/virtualenv and put it into your home directory. Then, from you home directory, do the following:
tar -xvzf virtualenv-x.x.x.tar.gz
cp virtualenv-x.x.x/virtualenv.py ~
python virtualenv.py ~
source bin/activate
easy_install -U pip
pip install -U virtualenv
pip install -U tiddlywebwiki
twinstance <instance_name>
mkdir .python-eggs
mkdir twconfig
mv <instance_name>/tiddlywebconfig.py twconfig/tiddlywebconfig.py
touch twconfig/tiddlyweb.log
wget http://github.com/tiddlyweb/tiddlyweb/raw/master/index.cgi
chmod +x index.cgi
mv index.cgi public_html/cgi-bin/


Configuration


Nano is a simple text editor that you can use to make some changes to index.cgi. Feel free to use whatever you like, though bear in mind that nano is probably the easiest to start off with.
cd public_html/cgi-bin
nano index.cgi

So, change the line at the top to point to your local version of python (type in "which python" to find this out). It should end up similar to the following:
#!/home/bengillies/bin/python

Also, change the lines that look like:
tiddlywebconfig_dir = '/tmp'

os.environ['PYTHON_EGG_CACHE'] = '/tmp'

To something like (replacing the start with your home directory:
tiddlywebconfig_dir = '/home/bengillies/twconfig/'

os.environ['PYTHON_EGG_CACHE'] = '/home/bengillies/.python-eggs'

You can save with ctrl-o, and then exit with ctrl-x (assuming you're using nano). Now, we need to alter the tiddlywebconfig.py file to finish things off:
cd ~/twconfig
nano tiddlywebconfig.py

Go down to the last but one line (the one before the closing }), and start a new line after it. Enter information so the the file looks like this:
# A basic configuration.
# Run "pydoc tiddlyweb.config" for details on configuration items.

config = {
    'system_plugins': ['tiddlywebwiki'],
    'secret': 'f433fbfcf1871ea99ddb75e97ff5512f5513414d', #this string will be different in your file. Just leave it as it is.
    'twanager_plugins': ['tiddlywebwiki'],
    'server_store': ['text', {'store_root': '/home/bengillies/<instance_name>/store'}],
    'server_prefix': '/cgi-bin/index.cgi',
    'server_host': {
        'scheme': 'http',
        'host': '<your domain name here>',
        'port': '80'
    },
}


That's it. You should now be able to point your web browser to http://your_domain.com/cgi-bin/index.cgi/recipes/default/tiddlers.wiki and start editing.

For more instructions on how to customise your tiddlyweb installation, it's probably best to look directly on the TiddlyWeb site at http://tiddlyweb.com