Skip to content

Commit

Permalink
Create new meta files in nikola theme -n
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 14, 2017
1 parent 19891cc commit 2ed1988
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions nikola/plugins/command/theme.py
Expand Up @@ -32,6 +32,7 @@
import shutil
import time
import requests
import configparser

import pygments
from pygments.lexers import PythonLexer
Expand Down Expand Up @@ -326,9 +327,7 @@ def new_theme(self, name, engine, parent):
LOGGER.info("Created directory {0}".format(base))

# Check if engine and parent match
engine_file = utils.get_asset_path('engine', utils.get_theme_chain(parent, self.site.themes_dirs))
with io.open(engine_file, 'r', encoding='utf-8') as fh:
parent_engine = fh.read().strip()
parent_engine = utils.get_template_engine(utils.get_theme_chain(parent, self.site.themes_dirs))

if parent_engine != engine:
LOGGER.error("Cannot use engine {0} because parent theme '{1}' uses {2}".format(engine, parent, parent_engine))
Expand All @@ -342,12 +341,16 @@ def new_theme(self, name, engine, parent):
LOGGER.error("Theme already exists")
return 2

with io.open(os.path.join(themedir, 'parent'), 'w', encoding='utf-8') as fh:
fh.write(parent + '\n')
LOGGER.info("Created file {0}".format(os.path.join(themedir, 'parent')))
with io.open(os.path.join(themedir, 'engine'), 'w', encoding='utf-8') as fh:
fh.write(engine + '\n')
LOGGER.info("Created file {0}".format(os.path.join(themedir, 'engine')))
cp = configparser.ConfigParser()
cp['Theme'] = {
'engine': engine,
'parent': parent
}

theme_meta_path = os.path.join(themedir, name + '.theme')
with io.open(theme_meta_path, 'w', encoding='utf-8') as fh:
cp.write(fh)
LOGGER.info("Created file {0}".format(theme_meta_path))

LOGGER.info("Theme {0} created successfully.".format(themedir))
LOGGER.notice('Remember to set THEME="{0}" in conf.py to use this theme.'.format(name))
Expand Down

0 comments on commit 2ed1988

Please sign in to comment.