Monday, June 22, 2009

GSoC09: Statistics module 3rd weekly report: up and running!

This week has been mainly focused on solving hopefully with best practices some tasks needed for the Javascript side and on setting up proper syncronization with Daniel's work.

First of all I got to know JSMock and how to use mocks, but I thought to have it integrated (if needed) later in the future. Looking around in the web I also found a great library called Functional Javascript, that supports functional constructs (lambdas and so on): that was interesting because IE doesn't support Javascript 1.7 statements, so it might be a way to workaround the limitation. Saved for later, too :)

On Tuesday we had a meeting with Daniel, where we decided to go for daily meetings, and, afterwards, during conference call I was asked to post meeting agenda and notes in the wiki and then mail the dev list about it every day.

Then I had to deal with a great issue: I was going to write a simple (at least I hoped so) test to check if my function that loads Google API dynamically worked properly. I've lost nearly one day on trying to do that properly with JSUnit, which seemed not to like async testing. I've found that someone had a sort of workaround but didn't publish the modified JSUnit code.

So I gave up for the moment, and, as we were talking about it with the mentors by mail, I've put some effort on retrieving parameters from a script tag instead of having them injected by Django templates right into Javascript variables. That meant separate completely those templates from the Javascript that lives inside that template. I took the Dojo way as an example, and it was very simple, using jQuery selectors (especially with the help of this awesome article) to get variables from attributes inside the script tag and add it, for example, in the melange package configuration, with very concise code:

$m.config = {};

(function () {
var configuration = jQuery("script[melangeConfig][src$='melange.js']").attr("melangeConfig");
if (configuration) {
var configuration_object = eval("({ "+configuration+" })");
jQuery.extend($m.config,configuration_object);
}
}());

But there was a problem: eval is evil! :)
So i found some guides to parse JSON without using eval (1,2,3), and I think I'll go for something like that, because json2 library doesn't like JSON strings like

{key: "value"}

but wants

{"key": "value"}

which is not something gviz gives us as an output. So we need to hack gviz or json2, or do something different like said before. So I've postponed the problem :)

On Thursday I worked on creating a _baseTemplate more abstract object to handle scripts outside Django templates with context taken from attributes in the script tag, and pushed an example in the repository. Then I made a simple example of content transclusion, which will take care, when all will be in place, to understand "melange" tags in HTML Django templates and substitute them, for example, with a graph.

After that, I returned working on the former JSUnit with Ajax issue, and then I found an article about YUITest, which I liked much and integrated in the repository and made it work again with JSCoverage. I had an issue on writing a test with it, because, when calling a wait() to make YUITest waiting for an ajax callback, the function inside the callback had a different scope so I couldn't send a resume(). But all went fine as soon as I discovered this great trick to keep context in ajax callbacks. And so here it is, working :)


The same day I had the idea to set up an issue tracker for our bitbucket statistic branch repository to better sync tasks with Daniel.

Saturday was more or less a "free day", even if I did some work, studying Selenium and integrating Selenium RC, with an example test using Python, generated from Selenium IDE Firefox extension.
Then I worked to integrate a new version of jQuery spin in the main Melange repository, and then...

My first Melange push!
(without dots :P)


Then I've explored libraries for Browser Side Templates, and I'm trying to find a winner between JBST and Pure. In that way, not only we will separate Javascript code from Django templates, but also we will separate Javascript logic from Javascript templates!
Last but not least, I've given my first code review for Daniel Diniz and James Levy JS libraries integration for Survey module in Rietveld :) Great work men!

No comments:

Post a Comment