This is loosely related to an earlier question I posted, though with a different image editing library (CamanJS instead of Pixastic) and the code refactored somewhat.
I'm trying to write a function changify that reverts the HTML5 image canvas to its original state, and then runs a number of preset changes to it. This code, which loads the right canvas element imageClipName from a list called camanCache, works:
changify = (imageClipName) ->
camanCache[imageClipName].revert ->
camanCache[imageClipName]
.brightness(10)
.contrast(10)
.noise(10)
.render()
console.log(camanCache[imageClipName])
But what I want is to find the saved preset changes from another list called imageValues and dynamically create the string of image function changes from the key value pairs of that list. Here's what I've tried to do, that fails:
imageClipName = "image_1"
imageValues = {image_1:{brightness: 10, contrast: 10, noise: 10}, image_2:{...}...}
changify = (imageClipName) ->
camanCache[imageClipName].revert ->
camanCache[imageClipName]
for o in imageValues when o.id == imageClipName
for key, val of o
.#{key}(val)
.render()
This gives me a coffeescript syntax error for the third line of the changify function (Unexpected 'INDENT'), but I suspect that .#{key}(val) won't work for appending multiple functions to camanCache[imageClipName]. How to dynamically string function calls like this in coffeescript?