def __init__(self, profile, project=None): # Figuring out main project session = profile.getSession() main = project or session.getMain() self.__profile = profile self.__session = session self.__locales = {} self.__commandReplacer = [] self.__id = 0 self.__cache = main.getCache() # Importing configuration from project self.config = main.getConfigValue("konstrukteur") self.__siteName = main.getConfigValue("konstrukteur.site.name", "Test website") self.__siteUrl = main.getConfigValue("konstrukteur.site.url", "//localhost") self.__pageUrl = main.getConfigValue("konstrukteur.pageUrl", "{{slug}}.{{language}}.html") self.__postUrl = main.getConfigValue("konstrukteur.blog.postUrl", "blog/{{date-monthly}}/{{slug}}.{{language}}.html") self.__archiveUrl = main.getConfigValue("konstrukteur.blog.archiveUrl", "blog/archive-{{pageno}}.{{language}}.html") self.__feedUrl = main.getConfigValue("konstrukteur.blog.feedUrl", "feed.{{language}}.xml") self.__feedLength = main.getConfigValue("konstrukteur.blog.itemsInFeed", 10) self.__archivePageLength = main.getConfigValue("konstrukteur.blog.postsPerArchivePage", 10) self.__extensions = main.getConfigValue("konstrukteur.extensions", ["markdown", "html"]) self.__theme = main.getConfigValue("konstrukteur.theme", main.getName()) self.__defaultLanguage = main.getConfigValue("konstrukteur.defaultLanguage", "en") self.__fileManager = FileManager.FileManager(self.__profile)
def build(regenerate, profile): """ Build static website """ if regenerate: session.pause() app = Konstrukteur() app.config = session.getMain().getConfigValue("konstrukteur") app.sitename = session.getMain().getConfigValue("konstrukteur.site.name", "Test website") app.siteurl = session.getMain().getConfigValue("konstrukteur.site.url", "//localhost") app.posturl = session.getMain().getConfigValue("konstrukteur.blog.postUrl", "{{current.lang}}/blog/{{current.slug}}") app.pageurl = session.getMain().getConfigValue("konstrukteur.pageUrl", "{{current.lang}}/{{current.slug}}") app.feedurl = session.getMain().getConfigValue("konstrukteur.blog.feedUrl", "feed.{{current.lang}}.xml") app.extensions = session.getMain().getConfigValue("konstrukteur.extensions", ["markdown", "html"]) app.theme = session.getMain().getConfigValue("konstrukteur.theme", session.getMain().getName()) app.defaultLanguage = session.getMain().getConfigValue("konstrukteur.defaultLanguage", "en") app.regenerate = not regenerate == False app.build(profile) if regenerate: session.resume()
def addBuildProfile(self, urlPrefix="asset", override=False): # First create a new profile with optional (CDN-) URL prefix profileId = self.addProfile("build", urlPrefix) # Then export all relative paths to main project and add this to the runtime data main = session.getMain() assets = self.__assets data = self.__data for fileId in assets: if not fileId in data: data[fileId] = {} if override or not "p" in data[fileId]: data[fileId]["p"] = profileId
def __generateArchiveData(self): pages = [] main = session.getMain() itemsPerPage = main.getConfigValue("konstrukteur.blog.archiveItemsPerPage", 10) title = main.getConfigValue("konstrukteur.blog.archive.title", "Index {{pageno}}") # If there is just one title, map the title for each language # This is mainly for simplified access later on if not isinstance(title, dict): titleMap = {} for language in self.__languages: titleMap[language] = title title = titleMap # Produce archive pages for each language for language in self.__languages: archiveTitle = title[language] sortedPosts = self.__getSortedPosts(language) pos = 0 pageno = 1 while pos < len(sortedPosts): archiveTitle = Util.replaceFields(archiveTitle, { "pageno" : pageno, "lang" : language }) archivePage = { "slug" : "archive-%d" % pageno, "title" : archiveTitle, "posts" : sortedPosts[pos:itemsPerPage + pos], "pageno" : pageno, "mtime" : None, # Fully generated content "lang" : language } pages.append(archivePage) pageno += 1 pos += itemsPerPage return pages
def addSourceProfile(self, urlPrefix="", override=False): # First create a new profile with optional (CDN-) URL prefix profileId = self.addProfile("source", urlPrefix) # Then export all relative paths to main project and add this to the runtime data main = session.getMain() assets = self.index() data = self.__data for fileId in assets: if not fileId in data: data[fileId] = {} if override or not "p" in data[fileId]: data[fileId]["p"] = profileId data[fileId]["u"] = main.toRelativeUrl(assets[fileId].getPath())
def storeLoader(classes, fileName, bootCode="", urlPrefix=""): """ Generates a source loader which is basically a file which loads the original JavaScript files. This is super useful during development of a project as it supports pretty fast workflows where most often a simple reload in the browser is enough to get the newest sources. - classes: List of sorted classes to compress - fileName: Filename to write result to - bootCode: Code to execute once all classes have been loaded - urlPrefix: Prepends the given URL prefix to all class URLs to load """ info("Generating loader for %s classes...", len(classes)) indent() main = session.getMain() files = [] for classObj in classes: path = classObj.getPath() # Support for multi path classes # (typically in projects with custom layout/structure e.g. 3rd party) if type(path) is list: for singleFileName in path: files.append(main.toRelativeUrl(singleFileName, urlPrefix)) else: files.append(main.toRelativeUrl(path, urlPrefix)) loader = '"%s"' % '","'.join(files) result = [] outdent() assetData = assetManager.export(classes) if assetData: assetCode = 'core.io.Asset.addData(%s);' % assetData result.append(packCode(assetCode)) wrappedBootCode = "function(){%s}" % bootCode if bootCode else "null" loaderCode = 'core.io.Queue.load([%s], %s, null, true);' % (loader, wrappedBootCode) result.append(packCode(loaderCode)) writeFile(fileName, "".join(result))
def create(name="myproject", origin=None, skeleton=None, **argv): """Creates a new project""" header("Creating project %s" % name) if not validProjectName.match(name): raise JasyError("Invalid project name: %s" % name) # # Initial Checks # # Figuring out destination folder destinationPath = os.path.abspath(name) if os.path.exists(destinationPath): raise JasyError("Cannot create project in %s. File or folder exists!" % destinationPath) # Origin can be either: # 1) None, which means a skeleton from the current main project # 2) An repository URL # 3) A project name known inside the current session # 4) Relative or absolute folder path if origin is None: originProject = session.getMain() if originProject is None: raise JasyError("Auto discovery failed! No Jasy projects registered!") originPath = originProject.getPath() originName = originProject.getName() elif isRepository(origin): info("Using remote skeleton") tempDirectory = tempfile.TemporaryDirectory() originPath = os.path.join(tempDirectory.name, "clone") originUrl = origin originVersion = getKey(argv, "origin-version") indent() originRevision = updateRepository(originUrl, originVersion, originPath) outdent() if originRevision is None: raise JasyError("Could not clone origin repository!") debug("Cloned revision: %s" % originRevision) originProject = getProjectFromPath(originPath) originName = originProject.getName() else: originProject = session.getProjectByName(origin) if originProject is not None: originPath = originProject.getPath() originName = origin elif os.path.isdir(origin): originPath = origin originProject = getProjectFromPath(originPath) originName = originProject.getName() else: raise JasyError("Invalid value for origin: %s" % origin) # Figure out the skeleton root folder skeletonDir = os.path.join(originPath, originProject.getConfigValue("skeletonDir", "skeleton")) if not os.path.isdir(skeletonDir): raise JasyError("The project %s offers no skeletons!" % originName) # For convenience: Use first skeleton in skeleton folder if no other selection was applied if skeleton is None: skeleton = getFirstSubFolder(skeletonDir) # Finally we have the skeleton path (the root folder to copy for our app) skeletonPath = os.path.join(skeletonDir, skeleton) if not os.path.isdir(skeletonPath): raise JasyError('Skeleton %s does not exist in project "%s"' % (skeleton, originName)) # # Actual Work # # Prechecks done info( "Creating %s from %s %s...", colorize(name, "bold"), colorize(skeleton + " @", "bold"), colorize(originName, "magenta"), ) debug("Skeleton: %s", colorize(skeletonPath, "grey")) debug("Destination: %s", colorize(destinationPath, "grey")) # Copying files to destination info("Copying files...") shutil.copytree(skeletonPath, destinationPath) debug("Files were copied successfully.") # Build data for template substitution data = {} data.update(argv) data["name"] = name data["origin"] = originName data["skeleton"] = os.path.basename(skeletonPath) data["jasy"] = jasy.__version__ # Do actual replacement of placeholders massFilePatcher(destinationPath, data) debug("Files were patched successfully.") # Change to directory before continuing os.chdir(destinationPath) # Create configuration file from question configs and custom scripts info("Starting configuration...") config = Config() config.injectValues(**argv) config.readQuestions("jasycreate", optional=True) config.executeScript("jasycreate.py", optional=True) config.write("jasyscript.yaml") # Done info("Your application %s was created successfully!", colorize(name, "bold"))
def __init__(self): self.__locale = {} self.__commandReplacer = [] self.__id = 0 self.__templates = {} self.__cache = session.getMain().getCache()