Skip to content
Permalink
Browse files

Add support for theme meta files (#2758)

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information...
Kwpolska committed May 14, 2017
1 parent 3270735 commit 19891cc0170f4b2040e13a47e4cbd94755441358
@@ -0,0 +1,10 @@
[Theme]
engine = jinja
parent = base
author = The Nikola Contributors
author_url = https://getnikola.com/
license = MIT

[Family]
family = base
mako_version = base

This file was deleted.

This file was deleted.

@@ -0,0 +1,9 @@
[Theme]
engine = mako
author = The Nikola Contributors
author_url = https://getnikola.com/
license = MIT

[Family]
family = base
jinja_version = base-jinja

This file was deleted.

@@ -0,0 +1,13 @@
[Theme]
engine = jinja
parent = base-jinja
author = The Nikola Contributors
author_url = https://getnikola.com/
based_on = Bootstrap 3 <http://getbootstrap.com/>
license = MIT
tags = bootstrap

[Family]
family = bootstrap3
mako_version = bootstrap3
variants = bootstrap3-gradients, bootstrap3-gradients-jinja

This file was deleted.

This file was deleted.

@@ -0,0 +1,13 @@
[Theme]
engine = mako
parent = base
author = The Nikola Contributors
author_url = https://getnikola.com/
based_on = Bootstrap 3 <http://getbootstrap.com/>
license = MIT
tags = bootstrap

[Family]
family = bootstrap3
jinja_version = bootstrap3-jinja
variants = bootstrap3-gradients, bootstrap3-gradients-jinja

This file was deleted.

This file was deleted.

@@ -2267,6 +2267,9 @@ def generic_page_renderer(self, lang, post, filters, context=None):
deps = post.deps(lang)
uptodate_deps = post.deps_uptodate(lang)
deps.extend(utils.get_asset_path(x, self.THEMES) for x in ('bundles', 'parent', 'engine'))
_theme_ini = utils.get_asset_path(self.config['THEME'] + '.theme', self.THEMES)
if _theme_ini:
deps.append(_theme_ini)

context = copy(context) if context else {}
context['post'] = post
@@ -28,6 +28,7 @@

from __future__ import print_function, unicode_literals, absolute_import
import calendar
import configparser
import datetime
import dateutil.tz
import hashlib
@@ -607,27 +608,52 @@ def get_theme_path(theme):
return theme


def parse_theme_meta(theme_dir):
"""Parse a .theme meta file."""
cp = configparser.ConfigParser()
# The `or` case is in case theme_dir ends with a trailing slash
theme_name = os.path.basename(theme_dir) or os.path.basename(os.path.dirname(theme_dir))
theme_meta_path = os.path.join(theme_dir, theme_name + '.theme')
cp.read(theme_meta_path)
return cp if cp.has_section('Theme') else None


def get_template_engine(themes):
"""Get template engine used by a given theme."""
for theme_name in themes:
engine_path = os.path.join(theme_name, 'engine')
if os.path.isfile(engine_path):
with open(engine_path) as fd:
return fd.readlines()[0].strip()
# default
return 'mako'
meta = parse_theme_meta(theme_name)
if meta:
e = meta.get('Theme', 'engine', fallback=None)
if e:
return e
else:
# Theme still uses old-style parent/engine files
engine_path = os.path.join(theme_name, 'engine')
if os.path.isfile(engine_path):
with open(engine_path) as fd:
return fd.readlines()[0].strip()
# default
return 'mako'


def get_parent_theme_name(theme_name, themes_dirs=None):
"""Get name of parent theme."""
parent_path = os.path.join(theme_name, 'parent')
if os.path.isfile(parent_path):
with open(parent_path) as fd:
parent = fd.readlines()[0].strip()
if themes_dirs:
meta = parse_theme_meta(theme_name)
if meta:
parent = meta.get('Theme', 'parent', fallback=None)
if themes_dirs and parent:
return get_theme_path_real(parent, themes_dirs)
return parent
return None
else:
# Theme still uses old-style parent/engine files
parent_path = os.path.join(theme_name, 'parent')
if os.path.isfile(parent_path):
with open(parent_path) as fd:
parent = fd.readlines()[0].strip()
if themes_dirs:
return get_theme_path_real(parent, themes_dirs)
return parent
return None


def get_theme_chain(theme, themes_dirs):

0 comments on commit 19891cc

Please sign in to comment.
You can’t perform that action at this time.