Ejemplo n.º 1
0
def static_jitter(user_agent, filename):
    app_root = settings.PROJECT_ROOT
    browser = httpagentparser.detect(user_agent).get('browser', {})
    browser_name = browser.get('name', 'IE').lower()
    browser_version = int(browser.get('version', '0').split('.')[0])

    actual_name = filename.split('/')[-1]

    input_file_path = app_root + '/' + filename

    output_dir = os.path.dirname(input_file_path)
    output_file_path = output_dir + '/{}.{}.{}'.format(
        browser_name, browser_version, actual_name)

    if not os.path.isfile(output_file_path):
        with open(output_file_path, 'w+r+') as output_file:
            import pdb
            pdb.set_trace()

            presets = get_presets(browser_name, browser_version)
            babeledjs = transformer.transform(input_file_path, **presets)
            output_file.write(babeledjs)
            output_file.seek(0)

            js = output_file.read()
            output_file.seek(0)

            minifiedjs, err = minify(js)
            output_file.truncate()

            output_file.write(minifiedjs)

    return static(output_dir + actual_name)
Ejemplo n.º 2
0
 def test_transform_vue_jsx(self):
     js_path = path.join(ROOT, 'test_vue_jsx.js')
     code = transformer.transform(
         js_path, **{
             'presets': ['es2015', 'stage-0'],
             'plugins':
             ['transform-decorators-legacy', 'transform-vue-jsx']
         })
     self.assertEqual(
         open(path.join(ROOT, 'result-test_vue_jsx.js'), 'r').read(), code)
Ejemplo n.º 3
0
 def test_transform_vue_jsx(self):
     js_path = path.join(ROOT, 'test_vue_jsx.js')
     code = transformer.transform(
         js_path,
         runtime=self.runtime,
         **{
             'presets': ['es2015', 'stage-0'],
             'plugins':
             ['transform-decorators-legacy', 'transform-vue-jsx']
         })
     with open(path.join(ROOT, 'result-test_vue_jsx.js'), 'r') as f:
         expected_code = f.read()
     self.assertEqual(expected_code, code)
Ejemplo n.º 4
0
 def test_transform(self):
     js_path = path.join(ROOT, 'test.js')
     code = transformer.transform(js_path)
     self.assertEqual('"use strict";\n\nvar a = 1;', code)
Ejemplo n.º 5
0
 def test_jquery(self):
     js_path = path.join(ROOT, 'jquery.js')
     transformer.transform(js_path, runtime=self.runtime)
Ejemplo n.º 6
0
 def test_large_file(self):
     js_path = path.join(ROOT, 'large.js')
     code = transformer.transform(js_path, runtime=self.runtime)
     self.assertEqual(code[:22], '"use strict";var foo="')
Ejemplo n.º 7
0
 def test_transform(self):
     path = join(ROOT, 'test.js')
     code = transformer.transform(path)
     self.assertEqual('"use strict";\n\nvar a = 1;', code)