Files
sm-user-plugin/models/slug.go
Jakub Zych 58595fef27 feat: Organisations admin screen with the avatar and the members manager
- controller golem15.user.organisations behind golem15.users.access_users
- list and form (name, slug preset from the name, description, avatar)
- members relation manager: link sets and unlink clears users.organisation_id
- deleting an organisation releases its members first
- Organisation gains Fillable, Rules, MorphName, AttachRelations, BeforeValidate
  and the Members relation; models.Slugify
- navigation side item organisations
- TestAdminOrganisations, TestAdminOrganisationMembers, TestSlugify
2026-10-05 13:58:54 +02:00

27 lines
725 B
Go

package models
import "strings"
// Slugify turns text into a slug by the rule the admin form's slug preset
// uses: lower-case ASCII letters and digits are kept, every run of other
// characters becomes one hyphen, and there is no hyphen at either end.
// Letters outside ASCII are not transliterated; they count as other
// characters. A text without a letter or digit gives the empty string.
func Slugify(text string) string {
var b strings.Builder
b.Grow(len(text))
gap := false
for _, r := range strings.ToLower(text) {
if (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') {
if gap && b.Len() > 0 {
b.WriteByte('-')
}
gap = false
b.WriteRune(r)
continue
}
gap = true
}
return b.String()
}