1 | Node = require('./node')
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | module.exports = class Code extends Node
|
16 |
|
17 |
|
18 |
|
19 | evaluate: ->
|
20 | codeBlock = @expression.match(/(-|!=|\&=|=|~)\s?(.*)?/)
|
21 | identifier = codeBlock[1]
|
22 | code = codeBlock[2]
|
23 |
|
24 |
|
25 | if identifier is '-'
|
26 | @opener = @markRunningCode(code)
|
27 |
|
28 |
|
29 | @closer = @markRunningCode(" ''") if @children.length isnt 0 and @opener.code.match(/(->|=>)/)
|
30 |
|
31 |
|
32 | else if identifier is '~'
|
33 | if @escapeHtml
|
34 | @opener = @markInsertingCode(code, true, false, true)
|
35 | else
|
36 | @opener = @markInsertingCode(code, false, false, true)
|
37 |
|
38 |
|
39 | else
|
40 | escape = identifier is '&=' or (identifier is '=' and @escapeHtml)
|
41 |
|
42 | if @children.length isnt 0 and code.match(/(->|=>)$/)
|
43 | @opener = @markInsertingCode(code, escape, false, false)
|
44 | @opener.block = 'start'
|
45 |
|
46 | @closer = @markRunningCode(" $buffer.join \"\\n\"")
|
47 | @closer.block = 'end'
|
48 |
|
49 | else
|
50 | @opener = @markInsertingCode(code, escape)
|