diff --git a/src/main/scala/view/helpers.scala b/src/main/scala/view/helpers.scala index ede7dc9..b5b76ea 100644 --- a/src/main/scala/view/helpers.scala +++ b/src/main/scala/view/helpers.scala @@ -9,12 +9,12 @@ * Provides helper methods for Twirl templates. */ object helpers extends AvatarImageProvider with LinkConverter with RequestCache { - + /** * Format java.util.Date to "yyyy-MM-dd HH:mm:ss". */ def datetime(date: Date): String = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date) - + /** * Format java.util.Date to "yyyy-MM-dd". */ @@ -57,13 +57,21 @@ value } + import scala.util.matching.Regex + import scala.util.matching.Regex._ + implicit class RegexReplaceString(s: String) { + def replaceAll(pattern: String, replacer: (Match) => String): String = { + pattern.r.replaceAllIn(s, replacer) + } + } + def activityMessage(message: String)(implicit context: app.Context): Html = Html(message .replaceAll("\\[issue:([^\\s]+?)/([^\\s]+?)#((\\d+))\\]" , s"""$$1/$$2#$$3""") .replaceAll("\\[pullreq:([^\\s]+?)/([^\\s]+?)#((\\d+))\\]" , s"""$$1/$$2#$$3""") .replaceAll("\\[repo:([^\\s]+?)/([^\\s]+?)\\]" , s"""$$1/$$2""") - .replaceAll("\\[branch:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]", s"""$$3""") - .replaceAll("\\[tag:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]" , s"""$$3""") + .replaceAll("\\[branch:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]", (m: Match) => s"""${m.group(3)}""") + .replaceAll("\\[tag:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]" , (m: Match) => s"""${m.group(3)}""") .replaceAll("\\[user:([^\\s]+?)\\]" , s"""$$1""") )