Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit length of slug #11

Closed
h4cc opened this issue Dec 4, 2015 · 3 comments
Closed

Limit length of slug #11

h4cc opened this issue Dec 4, 2015 · 3 comments

Comments

@h4cc
Copy link
Owner

h4cc commented Dec 4, 2015

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

@h4cc h4cc mentioned this issue Dec 5, 2015
fahrradflucht added a commit to fahrradflucht/slugger that referenced this issue Jul 17, 2016
truncate_slug/3 takes a slug like the ones that get generated by slugify/2 and a maximum_length and enforces that maximum length on the slug.

I bumped the Elixir version since I used to_charlist which is the successor of the softdeprecated to_char_list, but is not available in Elixir 1.0.

Fixes h4cc#11
@fahrradflucht
Copy link
Contributor

fahrradflucht commented Jul 17, 2016

I tried to implement this but, I just read that you wrote:

with and without breaking inside a slugged word.

My implementation atm only does the latter.

That aside I came here to ask whether I should bump the Elixir version (like I did) and use to_charlist or if I should use to_char_list which is soft-deprecated since 1.3.0 to maintain support for 1.0 (I don't actually know in which version to_charlist has been implemented but it isn't there in 1.0 and it's there in 1.3).

Edit: Now that I think about it, bumping the Elixir version should probably include bumping it in .travis.yml

@fahrradflucht
Copy link
Contributor

fahrradflucht commented Jul 19, 2016

I have done a second commit on my branch that adds an option to handle both cases (with or without breaking inside a slugged word) and cleans the whole thing up a bit.

Now a primarily need feedback regarding that Elixir version/to_charlist thing.

fahrradflucht added a commit to fahrradflucht/slugger that referenced this issue Aug 16, 2016
truncate_slug/3 takes a slug like the ones that get generated by slugify/2 and a maximum_length and enforces that maximum length on the slug.

I bumped the Elixir version since I used to_charlist which is the successor of the softdeprecated to_char_list, but is not available in Elixir 1.0.

Fixes h4cc#11
@h4cc h4cc closed this as completed in #19 Jun 1, 2017
@h4cc
Copy link
Owner Author

h4cc commented Jun 1, 2017

I added some tests that show some behaviour that might not be intended:

    assert Slugger.truncate_slug("a-b-c", 10) == "a-b-c"
    assert Slugger.truncate_slug("a-b-c", 5) == "a-b-c"
    assert Slugger.truncate_slug("a-b-c", 4) == "a-b"
    assert Slugger.truncate_slug("a-b-c", 3) == "a-b"
    assert Slugger.truncate_slug("a-b-c", 2) == "a"
    assert Slugger.truncate_slug("a-b-c", 1) == "a"
    assert Slugger.truncate_slug("a-b-c", 0) == ""
    assert Slugger.truncate_slug("a-b-c", -1) == "c"
    assert Slugger.truncate_slug("a-b-c", -2) == ""
    assert Slugger.truncate_slug("a-b-c", -3) == ""
    assert Slugger.truncate_slug("a-b-c", -4) == "b"
    assert Slugger.truncate_slug("a-b-c", -5) == "-b"

I assume that max_length < 1 should be "".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants