The Golf Web Application Server home roadmap1.0 help rss

JavaScript Preprocessor Hooks

22 Feb 2010 - Micha Niskin

You can use the familiar #! semantic to preprocess the JavaScript in your Golf apps. In any JavaScript file or component <script type="text/golf"> tag, simply prepend a #! line with the preprocessor you wish to have run on your JavaScript.


Here is a plugin/library using coffee-script (say plugins/mylib.js):

#!coffee -p
exports.isNumber: (x) -> typeof x == "number" || x instanceof Number
exports.sayhi: -> alert("hello there!")

And here is a component using coffee-script for its constructor:

  <style type="text/golf"></style>
<script type="text/golf">#!coffee -np
(a,b) ->
  @a: a
  @b: b
  @y: (x) -> @a*x + @b

  $("form").submit((event) =>
    x: $("input[name='x_in']").val()
<div>y(<span class="xval"/>) = <span class="yval"/></div>
    x: <input type="text" name="x_in" value="0"/>
    <input type="submit"/>

Note that coffee-script uses indentation to identify blocks, so the <script> tag is not indented.

blog comments powered by Disqus
Fork me on GitHub