GithubHelp home page GithubHelp logo

cl-slug's Introduction

cl-slug

Quicklisp Build Status Circle CI Coverage Status

Easily create slugs from any string. Supports many languages alphabets. See Supported languages to check for supported languages or to help to add one.

Inspired by Lisp Web Tales.

Usage

* (ql:quickload :cl-slug)
; => (:CL-SLUG)
* (import '(slug:slugify slug:asciify slug:CamelCaseFy))
; => T

The main function is called slugify:

* (slugify "My new cool article, for the blog (V. 2).")
; => "my-new-cool-article-for-the-blog-v-2"
* (slugify "André Miranda")
; => "andre-miranda"

slugify removes any accented character, replacing it with an unaccented equivalent, and any punctuation (a punctuation is a char that returns NIL for alphanumericp) and puts a dash (-) on it's place. You can change that by binding (of setfing) *slug-separator*:

* (let ((*slug-separator* #\_))
    (slugify "Testing the *slug-separator* var..."))
; => "testing_the_slug_separator_var"

slugify also ignores numbers:

* (slugify "one2three4five")
; => "one2three4five"

If you just want to remove accents and punctuation of a given string, use asciify:

* (asciify "Eu André!")
; => "Eu Andre!"

Or if you want a CamelCase, use CamelCaseFy:

* (CamelCaseFy "My new camel case string")
; => "MyNewCamelCaseString"

Available languages are stored in *available-languages*:

* slug:*available-languages*
((:TR . "Türkçe (Turkish)") (:SV . "Svenska (Swedish)") (:FI . "Suomi (Finnish)") 
 (:UK . "українська (Ukrainian)") (:RU . "Ру́сский (Russian)") (:RO . "Română (Romanian)")
 (:RM . "Rumàntsch (Romansh)") (:PT . "Português (Portuguese)") (:PL . "Polski (Polish)")
 (:NO . "Norsk (Norwegian)") (:LT . "Lietuvių (Lithuanian)") (:LV . "Latviešu (Latvian)")
 (:LA . "Lingua Latīna (Latin)") (:IT . "Italiano (Italian)") (:EL . "ελληνικά (Greek)")
 (:FR . "Français (French)") (:EO . "Esperanto") (:ES . "Español (Spanish)") (:EN . "English")
 (:DE . "Deutsch (German)") (:DA . "Dansk (Danish)") (:CS . "Čeština (Czech)")
 (:CURRENCY . "Currency"))

Dependencies

This library depends on CL-PPCRE. The test package uses the prove test library.

Installation

Available on Quicklisp:

(ql:quickload :cl-slug)

Supported languages

The languages that are supported right now are:

  • english
  • portuguese
  • esperanto
  • german
  • french
  • swedish
  • finnish
  • norwegian
  • danish
  • italian
  • spanish
  • romansh

Ported from Django():

  • currency
  • romanian
  • lithuanian
  • latvian
  • polish
  • czesh
  • ukranian
  • russian
  • turkish
  • greek
  • latin

At the present moment, adding new languages is a fairly manual process:

  1. Identify non-ASCII characters in a given language's alphabet
  2. Establish equivalence between the found characters and ASCII characters
  3. Write them down in the code.

All those things can actually be done for most of the dominant Western languages, but can't be applied for minor regional languages or many other non-Latin languages from the whole world, like Chinese. It's not generic and not scalable.

I couldn't think of a solution so far for this, but if you know a solution (even a partial one) I'd be glad to hear =].

Bugs

If you find any bug or inconsistency in the code, or if you find it too hard to use, please, feel free to open an issue.

Tests

This library is tested under ABCL, SBCL, CCL, CLISP and ECL Common Lisp implementations.

To run all the defined tests, use:

* (asdf:test-system :cl-slug)
; prints lots of (colorful) stuff...
; => T

Tests are ran with Travis CI and Circle CI using cl-travis, CIM, cl-coveralls and Roswell. Check it out!

Author

André Miranda.

License

LLGPL.

cl-slug's People

Contributors

euandreh avatar kmasubhani avatar sjl avatar varjagg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.