Skip to content

Commit

Permalink
Warning instead of failing when (un)slugify is called without language.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Mar 6, 2016
1 parent cd17877 commit f5816a8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nikola/utils.py
Expand Up @@ -743,7 +743,7 @@ def remove_file(source):
_slugify_hyphenate_re = re.compile(r'[-\s]+')


def slugify(value, lang, force=False):
def slugify(value, lang=None, force=False):
u"""Normalize string, convert to lowercase, remove non-alpha characters, convert spaces to hyphens.
From Django's "django/template/defaultfilters.py".
Expand All @@ -757,6 +757,8 @@ def slugify(value, lang, force=False):
>>> print(slugify('foo bar', lang='en'))
foo-bar
"""
if lang is None:
LOGGER.warn("slugify() called without language!")
if not isinstance(value, unicode_str):
raise ValueError("Not a unicode object: {0}".format(value))
if USE_SLUGIFY or force:
Expand All @@ -781,12 +783,14 @@ def slugify(value, lang, force=False):
return value


def unslugify(value, lang, discard_numbers=True):
def unslugify(value, lang=None, discard_numbers=True):
"""Given a slug string (as a filename), return a human readable string.
If discard_numbers is True, numbers right at the beginning of input
will be removed.
"""
if lang is None:
LOGGER.warn("unslugify() called without language!")
if discard_numbers:
value = re.sub('^[0-9]+', '', value)
value = re.sub('([_\-\.])', ' ', value)
Expand Down

0 comments on commit f5816a8

Please sign in to comment.