The code I posted before should do that. The inject call does the same object initialization as the javascript you originally posted.
To be clear, the old haml generated client-side code that looked like this:
<script>
var departments = new Object();
departments[9] = new Object();
departments[67] = new Object();
...
</script>
After this code was run, the resultant `departments` object would look like this:
departments = { 9: {}, 67: {} };
The inject code I provided does the same thing except it bypasses generation of the client-side javascript and instead generates the resultant object as a JavaScript object literal. The new code would look like this:
<script>
var departments = { 9: {}, 67: {} };
...
</script>