0

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...

Aaron Dufour
  • 17,288
  • 1
  • 47
  • 69
Jason Blade
  • 373
  • 2
  • 4
  • 17

1 Answers1

2

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>
Rudolf Meijering
  • 1,559
  • 1
  • 14
  • 20