@@ -7,13 +7,14 @@ import (
7
7
type forBlock struct {
8
8
iterableName string
9
9
itemName string
10
+ invalid bool
10
11
_scope * variableScope
11
12
* parserBlock
12
13
}
13
14
14
15
func newForBlock (name string , b * parserBlock ) block {
15
16
scope := newVariableScopeWithParent (b .parentBlock ().variables ())
16
- return & forBlock {"" , "" , scope , b }
17
+ return & forBlock {"" , "" , false , scope , b }
17
18
}
18
19
19
20
func (b * forBlock ) variables () * variableScope {
@@ -33,13 +34,27 @@ func (b *forBlock) parse(p *Page) {
33
34
34
35
// warn if missing iterable name
35
36
if b .iterableName == "" {
36
- b .warn (b .openPos , "for{} block is missing iterable name; should be for [@var]" )
37
+ b .warn (b .openPos , "Missing iterable name, should be: for [@var] {...}" )
38
+ b .invalid = true
37
39
return
38
40
}
39
41
40
42
// warn if missing item name
41
43
if b .itemName == "" {
42
- b .warn (b .openPos , "for{} block is missing item name after 'as'" )
44
+ b .warn (b .openPos , "Missing item name after 'as', should be: for [@var as @item] {...}" )
45
+ b .invalid = true
46
+ return
47
+ }
48
+
49
+ found , err := b .variables ().Get (b .iterableName )
50
+ if err != nil {
51
+ b .warn (b .openPos , err .Error ())
52
+ b .invalid = true
53
+ return
54
+ }
55
+ if found == nil {
56
+ b .warn (b .openPos , "@" + b .iterableName + " is not defined" )
57
+ b .invalid = true
43
58
return
44
59
}
45
60
@@ -51,14 +66,14 @@ func (b *forBlock) html(p *Page, el element) {
51
66
el .setMeta ("noTags" , true )
52
67
el .setMeta ("noIndent" , true )
53
68
54
- // do nothing, this was warned above
55
- if b .itemName == "" || b . iterableName == "" {
69
+ // do nothing if invalid
70
+ if b .invalid {
56
71
return
57
72
}
58
73
59
74
iterable , err := b .variables ().Get (b .iterableName )
60
75
if err != nil {
61
- b .warn (b .openPos , "for{} block: " + err .Error ())
76
+ b .warn (b .openPos , err .Error ())
62
77
return
63
78
}
64
79
@@ -77,6 +92,6 @@ func (b *forBlock) html(p *Page, el element) {
77
92
handleGenericContent (b , p , el )
78
93
}
79
94
default :
80
- b .warn (b .openPos , "for{} block: @" + b .iterableName + " is not iterable" )
95
+ b .warn (b .openPos , "@" + b .iterableName + " is not iterable" )
81
96
}
82
97
}
0 commit comments