ensure teams have a slug
parent
f2be5e79c2
commit
808ef19c5d
|
@ -3,6 +3,7 @@ package team
|
|||
|
||||
import user.User
|
||||
|
||||
import ornicar.scalalib.Random
|
||||
import org.joda.time.DateTime
|
||||
import com.novus.salat.annotations.Key
|
||||
import java.text.Normalizer
|
||||
|
@ -44,5 +45,7 @@ object Team {
|
|||
createdAt = DateTime.now,
|
||||
createdBy = createdBy.id)
|
||||
|
||||
def nameToId(name: String) = templating.StringHelper slugify name
|
||||
def nameToId(name: String) = (templating.StringHelper slugify name) |> { slug ⇒
|
||||
slug.isEmpty.fold(Random nextString 8, slug)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ object StringHelper extends StringHelper
|
|||
trait StringHelper {
|
||||
|
||||
def slugify(input: String) = {
|
||||
val nowhitespace = input.replace(" ", "-")
|
||||
val nowhitespace = input.trim.replace(" ", "-")
|
||||
val normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD)
|
||||
val slug = """[^\w-]""".r.replaceAllIn(normalized, "")
|
||||
slug.toLowerCase
|
||||
|
|
Loading…
Reference in New Issue