eg/tryhy: add version number

This commit is contained in:
Johan Euphrosine 2013-11-01 23:34:27 -07:00
parent 079e3002a7
commit 50ee81df13
5 changed files with 36 additions and 13 deletions

View File

@ -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

View File

@ -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 }

View File

@ -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;
}
);
};
}

View File

@ -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")))
)))

View File

@ -6,9 +6,13 @@
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery.console.js"></script>
<script type="text/javascript" src="js/repl.js"></script>
<script type="text/javascript">
var hy_version = '{{hy_version}}';
</script>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="hy-console" class="console"></div>
<div id="hy-console" class="console">
</div>
</body>
</html>