1 | Node = require('./node')
|
2 | {escapeQuotes} = require('../util/text')
|
3 |
|
4 | # Comment node for silent code blocks or pure
|
5 | # Haml comments.
|
6 | #
|
7 | # @example silent code block
|
8 | # -# silent
|
9 | # code comment
|
10 | #
|
11 | # @example Haml comment
|
12 | # / This is a comment
|
13 | #
|
14 | # @example Haml conditional comment
|
15 | # /[if IE]
|
16 | #
|
17 | # Comments nodes can be silent, so they swallow all the children output.
|
18 | #
|
19 | module.exports = class Comment extends Node
|
20 |
|
21 | # Evaluate the Haml comments
|
22 | #
|
23 | evaluate: ->
|
24 | [expression, identifier, comment] = @expression.match(/(-#|\/\[|\/)\s?(.*)?/)
|
25 |
|
26 | switch identifier
|
27 |
|
28 | # Silent code block
|
29 | when '-#'
|
30 | @silent = true
|
31 | @opener = @markText ''
|
32 |
|
33 | # Conditional comment
|
34 | when '\/['
|
35 | @opener = @markText "<!--[#{ comment }>"
|
36 | @closer = @markText '<![endif]-->'
|
37 |
|
38 | # Normal Haml comment
|
39 | when '\/'
|
40 |
|
41 | # With a inline comment
|
42 | if comment
|
43 | @opener = @markText "<!-- #{ escapeQuotes(comment) }"
|
44 | @closer = @markText ' -->'
|
45 |
|
46 | # With multi line comment
|
47 | else
|
48 | @opener = @markText "<!--"
|
49 | @closer = @markText '-->'
|