Peer Pressure

Stuff to look at about looking at stuff. From Chris Dent. What?

Archive

Aug
18th
Mon
permalink

And the Leaders said, "Let Them eat Cake"

I have tendency to want to tie together threads that don’t appear to have much to do with one another. A few days ago JP made a posting …musing about leadership… in which he suggested:

Leadership is about taking the risk of managing meaning

Perhaps true in hierarchies, but I prefer to think that a more critical action of leadership is feedback. So, to me, it’s not about accepting risk, it’s about helping to shape meaning, and the process of shaping meaning leads to understandings which lead to goals. Leadership is spread around among all the communicating participants. Leadership is something anyone, in the right environment, can do.

What this can mean is that sometimes the person who gives the most feedback in any situation can exhibit significant power. In conversation with Fred (one of the Osmosoft guys) I suggested that he, by asking the most questions and making the most comments about TiddlyWeb (i.e. providing feedback), was leading the direction of TiddlyWeb.

So asked him what he wanted next. And he wanted fudge cake. So I set about making that possible. Cake from TiddlyWeb.

In Web of TiddlyWebs with TiddlyWebWeb I gave an intro to the StorageInterface system in TiddlyWeb. It makes it relatively easy to provide different persistence engines.

There is a similar mechanism for handling multiple content-types for incoming and outgoing representations of resources. There is a SerializationInterface. Implementors of that interface are responsible for taking the internal object representation of some entity (Recipe, Bag, Tiddler) and turning it into a string that represents a particular type (HTML, JSON, a raw text format, Atom, etc). They also take a string of a particular type and turn it (if possible) into an object representation. The relevant methods are:

recipe_as(self, recipe):
as_recipe(self, recipe, input_string):
bag_as(self, bag):
as_bag(self, bag, input_string):
tiddler_as(self, tiddler):
as_tiddler(self, tiddler, input_string):
list_tiddlers(self, bag):
list_recipes(self, recipes):
list_bags(self, bags):

The default TiddlyWeb installation comes with four serializations: html, json, text and wiki. What serializations are available is controlled by entries in tiddlyweb.config.

Which serialization is used is determined by a simplified form of content negotation, handled by code in tiddlyweb.web.negotiate. For a GET request we look at the Accept header (or an extension on the URL) and eventually use a *_as or list_* method on the serialization to turn an object or objects into the requested format representation. For a PUT or POST request we look at the Content-Type header and eventually use a as_* to turn the provided representation into an object.

Calling code does not directly call recipe_as or similar. Instead it asks the Serializer to do a to_string() or from_string() on a provided object and optional string. A Serialization doesn’t have to provide support for transforming all objects, just stuff it cares about.

All these things make it quite easy to add support for other serializations. The first optional one I made added Atom support as a content oriented web service without Atom is very sad making. There’s a README beyond that link which explains how to add Atom to your own TiddlyWeb installation.

So back to Fred. Fred wants TiddlyWeb to produce cake. In my mind a TiddlyWeb that produces cake is producing cake with Tiddler information in/on/around/with the cake. To keep things simple I decided all we need to do to make TiddlyCake was to write tiddler content onto a picture of a cake and send it out. This means that we only need to write a tiddler_as method and choose a content type for it. cake/x-fudge is what we’ll use.

First we customize the tiddlyweb.config by making our own tiddlywebconfig.py:

config = {
        'extension_types': {
            'cake': 'cake/x-fudge',
            },
        'serializers': {
            'cake/x-fudge': ['cake.cake', 'image/jpeg'],
            },
        }

This says that when we put .cake on the end of a resource think of that as an Accept or Content-Type header being set to cake/x-fudge. When we have that content-type for requests, use the Serializer in the module cake.cake and output the results as image/jpeg.

Now we need to write cake/cake.py. We need a class called Serializer that inherits from SerializationInterface and implements tiddler_as().

In tiddler_as we gather up tiddler.text and do a bit of math to write it over the top of a picture of cake with some really lame line wrapping and then return a string in JPEG form.

Python has the very useful Python Imaging Library that makes most of the image manipulation easy (easy if you are willing to accept ugly).

I searched Creative Commons images on Flickr and found a nice looking cake from Just American Desserts in Spokane.

When you gather all the necessary pieces you can start up a server that will provide TiddlerCake. You give a URL like this:

http://0.0.0.0:8080/recipes/TiddlyWeb/tiddlers/TiddlyWeb.cake

and the browser will show something a little bit like this:

TiddlerCake

Sadly, I wanted to make this bit of silliness show up on the live TiddlyWeb server at peermore.com but it does not have the necessary graphic library support on it right now, and updating it is a task I don’t want to do today. So images of images will have to do for now. You can, of course, try it out for yourself on your own TiddlyWeb server.

Comments (View)
blog comments powered by Disqus