| OLD | NEW |
| 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 '''Base types for nodes in a GRIT resource tree. | 6 '''Base types for nodes in a GRIT resource tree. |
| 7 ''' | 7 ''' |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 inside_parts = inside_parts[:-1] | 290 inside_parts = inside_parts[:-1] |
| 291 | 291 |
| 292 # If the last item is a string (not a node) and ends with whitespace, | 292 # If the last item is a string (not a node) and ends with whitespace, |
| 293 # we need to add the ''' delimiter. | 293 # we need to add the ''' delimiter. |
| 294 if (isinstance(last_item, types.StringTypes) and | 294 if (isinstance(last_item, types.StringTypes) and |
| 295 last_item.rstrip() != last_item): | 295 last_item.rstrip() != last_item): |
| 296 inside_parts[-1] = inside_parts[-1] + u"'''" | 296 inside_parts[-1] = inside_parts[-1] + u"'''" |
| 297 | 297 |
| 298 return u''.join(inside_parts) | 298 return u''.join(inside_parts) |
| 299 | 299 |
| 300 def RunGatherers(self, recursive=0, debug=False): | 300 def RunGatherers(self, recursive=0, debug=False, substitute_messages=False): |
| 301 '''Runs all gatherers on this object, which may add to the data stored | 301 '''Runs all gatherers on this object, which may add to the data stored |
| 302 by the object. If 'recursive' is true, will call RunGatherers() recursively | 302 by the object. If 'recursive' is true, will call RunGatherers() recursively |
| 303 on all child nodes first. If 'debug' is True, will print out information | 303 on all child nodes first. If 'debug' is True, will print out information |
| 304 as it is running each nodes' gatherers. | 304 as it is running each nodes' gatherers. |
| 305 | |
| 306 Gatherers for <translations> child nodes will always be run after all other | |
| 307 child nodes have been gathered. | |
| 308 ''' | 305 ''' |
| 309 if recursive: | 306 if recursive: |
| 310 process_last = [] | |
| 311 for child in self.children: | 307 for child in self.children: |
| 312 if child.name == 'translations': | 308 assert child.name != 'translations' # <grit> node overrides |
| 313 process_last.append(child) | |
| 314 else: | |
| 315 child.RunGatherers(recursive=recursive, debug=debug) | |
| 316 for child in process_last: | |
| 317 child.RunGatherers(recursive=recursive, debug=debug) | 309 child.RunGatherers(recursive=recursive, debug=debug) |
| 318 | 310 |
| 319 def SubstituteMessages(self, substituter): | 311 def SubstituteMessages(self, substituter): |
| 320 '''Applies substitutions to all messages in the tree. | 312 '''Applies substitutions to all messages in the tree. |
| 321 | 313 |
| 322 Called as a final step of RunGatherers. | 314 Called as a final step of RunGatherers. |
| 323 | 315 |
| 324 Args: | 316 Args: |
| 325 substituter: a grit.util.Substituter object. | 317 substituter: a grit.util.Substituter object. |
| 326 ''' | 318 ''' |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 def ExpandVariables(self): | 552 def ExpandVariables(self): |
| 561 '''Whether we need to expand variables on a given node.''' | 553 '''Whether we need to expand variables on a given node.''' |
| 562 return False | 554 return False |
| 563 | 555 |
| 564 | 556 |
| 565 class ContentNode(Node): | 557 class ContentNode(Node): |
| 566 '''Convenience baseclass for nodes that can have content.''' | 558 '''Convenience baseclass for nodes that can have content.''' |
| 567 def _ContentType(self): | 559 def _ContentType(self): |
| 568 return self._CONTENT_TYPE_MIXED | 560 return self._CONTENT_TYPE_MIXED |
| 569 | 561 |
| OLD | NEW |