예제 #1
0
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
예제 #2
0
class CSSStyleGeneratorTest(unittest.TestCase, BaseStyleGeneratorTest):
    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'

    def testCustomDarkModeSelector(self):
        expected_file_name = 'colors_test_custom_dark_toggle_expected.css'
        self.generator.generator_options = {
            'dark_mode_selector': 'html[dark]:not(body)'
        }
        self.assertEqualToFile(self.generator.Render(), expected_file_name)

    def testCustomDarkModeSelector(self):
        expected_file_name = 'colors_test_dark_only_expected.css'
        self.generator.generate_single_mode = Modes.DARK
        self.assertEqualToFile(self.generator.Render(), expected_file_name)
예제 #3
0
class CSSStyleGeneratorTest(unittest.TestCase):
    def setUp(self):
        self.generator = CSSStyleGenerator()

    def assertEqualToFile(self, value, filename):
        with open(filename) as f:
            self.assertEqual(value, f.read())

    def testColorTestJSON(self):
        self.generator.AddJSONFileToModel('colors_test.json5')
        self.assertEqualToFile(self.generator.Render(),
                               'colors_test_expected.css')
class CSSStyleGeneratorTest(unittest.TestCase):
    def setUp(self):
        self.generator = CSSStyleGenerator()
        self.generator.AddJSONFileToModel('colors_test_palette.json5')
        self.generator.AddJSONFileToModel('colors_test.json5')

    def assertEqualToFile(self, value, filename):
        with open(filename) as f:
            contents = f.read()
            self.assertEqual(
                value, contents,
                '\n>>>>>\n%s<<<<<\n\ndoes not match\n\n>>>>>\n%s<<<<<' %
                (value, contents))

    def testColorTestJSON(self):
        self.assertEqualToFile(self.generator.Render(),
                               'colors_test_expected.css')

    def testColorTestJSONDarkOnly(self):
        self.generator.generate_single_mode = Modes.DARK
        self.assertEqualToFile(self.generator.Render(),
                               'colors_test_dark_only_expected.css')
예제 #5
0
class CSSStyleGeneratorTest(unittest.TestCase, BaseStyleGeneratorTest):
    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'