Skip to content
Permalink
Browse files
Add TOML to the data feature
  • Loading branch information
ralsina committed Aug 22, 2016
1 parent 6ff537f commit 3bd89b7300c398b3260a71eaf63305693bd8061a
Showing with 13 additions and 4 deletions.
  1. +13 −4 nikola/utils.py
@@ -56,6 +56,10 @@
from urllib.parse import urlparse, urlunparse # NOQA
import warnings
import PyRSS2Gen as rss
try:
import pytoml as toml
except ImportError:
toml = None
try:
import yaml
except ImportError:
@@ -1920,11 +1924,16 @@ def load_data(path):
"""Given path to a file, load data from it."""
ext = os.path.splitext(path)[-1]
if ext in {'.yml', '.yaml'}:
loader = yaml
if yaml is None:
req_missing(['yaml'], 'use YAML data files')
return {}
with io.open(path, 'r', encoding='utf8') as inf:
return yaml.load(inf)
elif ext in {'.json', '.js'}:
with io.open(path, 'r', encoding='utf8') as inf:
return json.load(inf)
loader = json
elif ext in {'.toml', '.tml'}:
if toml is None:
req_missing(['yaml'], 'use YAML data files')
return {}
loader = toml
with io.open(path, 'r', encoding='utf8') as inf:
return loader.load(inf)

0 comments on commit 3bd89b7

Please sign in to comment.