Michael Kerrin

Web, Python, JavaScript and related technologies

Archive for April 2011

Open Data Hack Day, Galway – Saturday May 14th

leave a comment »

An other Open Data Hack Day will be held on Saturday the 14th May from 10am to 5pm in the 091labs in Galway city center.

The goal of this Hack Day is to build on the work that gone into the previous hack days and to build on the opendata.ie website to promote Open Data in Ireland. But if anyone wants to come along with their own idea for a project we will find other interested parties to push the project forward.

To give people an idea of what happens on the day the following is an incomplete list of projects that people have worked on at previous hack days. Each project involved finding and collecting data, and in most cases writing a computer application to visualize and make sense of the data:

But for those that aren’t of a technical nature but are interested in Open Data, please come along during the day to see what is happening and to share your ideas of what would be a really cool application that you are interested in.

We will be around all day so everyone is encouraged to come along for the whole day or only for as long as they can make it.

Written by mkerrin

2011, April 29 at 7:25 pm

Posted in Open Data

pwt.jinja2js 0.6.0

with 2 comments

I have just uploaded a version 0.6.0 of pwt.jinja2js. This adds support for default values for macros arguments. So now you can do this:

{% macro defaultparam1(name = "World") -%}
Hello {{ name }}!
{%- endmacro %}

 

And you can call this like so to produce the desired output:

defaultparam1({}) -> "Hello World"
defaultparam({name: 'Michael'}) -> "Hello Michael"

 

Written by mkerrin

2011, April 5 at 10:33 am

pwt.recipe.closurebuilder 0.9.3

leave a comment »

Released new version of pwt.recipe.closurebuilder to PyPI. This just contains small updates to the closure libraries from Google.

Written by mkerrin

2011, April 4 at 10:30 am

pwt.jinja2js documentation

leave a comment »

The documentation for pwt.jinja2js has now been uploaded to PyPI. See them here.

Written by mkerrin

2011, April 4 at 9:45 am

pwt.jinja2js

leave a comment »

I have just released pwt.jinja2js This is my compiler for Jinja2 templates that compiles to Java Script. If anyone noticed I renamed the project from pwt.jscompiler that I previously announced on this blog. But pwt.jinja2js is now released to PyPI which should make it easier to use and fixes the name in stone now.

I started this project so that I could easily use templates in my Java Script code. Most other Java Script templates require web developers to include the template they want to render inside the HTML returned from the server. This is annoying as you have to remember to include both Java Script and your HTML snippet in the response, increasing the load of the HTML page resulting in slower website. I found and used Closure templates for a while. This does what pwt.jinja2js does and inspired me to work on this project. But closure templates is a Java project and the only way to use it in a Python project is via the command line which is annoying.

pwt.jinja2js works by compiling any macros found inside your Jinja2 template into a Java Script function that you can call just like any other Java Script function and it will return a rendered string of your template and data. It is then up to you to do what you want with this string. In order to know what function to call pwt.jinja2js uses the name of the macro as the name of the Java Script function but also includes a special namespace node that you can include in the top of the Jinja2 template so that all the Java Script functions are called after their macro name prefixed with the namespace supplied. So that you can avoid namespace conflicts.

pwt.jinja2js can be invoked numerous ways, the two main ways been on the command line by calling the jinja2js script which you get for free after running easy_install pw.jinja2js, which just writes the output of templates disc which can then be served along with all your other static files. The other way is to configure a WSGI server to run the pwt.jinja2.wsgi.Resource application. This will find all your templates in the same way as Jinja2 does and will render them on the fly and return them with the correct mine type so your browser will treat it as Java Script. For performance considerations you should compress your Java Script including the generated Java Script from your templates with a tool like Closure compiler, YUI Compressor, or any other similar tools. I personally use pwt.recipe.closurebuilder to integrate the closure compiler with my zc.buildout build to get the best result.

 

Written by mkerrin

2011, April 1 at 3:55 pm