Friday, June 5, 2009

MyUltimateTaskForTheSummer

So I need to find a way to bring FitNesse into Limelight. This will have to be done by taking all of the rendered information of a FitNesse page, wrapping it up in a nice bundle, sending it to Limelight, and then finally interpreting that information to reconstruct the page.

FitNesse pages are made up of a large string of WikiText (and some xml for some of the page properties, like if its a test page or a suite). When a page is rendered to be displayed, all of that WikiText is broken down into a massive tree structure of WikiWidgets. The WikiWidgets are objects that represent a wide range of functions or qualities. There is a WikiWidget for making text bold, for putting the date on the page, for making comments, or for inserting images. Each widget has a pattern of WikiText that it looks for, to know if it should be that sort of Widget. The widgets also have a parent widget and child widgets (with the ultimate parent being the WikiWidget Root). The bold WikiWidget is referenced with a ''' text to be made bold '''. When the page is rendered, the chunk of text with the ''' some text ''' would be turned into a bold widget, and the text inside those quotes (some text) would be made into a text widget, and as a child of the bold widget.

The process of breaking down the text into widgets is quite interesting. When it begins, a WidgetData object is created, and is loaded with every WikiWidget class (except literals, which is a different story). Then a builder object is created, which contains the WidgetData as well as the WikiText from the page to be rendered. Next, it will add a child widget to the WikiWidget Root by looping through every widget in the WidgetData and trying to find the first match of that widget's pattern to the WikiText. If it finds a match, it saves where the match is in the WikiText , and then keeps checking the other widget patterns to see if they come any earlier in the text. Once it finds the first match, it creates a WikiWidget object of that match, saves that object as a child of its parent (for the first match the parent is the WikiWidget Root), searches the text inside that widget for more matches (to become children of the just created widget), and searches the remainder of the WikiText for the next first match. This cycles recurssively until the entirety of the WikiText has been turned into a massive tree of WikiWidgets.

This tree of WikiWidgets would then be parsed into html and put on the page, but for my task I want to stop right here. I would then take this tree and probably turn it into a JSON object (a fairly simple data structure) and then ship it over to Limelight. Finally I would have to create some sort of translator which will turn this tree of widgets, in the JSON object, into Limelight props to be displayed.

This should be fun.

1 comment: