Giter Club home page Giter Club logo

slugger's People

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  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  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  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  avatar  avatar

slugger's Issues

Limit length of slug

Provide a way to limit the length, with and without breaking inside a slugged word.

Unique slug?

I'm using slugger to create a unique slug for some model.

I've implemented a function in my own app to handle this, where you give a function as parameter that can answer if the given slug is unique. If function returns falsy, it will try a new slug of the form "#{slug}-#{counter}".

Is this in the scope of Slugger? If so I will be happy to make a PR.

e.g.:

article_name = "slugs are unique"
Slugger.slugify(name, fn(slug) -> Repo.unique_slug?(slug) end)
# => "slugs-are-unique-7"

One could imagine other (more performant) ways of finding the next slug for a given name, so this might not be general enough to include in a general slugging tool?

Breaking changes in 0.3

It looks like there's some breaking changes in 0.3. I haven't looked into them too fully yet but some of my tests are now breaking. Here's an example FunctionClauseError I'm getting.

     ** (FunctionClauseError) no function clause matching in Regex.replace/4

     The following arguments were given to Regex.replace/4:

         # 1
         ~r/['’]s/u

         # 2
         nil

         # 3
         "s"

         # 4
         [global: nil]

     Attempted function clauses (showing 2 out of 2):

         def replace(regex, string, replacement, options) when is_binary(string) and is_binary(replacement) and is_list(options)
         def replace(regex, string, replacement, options) when is_binary(string) and is_function(replacement) and is_list(options)

     code: conn = post conn, api_community_path(conn, :create), %{community: community_params}
     stacktrace:
       (elixir) lib/regex.ex:595: Regex.replace/4
       (slugger) lib/slugger.ex:40: Slugger.slugify/2

Is there any documentation of the breaking changes?

Fix deprecation warnings

There are some deprecation warnings coming from lib/slugger.ex; looks like mostly simple things (Kernel.to_char_list/1 is deprecated, String.strip/2 is deprecated, etc.).

I know it's a bit weird but I really like having clean output (and especially having no warnings). Would you be open to a PR that fixes them?

Custom config settings doesn't work

Hi,
New to elixir so maybe i'm doing something wrong but this is what i've tried:

# config.exs
config :slugger, separator_char: ?_
config :slugger, replacement_file: "lib/myapp/replacements.exs"

Then mix compile try my new settings with iex -S phoenix.server -> Slugger.slugify("A b C") # still "A-b-C"

Also, is lib/myapp/* the right dir to place the replacement file in? (it doesn't pick up my changes)

Handle `'s ` specially?

I'm calling String.replace(string, ~r/['’]s\s/u, "s ") before passing the string to Slugger, because otherwise possessives look odd to me.

"Sheep's Milk"
|> Slugger.slugify_downcase() # => "sheep-s-milk" 🤔


"Sheep's Milk"
|> String.replace(~r/['’]s\s/u, "s ")
|> Slugger.slugify_downcase() # => "sheeps-milk" 😀

Is this something you think is worth changing in Slugger itself? (Maybe not, because it's multilingual?)

Feel free to 👎 and move on if you don't care to have this. If you want it, let me know and I'll PR.

The “unwanted characters regex” matches wanted characters

Hi!

I found a potential bug in the following line:

|> remove_unwanted_chars(separator, ~r/([^A-Za-z0-9가-힣])+/)

The line replaces all characters that does not match A-Za-z0-9가-힣 with the separator character.

However, we found an unwanted characters that fall under this expression, namely (U+2009).

source = "foo bar" # This is "foo<U+2009>bar"

String.replace(source, ~r/([^a-z0-9가-힣])+/, "-")
# => "foo bar"

String.replace(source, ~r/([^a-z0-9])+/, "-")
# => "foo-bar"

The behavior is the same for the U+2010, U+2011, U+2012, etc. characters.

Add specs.

Create specs so working with dializer will work.

Next release?

Awesome work! I was wondering if you have a plan of doing a new release to hex.pm? 😄

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.