Created
February 25, 2013 22:19
-
-
Save forficate/5033866 to your computer and use it in GitHub Desktop.
Drupal input filters in scala for play framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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