Am 21.11.2013 16:51, schrieb Manu Evans:

On Thu, 21 Nov 2013 15:26:16 GMT, Manu Evans wrote:

script(type="text/javascript")
  |var x = 0
  - foreach(x; things)
    | #{x},   // <-- it can't find x
  |];

Problem:
Error: undefined identifier x, did you mean template to(T)?

It seems that the scope of the '|' block under the foreach isn't scoped correctly, x is not local...?

You know, I reckon there's a possible library function here. What I need to do is make some D data available to the javascript.
It would be awesome to have a function which would produce a javascript declaration from a D value/structure.

Actually, as far as I can tell, all the '|' beneath script are ignored.
So just the same as :javascript, everything beneath script() seems to be copied verbatim as well.

Damn, you are right, script and style tags get special treatment. So the
correct way is this and control statements are not really possible:

script
	var x = [#{join(things, ",")}];

The idea of automatically mirroring D data as JavaScript is nice. A good
approximation should be to use JSON:

script
	var x = !{serializeToJson(things)}