Surprising hardcode behavior

36 views
Skip to first unread message

Ian Young

unread,
Aug 23, 2011, 6:45:27 PM8/23/11
to CoffeeKup
Hi there,

I'm trying to pass the Underscore library through to my coffeekup
views and encountering some strange behavior. It looks like functions
get scrubbed from the `hardcode` parameters at some point. Is this
intentional?

I've got a small test case below. Right now, it throws an error
because `foo.baz` is not defined in the view.

ck = require 'coffeekup'

template = ->
h1 foo.bar
h2 foo.baz()

helpers =
foo:
bar: "bar"
baz: -> "baz"

console.log ck.render(template, hardcode: helpers)


Thanks,
Ian

Maurice Machado

unread,
Aug 23, 2011, 9:00:17 PM8/23/11
to coff...@googlegroups.com
Not intended but expected. The current implementation of hardcode is very simplistic. For each (root) attribute in the hardcode object, we hardcode a variable in the compiled function with JSON.stringify(value) as value. Functions are ignored by JSON.stringify, so we use .toString() alternatively for functions at the root level, but we don't do it recursively yet.

Maurice Machado

unread,
Sep 4, 2011, 3:43:04 PM9/4/11
to CoffeeKup
Reply all
Reply to author
Forward
0 new messages