summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVal Neekman <val@neekware.com>2013-04-24 10:27:06 -0400
committerVal Neekman <val@neekware.com>2013-04-24 10:27:06 -0400
commite951142f77402cd4e0bdca69ea4aea5bb466c310 (patch)
tree26369e90d4a53ac5ff6807ef4833ff16a4a8e4a3
parenta4c78fab0157d7da3ed77ca8b2f98cd0dbac5bf2 (diff)
downloadpython-slugify-e951142f77402cd4e0bdca69ea4aea5bb466c310.tar.gz
added non-dash separator option0.0.4
-rw-r--r--README.md15
-rwxr-xr-xsetup.py2
-rw-r--r--slugify/__init__.py7
-rw-r--r--test.py8
4 files changed, 27 insertions, 5 deletions
diff --git a/README.md b/README.md
index 51c2f32..0004eb8 100644
--- a/README.md
+++ b/README.md
@@ -75,6 +75,13 @@ How to use
r = slugify(txt, max_length=20, word_boundary=True)
self.assertEquals(r, "jaja-lol-mememeoo-a")
+ txt = 'jaja---lol-méméméoo--a'
+ r = slugify(txt, max_length=20, word_boundary=True, separator=".")
+ self.assertEquals(r, "jaja.lol.mememeoo.a")
+
+ txt = 'jaja---lol-méméméoo--a'
+ r = slugify(txt, max_length=20, word_boundary=True, separator="ZZZZZZ")
+ self.assertEquals(r, "jajaZZZZZZlolZZZZZZmememeooZZZZZZa")
Running the tests
=================
@@ -86,9 +93,13 @@ To run the tests against the current environment:
Changelog
=========
+0.0.4
+-----
+* Added option to add a non-dash separator (feature request by: danilodimoia)
+
0.0.3
-----
-* Added the ability to truncate slugs + tests (viva Juan Riaza of Spain)
+* Added the ability to truncate slugs + tests (feature request by: Juan Riaza of Spain)
0.0.2
-----
@@ -103,7 +114,7 @@ Changelog
License
=======
-Copyright © Val Neekman
+Copyright © Val Neekman (Neekware Inc.)
All rights reserved.
diff --git a/setup.py b/setup.py
index e2df292..509282f 100755
--- a/setup.py
+++ b/setup.py
@@ -16,7 +16,7 @@ author_email = 'info@neekware.com'
license = 'BSD'
install_requires = ['Unidecode>=0.04.9']
classifiers = [
- 'Development Status :: 3 - Alpha',
+ 'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX',
diff --git a/slugify/__init__.py b/slugify/__init__.py
index 8d0295a..f8de605 100644
--- a/slugify/__init__.py
+++ b/slugify/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-__version__ = '0.0.3'
+__version__ = '0.0.4'
__all__ = ['slugify']
@@ -38,7 +38,7 @@ def smart_truncate(text, max_length=0, word_boundaries=False):
return truncated.strip('-')
-def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, word_boundary=False):
+def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, word_boundary=False, separator='-'):
""" Make a slug from the given text """
# text to unicode
@@ -83,6 +83,9 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
if max_length > 0:
text = smart_truncate(text, max_length, word_boundary)
+ if separator != '-':
+ text = text.replace('-', separator)
+
return text
diff --git a/test.py b/test.py
index c279a33..13f5a85 100644
--- a/test.py
+++ b/test.py
@@ -55,6 +55,14 @@ class TestSequenceFunctions(unittest.TestCase):
r = slugify(txt, max_length=20, word_boundary=True)
self.assertEquals(r, "jaja-lol-mememeoo-a")
+ txt = 'jaja---lol-méméméoo--a'
+ r = slugify(txt, max_length=20, word_boundary=True, separator=".")
+ self.assertEquals(r, "jaja.lol.mememeoo.a")
+
+ txt = 'jaja---lol-méméméoo--a'
+ r = slugify(txt, max_length=20, word_boundary=True, separator="ZZZZZZ")
+ self.assertEquals(r, "jajaZZZZZZlolZZZZZZmememeooZZZZZZa")
+
if __name__ == '__main__':
unittest.main()