def sourcesConcatenated(self, locale, moduleName, modulePath): module = self.currentBuild.files[locale][moduleName] if "__styles__" in module: if not "bundled" in self.options or self.options["bundled"]: styles = module["__styles__"].replace("\"", "\\\"").replace( "\n", "\\n") module["__concat__"] += "Modules.%s.css = \"%s\";\n" % ( moduleName, styles) else: try: styles = module["__styles__"] fileName = buildutil.getDestinationFileName( moduleName, None, styles, None, "css") if not os.path.exists( self.buildDir + "/" + fileName ): # avoid multiple locales writing the same file with codecs.open(self.buildDir + "/" + fileName, "w", "utf-8") as f: f.write(styles) module["__output__"].append(fileName) except Exception, exception: raise BuildError( "Could not write CSS output file for module %s" % moduleName, exception)
def writeFiles(self, locale, moduleName, modulePath): print " Writing output file..." module = self.currentBuild.files[locale][moduleName] try: contents = module["__concat__"] filename = buildutil.getDestinationFileName(moduleName, None, contents, locale, "js") with codecs.open(self.buildDir + "/" + filename, "w", "utf-8") as f: f.write(contents) module["__output__"].append(filename) except Exception, exception: raise BuildError("Could not write output file for module %s" % moduleName, exception)
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()
def writeFiles(self, locale, moduleName, modulePath): print " Writing output file..." module = self.currentBuild.files[locale][moduleName] try: contents = module["__concat__"] filename = buildutil.getDestinationFileName( moduleName, None, contents, locale, "js") with codecs.open(self.buildDir + "/" + filename, "w", "utf-8") as f: f.write(contents) module["__output__"].append(filename) except Exception, exception: raise BuildError( "Could not write output file for module %s" % moduleName, exception)
def sourcesConcatenated(self, locale, moduleName, modulePath): module = self.currentBuild.files[locale][moduleName] if "__styles__" in module: if not "bundled" in self.options or self.options["bundled"]: styles = module["__styles__"].replace("\"", "\\\"").replace("\n", "\\n") module["__concat__"] += "Modules.%s.css = \"%s\";\n" % (moduleName, styles) else: try: styles = module["__styles__"] fileName = buildutil.getDestinationFileName(moduleName, None, styles, None, "css") if not os.path.exists(self.buildDir + "/" + fileName): # avoid multiple locales writing the same file with codecs.open(self.buildDir + "/" + fileName, "w", "utf-8") as f: f.write(styles) module["__output__"].append(fileName) except Exception, exception: raise BuildError("Could not write CSS output file for module %s" % moduleName, exception)
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)
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)
def manifestLoaded(self, moduleName, modulePath, manifest): self.rebuildNeeded = False if not "statics" in manifest or len(manifest["statics"]) == 0: return for static in manifest["statics"]: path = self.projectBuilder.resolveFile(static["path"], modulePath + "/statics") mtime = os.stat(path).st_mtime if path in self.timestamps and mtime == self.timestamps[path]: continue self.rebuildNeeded = True self.timestamps[path] = mtime if not self.rebuildNeeded: return print " Copying statics..." for locale in self.projectBuilder.locales: self.currentBuild.files[locale][moduleName]["__staticMap__"] = {} for static in manifest["statics"]: print " %s..." % static["path"] path = self.projectBuilder.resolveFile(static["path"], modulePath + "/statics") (directory, fileName) = os.path.split(path) (baseName, extension) = os.path.splitext(fileName) with open(path, "r") as inFile: content = inFile.read() destFileName = buildutil.getDestinationFileName(moduleName, baseName, content, None, extension, pattern = "{moduleName}{.baseName}{.md5}{.extension}") destPath = self.buildDir + "/" + destFileName if not os.path.exists(destPath): # avoid multiple locales copying the same file with open(destPath, "w") as outFile: outFile.write(content) for locale in self.projectBuilder.locales: self.currentBuild.files[locale][moduleName]["__staticMap__"][static["path"]] = destFileName
def writeVersionFile(self, name, locale, hash): filename = buildutil.getDestinationFileName(name, None, None, locale, "md5") with open(self.buildDir + "/" + filename, "w") as f: f.write(hash)