Esempio n. 1
0
    def render(self, context):
        compressed_package = "<script type='text/javascript' src='" +\
                settings.MEDIA_URL + self.package_name + "-min.js'></script>"

        if settings.DEBUG == False:
            build_package(self.package_name, compress=True)
            return compressed_package

        uncompressed_package = "<script type='text/javascript' src='" +\
                settings.MEDIA_URL + self.package_name + ".js'></script>"

        if "request" in context:
            compress = context["request"].GET.get("compress", "False")
            if compress == "True":
                build_package(self.package_name, compress=True)
                return compressed_package
            elif compress == "False":
                build_package(self.package_name)
                return uncompressed_package

        if hasattr(settings, "JS_BUILDER_COMPRESS"):
            if getattr(settings, "JS_BUILDER_COMPRESS"):
                build_package(self.package_name, compress=True)
                return compressed_package

        build_package(self.package_name)
        return uncompressed_package
Esempio n. 2
0
    def test_build_package(self):
        #
        # TODO:
        #     more tests
        #
        os.mkdir(os.path.join(self.rootTestsDir, "data"))
        os.mkdir(os.path.join(self.rootTestsDir, "source"))
        os.mkdir(os.path.join(self.rootTestsDir, "dest"))

        self.settings_manager.set(
                JS_BUILDER_PACKAGES={"p1": [], "p2": ["a.js"]},
                JS_BUILDER_DEST=os.path.join(self.rootTestsDir, "dest"),
                JS_BUILDER_SOURCE=os.path.join(self.rootTestsDir, "source"))

        # wrong package name
        build_package("wrong package name")
        self.failUnless(check_last_log("wrong package name"))
        self.failUnlessEqual(
                    os.listdir(os.path.join(self.rootTestsDir, "dest")), [])

        # empty package
        build_package("p1")

        f = open(os.path.join(self.rootTestsDir, "source", "a.js"), "w")
        f.write("// require b.js\n")
        f.write("// require c.js\n")
        f.close()
        f = open(os.path.join(self.rootTestsDir, "source", "b.js"), "w")
        f.close()
        f = open(os.path.join(self.rootTestsDir, "source", "c.js"), "w")
        f.close()
        build_package("p2")
Esempio n. 3
0
 def handle_label(self, label, **options):
     """
     """
     build_package(label, **options)