Skip all nodes in an iteration context unless building the views for the iterated items.
Showing
1 changed file
with
39 additions
and
25 deletions
... | @@ -114,38 +114,52 @@ class Rivets.View | ... | @@ -114,38 +114,52 @@ class Rivets.View |
114 | # Builds the Rivets.Binding instances for the view. | 114 | # Builds the Rivets.Binding instances for the view. |
115 | build: => | 115 | build: => |
116 | @bindings = [] | 116 | @bindings = [] |
117 | skipNodes = [] | ||
118 | iterator = null | ||
117 | bindingRegExp = @bindingRegExp() | 119 | bindingRegExp = @bindingRegExp() |
118 | eventRegExp = /^on-/ | 120 | eventRegExp = /^on-/ |
119 | iterationRegExp = /^each-/ | 121 | iterationRegExp = /^each-/ |
120 | 122 | ||
121 | parseNode = (node) => | 123 | parseNode = (node) => |
122 | for attribute in node.attributes | 124 | unless node in skipNodes |
123 | if bindingRegExp.test attribute.name | 125 | for attribute in node.attributes |
124 | options = {} | 126 | if bindingRegExp.test attribute.name |
125 | 127 | type = attribute.name.replace bindingRegExp, '' | |
126 | type = attribute.name.replace bindingRegExp, '' | ||
127 | pipes = (pipe.trim() for pipe in attribute.value.split '|') | ||
128 | context = (ctx.trim() for ctx in pipes.shift().split '>') | ||
129 | path = context.shift() | ||
130 | splitPath = path.split /\.|:/ | ||
131 | options.formatters = pipes | ||
132 | model = @models[splitPath.shift()] | ||
133 | options.bypass = path.indexOf(":") != -1 | ||
134 | keypath = splitPath.join() | ||
135 | |||
136 | if model | ||
137 | if dependencies = context.shift() | ||
138 | options.dependencies = dependencies.split /\s+/ | ||
139 | |||
140 | if eventRegExp.test type | ||
141 | type = type.replace eventRegExp, '' | ||
142 | options.special = "event" | ||
143 | 128 | ||
144 | if iterationRegExp.test type | 129 | if iterationRegExp.test type |
145 | type = type.replace iterationRegExp, '' | 130 | unless @models[type.replace iterationRegExp, ''] |
146 | options.special = "iteration" | 131 | skipNodes.push n for n in node.getElementsByTagName '*' |
147 | 132 | iterator = [attribute] | |
148 | @bindings.push new Rivets.Binding node, type, model, keypath, options | 133 | |
134 | for attribute in iterator or node.attributes | ||
135 | iterator = null | ||
136 | |||
137 | if bindingRegExp.test attribute.name | ||
138 | options = {} | ||
139 | |||
140 | type = attribute.name.replace bindingRegExp, '' | ||
141 | pipes = (pipe.trim() for pipe in attribute.value.split '|') | ||
142 | context = (ctx.trim() for ctx in pipes.shift().split '>') | ||
143 | path = context.shift() | ||
144 | splitPath = path.split /\.|:/ | ||
145 | options.formatters = pipes | ||
146 | model = @models[splitPath.shift()] | ||
147 | options.bypass = path.indexOf(":") != -1 | ||
148 | keypath = splitPath.join() | ||
149 | |||
150 | if model | ||
151 | if dependencies = context.shift() | ||
152 | options.dependencies = dependencies.split /\s+/ | ||
153 | |||
154 | if eventRegExp.test type | ||
155 | type = type.replace eventRegExp, '' | ||
156 | options.special = "event" | ||
157 | |||
158 | if iterationRegExp.test type | ||
159 | type = type.replace iterationRegExp, '' | ||
160 | options.special = "iteration" | ||
161 | |||
162 | @bindings.push new Rivets.Binding node, type, model, keypath, options | ||
149 | 163 | ||
150 | for el in @els | 164 | for el in @els |
151 | parseNode el | 165 | parseNode el | ... | ... |
-
Please register or sign in to post a comment