Jason Blade
Jason Blade

Reputation: 383

How do I make use of CoffeeKup when writing jQuery

I am quite new to web development and have started programming with node.js & express and using the coffeekup view engine. My problem is the following:

If I use the CoffeeKup view engine can I somehow insert coffeeKup code as a parameter to the jquery append method?!? So for example instead of writing $('body').append('<p>') I can write $('body').append('p') or $('body').append(p) or something similar. I want the compiler to somehow preprocess my coffee code...

Upvotes: 0

Views: 344

Answers (1)

Rudolf Meijering
Rudolf Meijering

Reputation: 1587

There's examples of what you are trying to achieve in the examples/browser directory of the coffeekup source. Maurice calls your specific flavour of client-side (browser) coffeekup creme.

The gist of it is that you include coffeekup and coffeescript libraries and write your template in a js file or in a script element. The following is from the creme/index.html file.

<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>
<script src="coffeekup.js"></script>

<script type="text/coffeescript">
  stooges = ['moe', 'larry', 'curly']

  $().ready ->
    codey = ->
      h2 'Template as a function'

      ul ->
        for guy in @stooges
          li guy

    $('body').append CoffeeKup.render(codey, stooges: stooges)
</script>

Upvotes: 2

Related Questions