Exemple #1
0
    def cmd_serve(self):
        project = self.current_project()

        # Check config
        if 'server' in project.config:
            config = project.config['server']
        else:
            exit_with_error("No 'server' section found in '%s'." % self.args.config)

        log.message("Starting server at %s " % 
            datetime.datetime.now().strftime('%d %B %Y - %H:%M:%S'))
        
        # Watch - doesn't lock thread without explicit .join()
        if self.args.watch:
            import docta.utils.watcher as watcher
            watcher.watch(project)

        # Prepare output dir
        output_dir = project.output_dir('html')
        fs.mkdirs(output_dir)

        # Server - runs and locks current thread
        docta.utils.server.run(output_dir,
                               host=config.get('host', None),
                               port=config.get('port', None))
Exemple #2
0
    def render(self):
        out_format = self.out_format
        output_dir = self.project.output_dir(out_format)

        # Prepare output dir
        fs.mkdirs(output_dir)

        # Render chapters
        home = True
        for chapter in self.project.tree:
            self.render_chapter(chapter, home=home)
            home = False  # only the first root chapter is 'home'

        # Copy assets
        self.project.copy_assets(out_format)

        # Copy resources
        self.project.copy_resources(out_format)
Exemple #3
0
    def render_chapter(self, chapter, home=False):
        # print("Render: %s" % str(chapter))
        output_dir = self.project.output_dir(self.out_format)

        # dir for index
        # if chapter.is_index:
        #     # print(fs.path_for_dir(output_dir, chapter.rel_dir_path))
        #     fs.mkdirs(fs.path_for_dir(output_dir, chapter.rel_dir_path))

        # load content - render - flush content
        chapter.load_content()

        if not chapter.content_raw is None:
            out_file_path = fs.join(output_dir, chapter.rel_dir_path,
                                    self.get_html_name(chapter))
            fs.mkdirs(fs.dirname(out_file_path))
            # print(out_file_path)

            if 'template' in chapter.meta:
                template = self.get_template(chapter.meta['template'])
            elif home:
                template = self.get_template('home.html')
            elif chapter.is_index:
                template = self.get_template('index.html')
            else:
                template = self.get_template('page.html')

            with fs.open(out_file_path, 'w') as out_file:
                context = self.template_context(chapter)
                html = template.render(**context)
                out_file.write(html)
        
        chapter.flush_content()

        # render children
        for child in chapter.children:
            self.render_chapter(child)