yesodweb/hamlet — Issue #46: Changing widgetFile for Coffee
Author: scan
Created: 2012-02-27 09:39:57+00:00
State: open

I don't really like Javascript as a language, and I've grown used to working with [Coffeescript](http://jashkenas.github.com/coffee-script/). So I am glad to hear that Yesod allows it in place of Julius.

In the scaffold, there is a pre-defined `widgetFile` function. I like the idea, if the templates have the same name, they get detected together. But `.coffee` files are excluded, so I tried to make my own:

```
widgetFile :: String -> Q Exp
#if DEVELOPMENT
widgetFile = widgetFileReload
#else
widgetFile = widgetFileNoReload
#endif

widgetFileNoReload :: FilePath -> Q Exp
widgetFileNoReload x = do
let h = whenExists x "hamlet" whamletFile
let c = whenExists x "coffee" coffeeFile
let l = whenExists x "lucius" luciusFile
[|$h >> addJulius $c >> addLucius $l|]

widgetFileReload :: FilePath -> Q Exp
widgetFileReload x = do
let h = whenExists x "hamlet" whamletFile
let c = whenExists x "coffee" coffeeFileReload
let l = whenExists x "lucius" luciusFileReload
[|$h >> addJulius $c >> addLucius $l|]
```
(cf. [this gist](https://gist.github.com/1922803))

I have the files `default-wrapper.hamlet`, `default-wrapper.lucius` and `default-wrapper.coffee` in my `templates/` folder, but when I start the development server, the generated `.js` file is empty.

What can I do?