def cmd_init(self): import docta # Test if dir is empty for name in os.listdir(self.current_dir()): if not name.startswith('.'): command = ' '.join((self.script_name(), self.args.command)) exit_with_error("Current dir is not empty. Please run `%s` in empty dir." % command) # Copy initial project source_dir = fs.real(fs.dirname(docta.__file__)) initial_dir = fs.join(source_dir, 'initial', 'default') fs.cp(initial_dir, self.current_dir())
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)