def init(directory='./'): """Init peanut environments """ # copy default config config_path = os.path.join(directory, 'config.yml') if os.path.isfile(config_path): logging.error('Config file %s already exists', config_path) return shutil.copy(get_resource('config.yml'), directory) logging.info('Config file created at %s', config_path, prefix=' ↳ ') # copy default theme assets assets_path = os.path.join(directory, 'assets/') if os.path.isdir(assets_path): logging.error('Asset directory %s alerady exists', assets_path) return shutil.copytree(get_resource('themes/default/assets'), assets_path) logging.info('Asset directory created at %s', assets_path, prefix=' ↳ ') # mkdir draft_path = os.path.join(directory, 'drafts/') if os.path.isdir(draft_path): logging.info('Draft directory already exists', prefix=' ↳ ') return try: os.makedirs(draft_path) except OSError: logging.error('Create draft directory failed') logging.info('Draft directory created at %s', draft_path, prefix=' ↳ ')
def __init__(self, path, filters=None, **kwargs): loader = ChoiceLoader([SmartLoader(path), SmartLoader(get_resource("themes/default"))]) self.env = jinja2.Environment(loader=loader, lstrip_blocks=True, trim_blocks=True) # Update filters if isinstance(filters, dict): self.env.filters.update(filters) # Update global namesapce self.env.globals.update(kwargs)
def __init__(self, path, filters=None, **kwargs): loader = ChoiceLoader([ SmartLoader(path), SmartLoader(get_resource('themes/default')), ]) self.env = jinja2.Environment( loader=loader, lstrip_blocks=True, trim_blocks=True, ) # Update filters if isinstance(filters, dict): self.env.filters.update(filters) # Update global namesapce self.env.globals.update(kwargs)