Changeset 65
- Timestamp:
- 12/19/05 22:15:48 (3 years ago)
- Files:
-
- branches/timcommithook/pyramid/flatteners.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/timcommithook/pyramid/flatteners.py
r62 r65 96 96 parentdata = getParentData(self,ctx,dir,name) 97 97 # Add the template data (locals,globals and template) to self.original 98 getFragmentData(self,ctx,dir,name,parentdata)98 data = getFragmentData(self,ctx,dir,name,parentdata) 99 99 # inherit data from parent and merge the result with any 'local' data 100 data = inheritAndMergeLocals(self,ctx,dir, name,parentdata).get(key,{})100 data = inheritAndMergeLocals(self,ctx,dir,None,data,parentdata).get(key,{}) 101 101 return flatten(data, ctx, dir) 102 102 … … 130 130 131 131 # Add the template data (locals,globals and template) to self.original 132 getFragmentData(self,ctx,dir,name,parentdata) 132 data = getFragmentData(self,ctx,dir,name,parentdata) 133 file = self.original.file 134 self.original = data 135 self.original.file = file 133 136 134 137 # inherit data from parent and merge the result with any 'local' data 135 mergedData = inheritAndMergeLocals(self,ctx,dir,name, parentdata)138 mergedData = inheritAndMergeLocals(self,ctx,dir,name,data,parentdata) 136 139 137 140 # Flatten the resultant data ready for use in the template … … 165 168 166 169 # inherit data from parent and merge the result with any 'local' data 167 mergedData = inheritAndMergeLocals(self,ctx,dir,name, parentdata)170 mergedData = inheritAndMergeLocals(self,ctx,dir,name,data,parentdata) 168 171 169 172 # Flatten the resultant data ready for use in the template … … 183 186 # must have come from the cache so return it 184 187 if ctx.data.get(ctx.path,{}).has_key(name): 185 self.original =copy.deepcopy(ctx.data[ctx.path][name])188 return copy.deepcopy(ctx.data[ctx.path][name]) 186 189 else: 187 190 try: 188 191 yaml = file(os.path.join(dir,name)).read() 189 selffile = self.original.file 190 self.original = syck.load(yaml,Loader=Y.Loader, implicit_typing=False) 191 self.original.file = selffile 192 return syck.load(yaml,Loader=Y.Loader, implicit_typing=False) 192 193 except: 193 194 # if the file can't be read. fall back to the parent data 194 self.original =copy.deepcopy(parentdata)195 return copy.deepcopy(parentdata) 195 196 196 197 def getParentData(self,ctx,dir,name): … … 202 203 return parentdata 203 204 204 def inheritAndMergeLocals(self,ctx,dir,name, parentdata):205 def inheritAndMergeLocals(self,ctx,dir,name,data,parentdata): 205 206 ''' store a copy of the data (merged with it's parentdata) on the context and then merge it with the current local data 206 207 ''' 207 208 # for clarity/terseness define a few varibales 208 globals = self.original.globals209 locals = self.original.locals209 globals = data.globals 210 locals = data.locals 210 211 211 212 if ctx.verbose: 212 logFragmentData(path( self.original.template),parentdata, globals, locals)213 logFragmentData(path(data.template),parentdata, globals, locals) 213 214 214 215 # store it on the context … … 216 217 # Also assigning the locals with the current local data 217 218 node = Y.fragment( { 218 'template': self.original.template,219 'global':dictutils.merge(parentdata.globals.copy(),globals ,dir=path(dir).normpath(),partialbuild=ctx.partialbuild),220 'local':locals ,221 'file': self.original.file219 'template':data.template, 220 'global':dictutils.merge(parentdata.globals.copy(),globals.copy(),dir=path(dir).normpath(),partialbuild=ctx.partialbuild), 221 'local':locals.copy(), 222 'file':data.file 222 223 } ) 223 224 # set this fragment on the context with a key of the yaml file name 224 if not ctx.partialbuild :225 if not ctx.partialbuild and name is not None: 225 226 ctx.data.setdefault(str(ctx.path),{})[name] = node 226 227 # merge the parentdata and globals and render the item 227 228 globals = node.globals 228 229 229 data = dictutils.merge(node.globals.copy(),locals ,partialbuild=ctx.partialbuild)230 data = dictutils.merge(node.globals.copy(),locals.copy(),partialbuild=ctx.partialbuild) 230 231 return data 231 232
