| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Code shared by the various language-specific code generators.""" | 5 """Code shared by the various language-specific code generators.""" |
| 6 | 6 |
| 7 from functools import partial | 7 from functools import partial |
| 8 import os.path | 8 import os.path |
| 9 import re | 9 import re |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 return kind.length | 40 return kind.length |
| 41 return None | 41 return None |
| 42 | 42 |
| 43 def StudlyCapsToCamel(studly): | 43 def StudlyCapsToCamel(studly): |
| 44 return studly[0].lower() + studly[1:] | 44 return studly[0].lower() + studly[1:] |
| 45 | 45 |
| 46 def CamelCaseToAllCaps(camel_case): | 46 def CamelCaseToAllCaps(camel_case): |
| 47 return '_'.join( | 47 return '_'.join( |
| 48 word for word in re.split(r'([A-Z][^A-Z]+)', camel_case) if word).upper() | 48 word for word in re.split(r'([A-Z][^A-Z]+)', camel_case) if word).upper() |
| 49 | 49 |
| 50 def UnderToCamel(under): | |
| 51 """Converts underscore_separated strings to CamelCase strings.""" | |
| 52 return ''.join(word.capitalize() for word in under.split('_')) | |
| 53 | |
| 54 def WriteFile(contents, full_path): | 50 def WriteFile(contents, full_path): |
| 55 # Make sure the containing directory exists. | 51 # Make sure the containing directory exists. |
| 56 full_dir = os.path.dirname(full_path) | 52 full_dir = os.path.dirname(full_path) |
| 57 if not os.path.exists(full_dir): | 53 if not os.path.exists(full_dir): |
| 58 os.makedirs(full_dir) | 54 os.makedirs(full_dir) |
| 59 | 55 |
| 60 # Dump the data to disk. | 56 # Dump the data to disk. |
| 61 with open(full_path, "w+") as f: | 57 with open(full_path, "w+") as f: |
| 62 f.write(contents) | 58 f.write(contents) |
| 63 | 59 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 def GenerateFiles(self, args): | 91 def GenerateFiles(self, args): |
| 96 raise NotImplementedError("Subclasses must override/implement this method") | 92 raise NotImplementedError("Subclasses must override/implement this method") |
| 97 | 93 |
| 98 def GetJinjaParameters(self): | 94 def GetJinjaParameters(self): |
| 99 """Returns default constructor parameters for the jinja environment.""" | 95 """Returns default constructor parameters for the jinja environment.""" |
| 100 return {} | 96 return {} |
| 101 | 97 |
| 102 def GetGlobals(self): | 98 def GetGlobals(self): |
| 103 """Returns global mappings for the template generation.""" | 99 """Returns global mappings for the template generation.""" |
| 104 return {} | 100 return {} |
| OLD | NEW |