Created
October 8, 2010 08:43
-
-
Save guillaumebort/616525 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package controllers | |
import play._ | |
import play.mvc._ | |
import play.libs._ | |
object Application extends Controller { | |
def index = Template | |
def check(text: String) = { | |
val xml = WS.url("https://www.google.com/tbproxy/spell?lang=en&hl=en").body( | |
<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1"> | |
<text>{text}</text> | |
</spellrequest> | |
).post().getXml() | |
val mistakes = xml \\ "c" map { elem => | |
(elem \ "@o", elem \ "@l", elem.text) | |
} | |
Template(mistakes) | |
} | |
} |
This file contains hidden or 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
#{extends 'main.html' /} | |
#{set title:'Result' /} | |
<p id="result"> | |
${text} | |
</p> | |
<script type="text/javascript" charset="utf-8"> | |
var text = $('#result').text().trim(), mistakes = ${mistakes.json()}.reverse, html = '', o = 0, token | |
while(token = mistakes.pop()) { | |
html += text.substring(o, token._1) | |
o = token._1 + token._2 | |
html += '<em>' + text.substring(token._1, o) + '</em>' | |
} | |
html += text.substring(o, text.length) | |
$('#result').html(html) | |
</script> | |
<hr> | |
<a href="@{index()}">Back</a> | |
<style type="text/css" media="screen"> | |
em { | |
color: red; | |
} | |
</style> |
This file contains hidden or 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
#{extends 'main.html' /} | |
#{set title:'Home' /} | |
#{form @check()} | |
<textarea name="text"></textarea> | |
<br> | |
<input type="submit" value="Check!"> | |
#{/form} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment