Skip to content

Instantly share code, notes, and snippets.

@forficate
Created February 25, 2013 22:19
Show Gist options
  • Save forficate/5033866 to your computer and use it in GitHub Desktop.
Save forficate/5033866 to your computer and use it in GitHub Desktop.
Drupal input filters in scala for play framework
abstract trait InputFormat {
def format(source: String): String
}
object LineBreakFormatter extends InputFormat {
def format(source: String) = source.replaceAll("\n", "<br/>")
}
object HtmlEscapeFormatter extends InputFormat {
def format(source: String) = play.api.templates.HtmlFormat.escape(source).body
}
object InputFormats {
private val formaters = HtmlEscapeFormatter :: LineBreakFormatter :: Nil
def format(source: String) = formaters.foldLeft(source)((result, formatter) => formatter.format(result))
}
//Example template useage: @Html(InputFormats.format(content))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment