From 50ee81df131d541be392822e872ce78a81f75b49 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Fri, 1 Nov 2013 23:34:27 -0700 Subject: [PATCH] eg/tryhy: add version number --- eg/tryhy/app.yaml | 4 ---- eg/tryhy/css/style.css | 3 +++ eg/tryhy/js/repl.js | 21 ++++++++++++++++++--- eg/tryhy/main.hy | 15 ++++++++++----- eg/tryhy/{ => templates}/index.html | 6 +++++- 5 files changed, 36 insertions(+), 13 deletions(-) rename eg/tryhy/{ => templates}/index.html (75%) diff --git a/eg/tryhy/app.yaml b/eg/tryhy/app.yaml index 0ce0551..b492c71 100644 --- a/eg/tryhy/app.yaml +++ b/eg/tryhy/app.yaml @@ -9,10 +9,6 @@ handlers: static_files: favicon.ico upload: favicon\.ico -- url: / - static_files: index.html - upload: index\.html - - url: /js static_dir: js diff --git a/eg/tryhy/css/style.css b/eg/tryhy/css/style.css index 917190e..1401b36 100644 --- a/eg/tryhy/css/style.css +++ b/eg/tryhy/css/style.css @@ -14,6 +14,9 @@ div.console div.jquery-console-message-value { color:#1ad027; font-family:monospace; padding:0.1em; } div.console div.jquery-console-message-type +{ color:#52666f; font-family:monospace; + padding:0.1em; } +div.console div.jquery-console-welcome { color:#52666f; font-family:monospace; padding:0.1em; } div.console span.jquery-console-prompt-label { font-weight:bold } diff --git a/eg/tryhy/js/repl.js b/eg/tryhy/js/repl.js index cc07a0b..bd82ffd 100644 --- a/eg/tryhy/js/repl.js +++ b/eg/tryhy/js/repl.js @@ -1,7 +1,7 @@ $(document).ready(function(){ var backlog = []; - $('#hy-console').console({ - promptLabel: 'hy=> ', + var console = $('#hy-console').console({ + promptLabel: '=> ', commandValidate:function(line){ if (line == '') return false; else return true; @@ -23,5 +23,20 @@ $(document).ready(function(){ animateScroll:true, promptHistory:true, autofocus:true, - }).promptText('(+ 41 1)'); + welcomeMessage: 'hy ({hy_version})'.supplant({hy_version: hy_version}) + }); + console.promptText('(+ 41 1)'); }); + + +if (!String.prototype.supplant) { + String.prototype.supplant = function (o) { + return this.replace( + /\{([^{}]*)\}/g, + function (a, b) { + var r = o[b]; + return typeof r === 'string' || typeof r === 'number' ? r : a; + } + ); + }; +} diff --git a/eg/tryhy/main.hy b/eg/tryhy/main.hy index 2e1404e..6d796a1 100644 --- a/eg/tryhy/main.hy +++ b/eg/tryhy/main.hy @@ -1,8 +1,9 @@ -(import [hy.cmdline [HyREPL]] - [sys] +(import [sys] [StringIO [StringIO]] - [flask [Flask redirect request]] - [json]) + [json] + [hy.cmdline [HyREPL]] + [hy] + [flask [Flask redirect request render_template]]) (defclass MyHyREPL [HyREPL] [[eval (fn [self code] @@ -19,6 +20,11 @@ (def app (Flask __name__)) +(with-decorator (kwapply (app.route "/") {"methods" ["GET"]}) + (fn [] + (kwapply (render_template "index.html") {"hy_version" hy.__version__}) + )) + (with-decorator (kwapply (app.route "/eval") {"methods" ["POST"]}) (fn [] (let [[repl (MyHyREPL)] [input (request.get_json)]] @@ -26,4 +32,3 @@ (repl.eval expr)) (json.dumps (repl.eval (get input "code"))) ))) - diff --git a/eg/tryhy/index.html b/eg/tryhy/templates/index.html similarity index 75% rename from eg/tryhy/index.html rename to eg/tryhy/templates/index.html index 3ee5a48..6cb7896 100644 --- a/eg/tryhy/index.html +++ b/eg/tryhy/templates/index.html @@ -6,9 +6,13 @@ + -
+
+