Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: grit/node/structure.py

Issue 16539002: GRIT: Enable variable expansion in filenames during HTML inlining. (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « grit/gather/interface.py ('k') | grit/node/structure_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''The <structure> element. 6 '''The <structure> element.
7 ''' 7 '''
8 8
9 import os 9 import os
10 import platform 10 import platform
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 gathertype = _GATHERERS[self.attrs['type']] 86 gathertype = _GATHERERS[self.attrs['type']]
87 87
88 self.gatherer = gathertype(self.attrs['file'], 88 self.gatherer = gathertype(self.attrs['file'],
89 self.attrs['name'], 89 self.attrs['name'],
90 self.attrs['encoding']) 90 self.attrs['encoding'])
91 self.gatherer.SetGrdNode(self) 91 self.gatherer.SetGrdNode(self)
92 self.gatherer.SetUberClique(self.UberClique()) 92 self.gatherer.SetUberClique(self.UberClique())
93 if hasattr(self.GetRoot(), 'defines'): 93 if hasattr(self.GetRoot(), 'defines'):
94 self.gatherer.SetDefines(self.GetRoot().defines) 94 self.gatherer.SetDefines(self.GetRoot().defines)
95 self.gatherer.SetAttributes(self.attrs) 95 self.gatherer.SetAttributes(self.attrs)
96 if self.ExpandVariables():
97 self.gatherer.SetFilenameExpansionFunction(self._Substitute)
96 98
97 # Parse local variables and instantiate the substituter. 99 # Parse local variables and instantiate the substituter.
98 if self.attrs['variables']: 100 if self.attrs['variables']:
99 variables = self.attrs['variables'] 101 variables = self.attrs['variables']
100 self.substituter = util.Substituter() 102 self.substituter = util.Substituter()
101 self.substituter.AddSubstitutions(self._ParseVariables(variables)) 103 self.substituter.AddSubstitutions(self._ParseVariables(variables))
102 104
103 self.skeletons = {} # Maps expressions to skeleton gatherers 105 self.skeletons = {} # Maps expressions to skeleton gatherers
104 for child in self.children: 106 for child in self.children:
105 assert isinstance(child, variant.SkeletonNode) 107 assert isinstance(child, variant.SkeletonNode)
106 skel = gathertype(child.attrs['file'], 108 skel = gathertype(child.attrs['file'],
107 self.attrs['name'], 109 self.attrs['name'],
108 child.GetEncodingToUse(), 110 child.GetEncodingToUse(),
109 is_skeleton=True) 111 is_skeleton=True)
110 skel.SetGrdNode(self) # TODO(benrg): Or child? Only used for ToRealPath 112 skel.SetGrdNode(self) # TODO(benrg): Or child? Only used for ToRealPath
111 skel.SetUberClique(self.UberClique()) 113 skel.SetUberClique(self.UberClique())
114 if hasattr(self.GetRoot(), 'defines'):
115 skel.SetDefines(self.GetRoot().defines)
116 if self.ExpandVariables():
117 skel.SetFilenameExpansionFunction(self._Substitute)
112 self.skeletons[child.attrs['expr']] = skel 118 self.skeletons[child.attrs['expr']] = skel
113 119
114 def MandatoryAttributes(self): 120 def MandatoryAttributes(self):
115 return ['type', 'name', 'file'] 121 return ['type', 'name', 'file']
116 122
117 def DefaultAttributes(self): 123 def DefaultAttributes(self):
118 return { 'encoding' : 'cp1252', 124 return { 'encoding' : 'cp1252',
119 'exclude_from_rc' : 'false', 125 'exclude_from_rc' : 'false',
120 'line_end' : 'unix', 126 'line_end' : 'unix',
121 'output_encoding' : 'utf-8', 127 'output_encoding' : 'utf-8',
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 def SubstituteMessages(self, substituter): 349 def SubstituteMessages(self, substituter):
344 '''Propagates substitution to gatherer. 350 '''Propagates substitution to gatherer.
345 351
346 Args: 352 Args:
347 substituter: a grit.util.Substituter object. 353 substituter: a grit.util.Substituter object.
348 ''' 354 '''
349 assert hasattr(self, 'gatherer') 355 assert hasattr(self, 'gatherer')
350 if self.ExpandVariables(): 356 if self.ExpandVariables():
351 self.gatherer.SubstituteMessages(substituter) 357 self.gatherer.SubstituteMessages(substituter)
352 358
OLDNEW
« no previous file with comments | « grit/gather/interface.py ('k') | grit/node/structure_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698