コード例 #1
0
ファイル: __init__.py プロジェクト: TMG-nl/sherman
    def modulesWritten(self):
        self.buildFullBootModule()

        for locale in self.projectBuilder.locales:
            resources = {}
            bootScripts = []
            for module in self.projectBuilder.modules:
                moduleName = module["name"]
                if moduleName == "inline":
                    continue

                module = self.currentBuild.files[locale][moduleName]

                jsFileName = None
                for fileName in module["__output__"]:
                    if fileName.endswith(".js"):
                        jsFileName = fileName
                if not jsFileName:
                    raise BuildError("Module %s did not generate a JavaScript output file" % moduleName)

                resources[moduleName] = {}
                resources[moduleName][locale] = jsFileName
                resources[moduleName]["dependencies"] = module["__manifest__"]["dependencies"]
                if moduleName == "boot":
                    bootScripts.append("[static_base]/" + jsFileName)
                if "essential" in module["__manifest__"] and module["__manifest__"]["essential"]:
                    resources[moduleName]["essential"] = True

            bootJson = {
                "bootscripts": bootScripts,
                "resources": resources,
                "locale": locale,
                "baseurl": "[static_base]/",
                "config": "[config]"
            }

            if "tiles" in self.projectBuilder.features:
                bootJson["tileModuleDependencies"] = self.projectBuilder.features["tiles"].tileModuleDependencies

            bootJson = json.dumps(bootJson)

            fileName = buildutil.getDestinationFileName("boot", None, bootJson, locale, "json")
            with codecs.open(self.buildDir + "/" + fileName, "w", "utf-8") as f:
                f.write(bootJson)

            bootHash = buildutil.getContentHash(bootJson)
            self.writeVersionFile("__versionjson__", locale, bootHash)

        self.reinstateBootModule()
コード例 #2
0
    def writeBootHtml(self, locale):
        bootstrapCode = {
            "head": "",
            "body": "Application.init([config])",
            "tail": ""
        }
        self.invokeFeatures("generateBootstrapCode", locale, bootstrapCode)

        headJs = (
            "try{document.domain='%(domain)s'}catch(e){}"
            "function giveUp(e){var a=confirm('Het spijt me te moeten zeggen dat %(title)s niet kon opstarten. Zullen we het opnieuw proberen?');"
            r"if(a){window.location.reload()}else{document.body?document.body.innerHTML='<h1>'+e+'</h1><p><button onclick=\"window.location.reload()\">Verfrissen</button></p>':alert(e)}}"
            "try{"
            "%(head)s"
            "function go(){"
            "%(body)s"
            "}"
            "%(tail)s"
            "}catch(e){giveUp(e)}") % {
                "domain": self.projectManifest["domain"],
                "title": self.projectManifest["title"],
                "head": bootstrapCode["head"],
                "body": bootstrapCode["body"],
                "tail": bootstrapCode["tail"]
            }

        onloadJs = ("try{go()}catch(e){giveUp(e)}")

        # icing on the cake, include your favorite icon in the HTML
        favicon = buildutil.base64EncodeImage(self.projectDir +
                                              "/boot/favicon.ico")

        with open(self.projectDir + "/boot/boot.tpl.html") as f:
            bootHtml = f.read() % {
                "favicon": favicon,
                "headJs": headJs,
                "onloadJs": onloadJs
            }

        filename = buildutil.getDestinationFileName("boot", None, bootHtml,
                                                    locale, "html")
        with codecs.open(self.buildDir + "/" + filename, "w", "utf-8") as f:
            f.write(bootHtml)

        return buildutil.getContentHash(bootHtml)
コード例 #3
0
ファイル: build.py プロジェクト: TMG-nl/sherman
    def writeBootHtml(self, locale):
        bootstrapCode = {
            "head": "",
            "body": "Application.init([config])",
            "tail": ""
        }
        self.invokeFeatures("generateBootstrapCode", locale, bootstrapCode)

        headJs = (
            "try{document.domain='%(domain)s'}catch(e){}"
            "function giveUp(e){var a=confirm('Het spijt me te moeten zeggen dat %(title)s niet kon opstarten. Zullen we het opnieuw proberen?');"
            r"if(a){window.location.reload()}else{document.body?document.body.innerHTML='<h1>'+e+'</h1><p><button onclick=\"window.location.reload()\">Verfrissen</button></p>':alert(e)}}"
            "try{"
            "%(head)s"
            "function go(){"
            "%(body)s"
            "}"
            "%(tail)s"
            "}catch(e){giveUp(e)}"
        ) % {
            "domain": self.projectManifest["domain"],
            "title": self.projectManifest["title"],
            "head": bootstrapCode["head"],
            "body": bootstrapCode["body"],
            "tail": bootstrapCode["tail"]
        }

        onloadJs = ("try{go()}catch(e){giveUp(e)}")

        # icing on the cake, include your favorite icon in the HTML
        favicon = buildutil.base64EncodeImage(self.projectDir + "/boot/favicon.ico")

        with open(self.projectDir + "/boot/boot.tpl.html") as f:
            bootHtml = f.read() % {
                "favicon": favicon,
                "headJs": headJs,
                "onloadJs": onloadJs
            }

        filename = buildutil.getDestinationFileName("boot", None, bootHtml, locale, "html")
        with codecs.open(self.buildDir + "/" + filename, "w", "utf-8") as f:
            f.write(bootHtml)

        return buildutil.getContentHash(bootHtml)