Skip to content

Commit

Permalink
pkgindex_compiler: support for theme INI files
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 17, 2017
1 parent c1a23b7 commit 54b2bec
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion v7/pkgindex_compiler/pkgindex_compiler.plugin
Expand Up @@ -8,6 +8,6 @@ MinVersion = 7.8.1+

[Documentation]
Author = Chris Warrick, Roberto Alsina
Version = 0.2.2
Version = 0.3.0
Website = https://plugins.getnikola.com/
Description = Compile pages in package indexes
62 changes: 39 additions & 23 deletions v7/pkgindex_compiler/pkgindex_compiler.py
Expand Up @@ -154,9 +154,13 @@ def parse_theme_info(post, pkg_dir, config):
data['previewimage_thumbnail'] = '/' + demo_dir + '.thumbnail.png'
data['demo_link'] = '/' + demo_dir + '/demo/'
conf_sample = os.path.join(pkg_dir, 'conf.py.sample')
ini = os.path.join(pkg_dir, theme + '.theme')
engine = os.path.join(pkg_dir, 'engine')
parent = os.path.join(pkg_dir, 'parent')

data['chain'] = utils.get_theme_chain(theme, [os.path.dirname(pkg_dir), 'themes'])
data['chain'] = [os.path.basename(i) for i in reversed(data['chain'])]

if os.path.exists(conf_sample):
post.add_dependency(conf_sample)
with io.open(conf_sample, 'r', encoding='utf-8') as f:
Expand All @@ -166,30 +170,42 @@ def parse_theme_info(post, pkg_dir, config):
else:
data['confpy'] = None

if os.path.exists(engine):
post.add_dependency(engine)
with io.open(engine, 'r', encoding='utf-8') as f:
data['engine'] = f.read().strip()
else:
data['engine'] = 'mako'

if os.path.exists(parent):
post.add_dependency(parent)
with io.open(parent, 'r', encoding='utf-8') as f:
data['parent'] = f.read().strip()
elif theme == 'base':
pass
if os.path.exists(ini):
post.add_dependency(ini)
c = configparser.ConfigParser()
c.read(ini)
data['parent'] = c.get('Theme', 'parent', fallback=None)
data['engine'] = c.get('Theme', 'engine', fallback='mako')
data['bootswatch'] = c.getboolean('Nikola', 'bootswatch', fallback=False)
data['tags'] = 'theme,' + data['engine']
theme_tags = c.get('Theme', 'tags', fallback='')
if theme_tags:
data['tags'] += ',' + theme_tags

if data['parent'] is None and theme != 'base':
raise ValueError("Theme {0} has no parent.".format(theme))
else:
raise ValueError("Theme {0} has no parent.".format(theme))

data['chain'] = utils.get_theme_chain(theme, [os.path.dirname(pkg_dir), 'themes'])
data['chain'] = [os.path.basename(i) for i in reversed(data['chain'])]
data['bootswatch'] = (('bootstrap' in data['chain'] or
'bootstrap-jinja' in data['chain'] or
'bootstrap3-jinja' in data['chain'] or
'bootstrap3' in data['chain']) and
'bootstrap3-gradients' not in data['chain'])
data['tags'] = 'theme,' + data['engine']
if os.path.exists(engine):
post.add_dependency(engine)
with io.open(engine, 'r', encoding='utf-8') as f:
data['engine'] = f.read().strip()
else:
data['engine'] = 'mako'

if os.path.exists(parent):
post.add_dependency(parent)
with io.open(parent, 'r', encoding='utf-8') as f:
data['parent'] = f.read().strip()
elif theme == 'base':
pass
else:
raise ValueError("Theme {0} has no parent.".format(theme))
data['bootswatch'] = (('bootstrap' in data['chain'] or
'bootstrap-jinja' in data['chain'] or
'bootstrap3-jinja' in data['chain'] or
'bootstrap3' in data['chain']) and
'bootstrap3-gradients' not in data['chain'])
data['tags'] = 'theme,' + data['engine']

return data

Expand Down

0 comments on commit 54b2bec

Please sign in to comment.