ts_generator.py 1014 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright 2021 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import re
  5. from style_variable_generator.css_generator import CSSStyleGenerator
  6. class TSStyleGenerator(CSSStyleGenerator):
  7. '''Generator for TS Variables'''
  8. @staticmethod
  9. def GetName():
  10. return 'TS'
  11. def Render(self):
  12. return self.ApplyTemplate(self, 'templates/ts_generator.tmpl',
  13. self.GetParameters())
  14. def GetParameters(self):
  15. params = CSSStyleGenerator.GetParameters(self)
  16. params['include_style_sheet'] = self.generator_options.get(
  17. 'include_style_sheet', 'false') == 'true'
  18. return params
  19. def GetFilters(self):
  20. filters = CSSStyleGenerator.GetFilters(self)
  21. filters['to_ts_var_name'] = self.ToTSVarName
  22. return filters
  23. def ToTSVarName(self, model_name):
  24. return re.sub(r'[\.\-]', '_', model_name.upper())