def generate_widget_js(lang): code = [] with language(lang): # Provide isolation code.append('(function (siteglobals) {\n') code.append('var module = {}, exports = {};\n') code.append('var lang = "%s";\n' % lang) c = JavaScriptCatalog() c.translation = DjangoTranslation(lang, domain='djangojs') catalog, plural = c.get_catalog(), c.get_plural() str_wl = ('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December') catalog = dict((k, v) for k, v in catalog.items() if k.startswith('widget\u0004') or k in str_wl) template = Engine().from_string(js_catalog_template) context = Context({ 'catalog_str': indent(json.dumps(catalog, sort_keys=True, indent=2)) if catalog else None, 'formats_str': indent(json.dumps(get_formats(), sort_keys=True, indent=2)), 'plural': plural, }) i18n_js = template.render(context) i18n_js = i18n_js.replace( 'for (const ', 'for (var ') # remove if we really want to break IE11 for good i18n_js = i18n_js.replace( r"value.includes(", r"-1 != value.indexOf(" ) # remove if we really want to break IE11 for good code.append(i18n_js) files = [ 'vuejs/vue.js' if settings.DEBUG else 'vuejs/vue.min.js', 'vuejs/vue-resize.min.js', 'pretixpresale/js/widget/docready.js', 'pretixpresale/js/widget/floatformat.js', 'pretixpresale/js/widget/widget.js', ] for fname in files: f = finders.find(fname) with open(f, 'r', encoding='utf-8') as fp: code.append(fp.read()) if settings.DEBUG: code.append('})(this);\n') else: # Do not expose debugging variables code.append('})({});\n') code = ''.join(code) code = rJSMinFilter(content=code).output() return code
def test_jsmin_filter(self): content = """/*! * django-compressor * Copyright (c) 2009-2014 Django Compressor authors */ var foo = "bar";""" output = """/*! * django-compressor * Copyright (c) 2009-2014 Django Compressor authors */var foo="bar";""" self.assertEqual(output, rJSMinFilter(content).output())