def main():
    parser = argparse.ArgumentParser(
        description='Generate style variables from JSON5 color file.')

    parser.add_argument(
        '--generator',
        choices=['CSS', 'Views'],
        required=True,
        help='type of file to generate')
    parser.add_argument('--out-file', help='file to write output to')
    parser.add_argument('targets', nargs='+', help='source json5 color files')

    args = parser.parse_args()

    if args.generator == 'CSS':
        style_generator = CSSStyleGenerator()

    if args.generator == 'Views':
        style_generator = ViewsStyleGenerator()

    for t in args.targets:
        style_generator.AddJSONFileToModel(t)

    style_generator.out_file_path = args.out_file

    if args.out_file:
        with open(args.out_file, 'w') as f:
            f.write(style_generator.Render())
    else:
        print(style_generator.Render())

    return 0
def FindInvalidCSSVariables(json_string, input_file, git_runner=RunGit):
    style_generator = CSSStyleGenerator()
    style_generator.AddJSONToModel(json_string, in_file=input_file)

    context = style_generator.in_file_to_context[input_file]
    if (not context or 'prefix' not in context):
        raise KeyError('This tool only works on files with a CSS prefix.')

    css_prefix = '--' + context['prefix'] + '-'

    valid_names = style_generator.GetCSSVarNames()

    found_names_list = git_runner([
        'grep', '-ho',
        '\\%s[a-z-]*' % css_prefix, '--', '*.css', '*.html', '*.js'
    ]).splitlines()
    found_names = set()
    for name in found_names_list:
        rgb_suffix = '-rgb'
        if name.endswith(rgb_suffix):
            name = name[:-len(rgb_suffix)]
        found_names.add(name)
    return {
        'unspecified': found_names.difference(valid_names),
        'unused': valid_names.difference(found_names),
        'css_prefix': css_prefix,
    }
Beispiel #3
0
 def get_css_var_names_for_contents(contents_function):
     style_generator = CSSStyleGenerator()
     for f in files:
         file_contents = contents_function(f)
         if len(file_contents) == 0:
             continue
         style_generator.AddJSONToModel('\n'.join(file_contents),
                                        in_file=f.LocalPath())
     return style_generator.GetCSSVarNames()
 def setUp(self):
     self.generator = CSSStyleGenerator()
     self.generator.AddJSONFileToModel('colors_test_palette.json5')
     self.generator.AddJSONFileToModel('colors_test.json5')
Beispiel #5
0
 def setUp(self):
     self.generator = CSSStyleGenerator()
     self.generator.AddJSONFileToModel('colors_test_palette.json5')
     self.generator.AddJSONFileToModel('colors_test.json5')
     self.expected_output_file = 'colors_test_expected.css'
Beispiel #6
0
 def setUp(self):
     self.generator = CSSStyleGenerator()