/
pug_blocks.go
260 lines (204 loc) · 4.44 KB
/
pug_blocks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
package pugjs
import (
"bytes"
"github.com/stretchr/testify/mock"
)
// Render blocks
// see https://github.com/pugjs/pug-ast-spec/blob/master/parser.md
// Not complete, and some minor things have been stripped
type (
// Node objects
// Node is something renderable
Node interface {
Render(r *renderState, wr *bytes.Buffer) error
Inline() bool
}
// Blocks
// Block is a list of nodes
Block struct {
Nodes []Node
}
// Abstract Node Types
// AttributedNode extends a node with attributes
AttributedNode struct {
Attrs []Attribute
AttributeBlocks []JavaScriptExpression
}
// BlockNode is a block (which is renderable)
BlockNode struct {
Block Block
}
// ExpressionNode is a javascript expression
ExpressionNode struct {
Expr JavaScriptExpression
}
// PlaceholderNode does nothing
PlaceholderNode struct{}
// ValueNode contains a value
ValueNode struct {
Val string
}
// Attribute is a key-value attribute (might have to be escaped)
Attribute struct {
Name string
Val JavaScriptExpression
MustEscape bool
BoolVal *bool
}
// JavaScriptExpression is a string
JavaScriptExpression string
// JavaScriptIdentifier is a string
JavaScriptIdentifier string
// Doctypes
// Doctype is a `<!DOCTYPE...` node
Doctype struct {
ValueNode
}
// Comments
// CommonComment is the basic value for comments
CommonComment struct {
ValueNode
}
// Comment is single line comment
Comment struct {
CommonComment
}
// BlockComment is multi line comment
BlockComment struct {
BlockNode
CommonComment
}
// Text
// Text contains raw text
Text struct {
ValueNode
}
// Tag
// CommonTag is the base structure for tags
CommonTag struct {
AttributedNode
BlockNode
SelfClosing bool // SelfClosing if the tag is explicitly stated as self-closing
IsInline *bool // IsInline if the tag is defined as an inline tag as opposed to a block-level tag
}
// Tag is just a tag
Tag struct {
CommonTag
Name string
}
// InterpolatedTag a tag which is created on the fly
InterpolatedTag struct {
CommonTag
ExpressionNode
}
// Code
// Code is a code block
Code struct {
BlockNode
ValueNode
Buffer bool // Buffer if the value of the piece of code is buffered in the template
MustEscape bool // MustEscape if the value must be HTML-escaped before being buffered
IsInline *bool // IsInline whether the node is the result of a string interpolation
}
// Code Helpers
// Conditional is equivalent to `if`
Conditional struct {
Test JavaScriptExpression
Consequent Node
Alternate Node
}
// Each iterates over something
Each struct {
BlockNode
Obj JavaScriptExpression
Val JavaScriptIdentifier
Key JavaScriptIdentifier
}
// While loop
While struct {
BlockNode
Test JavaScriptExpression
}
// Mixin
// Mixin can be defined or called
Mixin struct {
AttributedNode
BlockNode
Name JavaScriptIdentifier
Call bool
Args JavaScriptExpression
}
// MixinBlock renders the mixin block
MixinBlock struct {
PlaceholderNode
}
// Case switch/case construct
Case struct {
BlockNode
ExpressionNode
}
// When is a case in a case-construct
When struct {
BlockNode
ExpressionNode
}
// MockNode is an autogenerated mock type for the Node type
MockNode struct {
mock.Mock
}
)
// Inline check for a block
func (b *Block) Inline() bool {
for _, n := range b.Nodes {
if !n.Inline() {
return false
}
}
return true
}
// Inline for BlockNodes
func (b *BlockNode) Inline() bool {
return b.Block.Inline()
}
// Inline for CommonTags
func (ct *CommonTag) Inline() bool {
return *ct.IsInline
}
// Inline for Code
func (c *Code) Inline() bool {
return *c.IsInline
}
// Inline for ValueNodes
func (v *ValueNode) Inline() bool {
return true
}
// Inline for PlaceholderNodes
func (p *PlaceholderNode) Inline() bool {
return true
}
// Inline for Conditionals
func (c *Conditional) Inline() bool {
return true
}
// Inline provides a mock function with given fields:
func (_m *MockNode) Inline() bool {
ret := _m.Called()
var r0 bool
if rf, ok := ret.Get(0).(func() bool); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(bool)
}
return r0
}
// Render provides a mock function with given fields: r, wr
func (_m *MockNode) Render(r *renderState, wr *bytes.Buffer) error {
ret := _m.Called(r, wr)
var r0 error
if rf, ok := ret.Get(0).(func(*renderState, *bytes.Buffer) error); ok {
r0 = rf(r, wr)
} else {
r0 = ret.Error(0)
}
return r0
}