h4cc / slugger Goto Github PK
View Code? Open in Web Editor NEWA Slugger for elixir.
License: MIT License
A Slugger for elixir.
License: MIT License
I recommend a look at https://github.com/simov/slugify/blob/master/lib/slugify.js
for symbol and currency conversion.
Provide a way to limit the length, with and without breaking inside a slugged word.
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?
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?
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?
Hi, thanks for the awesome package.
Is there any chance to link ecto_autoslug_field
from this package's readme
since ecto_autoslug_field
is built on top of the slugger
?
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)
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.
ö
is not included in Turkish so it uses German ö
which translates as oe
. It should be o
.
This returns invalid string binaries when the string contains an emoji:
Slugger.slugify_downcase("Hi!")
# => "hi"
Slugger.slugify_downcase("Hi! 👋")
# => <<104, 105, 45, 159, 145, 139>>
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.
How about using the fixture testdata from here?
https://github.com/javiereguiluz/EasySlugger/tree/master/tests/fixtures
@javiereguiluz Would that be a problem for you?
Create specs so working with dializer will work.
Awesome work! I was wondering if you have a plan of doing a new release to hex.pm? 😄
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.