def _render_with(self, engine, output_dir, template, output_path): """Render the bundle into the output directory.""" # If there is a template and path, render it if template and output_path: plugins = {} for p in engine.template_plugins: plugins[p.name] = p(engine) ctx = {} ctx.update(engine.context) ctx.update({ 'bundle': self, 'meta': self.meta, 'engine': engine, 'config': engine.config, 'bundles': engine.bundles.values(), 'plugins': plugins, }) r = template.render(ctx) output_path = self._finalize_output_path(output_dir, output_path) with open(output_path, 'wb') as out: out.write(r.encode('utf8')) yield 'render', output_path else: # If nothing to render, allow the bundle to copy content action = os.symlink if engine.config['debug'] else shutil.copy action_log = 'link' if engine.config['debug'] else 'copy' for input_dir, directory, filename in self._to_copy(engine): src_path = os.path.join(input_dir, directory, filename) dest_path = os.path.join(output_dir, directory, filename) ensure_path(os.path.dirname(dest_path)) if os.path.exists(dest_path): os.unlink(dest_path) action(src_path, dest_path) yield action_log, dest_path
def _finalize_output_path(self, output_dir, output_path): output_path = os.path.join(output_dir, output_path) ensure_path(os.path.dirname(output_path)) if os.path.exists(output_path) and os.path.isdir(output_path): output_path = os.path.join(output_path, 'index.html') return output_path
def _finalize_output_path(self, *a, **kw): path = super(Collection, self)._finalize_output_path(*a, **kw) if not path.endswith('index.html') and not path.endswith('atom.xml'): ensure_path(path) path = os.path.join(path, 'index.html') return path