ensure teams have a slug
This commit is contained in:
parent
f2be5e79c2
commit
808ef19c5d
|
@ -3,6 +3,7 @@ package team
|
||||||
|
|
||||||
import user.User
|
import user.User
|
||||||
|
|
||||||
|
import ornicar.scalalib.Random
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import com.novus.salat.annotations.Key
|
import com.novus.salat.annotations.Key
|
||||||
import java.text.Normalizer
|
import java.text.Normalizer
|
||||||
|
@ -44,5 +45,7 @@ object Team {
|
||||||
createdAt = DateTime.now,
|
createdAt = DateTime.now,
|
||||||
createdBy = createdBy.id)
|
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 {
|
trait StringHelper {
|
||||||
|
|
||||||
def slugify(input: String) = {
|
def slugify(input: String) = {
|
||||||
val nowhitespace = input.replace(" ", "-")
|
val nowhitespace = input.trim.replace(" ", "-")
|
||||||
val normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD)
|
val normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD)
|
||||||
val slug = """[^\w-]""".r.replaceAllIn(normalized, "")
|
val slug = """[^\w-]""".r.replaceAllIn(normalized, "")
|
||||||
slug.toLowerCase
|
slug.toLowerCase
|
||||||
|
|
Loading…
Reference in a new issue