Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial Dancer app + JS/HTML

  • Loading branch information...
commit ac56e61e52e37da80a0b64678452a080d32df195 1 parent 2d5b40b
@ctfliblime authored
View
34 app.psgi
@@ -0,0 +1,34 @@
+use 5.10.0;
+use warnings;
+use strict;
+
+use Xape::Enumerator;
+use Method::Signatures;
+use Dancer;
+use Dancer::Plugin::Ajax;
+
+get '/' => sub {
+ send_file 'index.html';
+};
+
+func get_enum_from_text(Str $phrase, Str $language) {
+ my $e = Xape::Enumerator->new($language);
+ my $enum = $e->sum($phrase);
+ my $text = $e->xlit($phrase);
+ $text ||= $phrase;
+ return ($enum, $text);
+}
+
+ajax '/777/:language/:phrase' => sub {
+ my ($enum, $text) = get_enum_from_text(params->{phrase}, params->{language});
+ header('Content-Type' => 'application/json; charset=utf-8');
+ return to_json({enum => $enum, text => $text});
+};
+
+get '/777/:language/:phrase' => sub {
+ my ($enum, $text) = get_enum_from_text(params->{phrase}, params->{language});
+ header('Content-Type' => 'text/html; charset=utf-8');
+ return qq(<dl><dt>$text</dt><dd>$enum</dd></dl>);
+};
+
+start;
View
1  config.yml
@@ -0,0 +1 @@
+charset: UTF-8
View
8 public/css/xape.css
@@ -0,0 +1,8 @@
+dl {
+ float: left;
+}
+
+dl dd {
+ display: block;
+ margin: 0;
+}
View
30 public/index.html
@@ -0,0 +1,30 @@
+<html>
+ <head>
+ <link rel="StyleSheet" href="css/xape.css" type="text/css" media="screen" />
+ <title>Xape Ape</title>
+ </head>
+
+ <body>
+ <h1 class="heading"><span id="main">Xape</span></h1>
+ <div class="inputs">
+ <form id="f">
+ <select id="language">
+ <option value="he">Hebrew</option>
+ </select>
+ <input type="text" id="phrase" />
+ </form>
+ </div>
+ <div class="outputs">
+ <dl>
+ <dt id="phrase_text"></dt>
+ <dd id="phrase_enum"></dd>
+ </dl>
+ </div>
+ </body>
+
+ <script type="text/javascript"
+ src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
+ <script type="text/javascript"
+ src="js/xape.js"></script>
+
+</html>
View
21 public/js/xape.js
@@ -0,0 +1,21 @@
+$(document).ready(
+ function() {
+ $("#phrase").val("VIAOV").focus();
+ $("#f").submit(
+ function() {
+ get_enum($("#phrase").val(), $("#language").val());
+ return false;
+ }
+ );
+ }
+);
+
+function get_enum(phrase, language) {
+ var uri = encodeURI("777/" + language + "/" + phrase);
+ $.getJSON(uri, null, update_results);
+}
+
+function update_results(data, textStatus, jqXHR) {
+ $("#phrase_text").html(data.text);
+ $("#phrase_enum").html(data.enum);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.