gfse&minibar: select the right grammar in minibar when invoked from gfse

The grammar that the user is currently working is now the one shown initially
in minibar, instead of the first grammar in alphabetical order.
Also GFServer.hs now removes absolute paths to the grammar files on the server in error messages from GF returned to to gfse.
This commit is contained in:
hallgren
2012-02-10 15:24:59 +00:00
parent 196d17c961
commit a6acb994e8
4 changed files with 34 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
{-# LANGUAGE CPP #-}
module GFServer(server) where
import Data.List(partition)
import Data.List(partition,stripPrefix,tails)
import Data.Maybe(mapMaybe)
import qualified Data.Map as M
import Control.Monad(when)
import System.Random(randomRIO)
@@ -169,7 +170,8 @@ handle state0 cache execute1
let args = "-s":"-make":map fst files
cmd = unwords ("gf":args)
out <- readProcessWithExitCode "gf" args ""
return (state,html200 (resultpage ('/':dir++"/") cmd out files))
cwd <- getCurrentDirectory
return (state,html200 (resultpage cwd ('/':dir++"/") cmd out files))
upload files =
do let update (name,contents)= updateFile name contents
@@ -219,24 +221,28 @@ handle state0 cache execute1
-- * Dynamic content
resultpage dir cmd (ecode,stdout,stderr) files =
resultpage cwd dir cmd (ecode,stdout,stderr) files =
unlines $
"<!DOCTYPE html>":
"<title>Uploaded</title>":
"<link rel=stylesheet type=\"text/css\" HREF=\"/gfse/editor.css\" title=\"Normal\">":
"<h1>Uploaded</h1>":
"<pre>":escape cmd:"":escape stderr:escape stdout:
"<pre>":escape cmd:"":escape (rel stderr):escape (rel stdout):
"</pre>":
(if ecode==ExitSuccess
then "<h3>OK</h3>":links
else "<h3 class=error_message>Error</h3>":listing)
where
links = "<dl>":
("<dt>▸ <a href=\"/minibar/minibar.html?"++dir++"\">Minibar</a>"):
("<dt>▸ <a href=\"/minibar/minibar.html?"++dir++pgf++"\">Minibar</a>"):
"<dt>◂ <a href=\"javascript:history.back()\">Back to Editor</a>":
"</dl>":
[]
pgf = case files of
(abstract,_):_ -> "%20"++take (length abstract-3) abstract++".pgf"
_ -> ""
listing = concatMap listfile files
listfile (name,source) =
@@ -246,6 +252,13 @@ resultpage dir cmd (ecode,stdout,stderr) files =
num n s = pad (show n)++" "++escape s
pad s = replicate (5-length s) ' '++s
rel = unlines . map relative . lines
-- remove absolute file paths from error messages:
relative s = case stripPrefix cwd s of
Just ('/':rest) -> rest
_ -> s
escape = concatMap escape1
escape1 '<' = "&lt;"
escape1 '&' = "&amp;"

View File

@@ -170,11 +170,13 @@ Some implementation details:
<li>[Added 2011-10-18] Added a button to display some grammar info and a
start category menu. The start category menu can be turned off by passing
the option <code>{startcat_menu:false}</code> when starting the minibar.
<li>[Added 2012-02-10] New minibar option <code>initial_grammar</code> to
control which of the available grammars is selected initially.
</ul>
<hr>
<small class=modtime>
<!-- hhmts start --> Last modified: Tue Oct 18 17:18:42 CEST 2011 <!-- hhmts end -->
<!-- hhmts start --> Last modified: Fri Feb 10 15:55:30 CET 2012 <!-- hhmts end -->
</small>
<address>
<a href="http://www.cs.chalmers.se/~hallgren/">TH</a>

View File

@@ -32,7 +32,8 @@ function Minibar(server,opts) {
target: "minibar",
try_google: true,
feedback_url: null,
help_url: null
help_url: null,
initial_grammar: null
}
// Apply supplied options
@@ -81,7 +82,9 @@ Minibar.prototype.show_grammarlist=function(grammars) {
}
if(options.help_url)
menubar.appendChild(button("Help",bind(open_help,this)));
select_grammar(grammars[0]);
var grammar0=options.initial_grammar || grammars[0];
grammar_menu.value=grammar0;
select_grammar(grammar0);
}
}

View File

@@ -7,13 +7,6 @@ var online_options={
//grammar_list: ["Foods.pgf"], // leave undefined to get list from server
}
if(/^\?\/tmp\//.test(location.search)) {
online_options.grammars_url=location.search.substr(1);
}
var server=pgf_online(online_options);
var minibar_options= {
show_abstract: true,
show_trees: true,
@@ -22,4 +15,12 @@ var minibar_options= {
//feedback_url: "feedback.html",
try_google: true
}
if(/^\?\/tmp\//.test(location.search)) {
var args=decodeURIComponent(location.search.substr(1)).split(" ")
if(args[0]) online_options.grammars_url=args[0];
if(args[1]) minibar_options.initial_grammar=args[1];
}
var server=pgf_online(online_options);
var minibar=new Minibar(server,minibar_options);