Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add TOML to the data feature
  • Loading branch information
ralsina committed Aug 22, 2016
1 parent 6ff537f commit 3bd89b7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions nikola/utils.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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.