summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2012-02-10 15:24:59 +0000
committerhallgren <hallgren@chalmers.se>2012-02-10 15:24:59 +0000
commit6b29296060a0fcbc32ddb27fe56325bccff144e0 (patch)
treeab2a0233332fe3dbbd8a635303c9b068a88d2cd7 /src
parentd8958ed68d1b315d9a49ca45f4db3a7472d36cbb (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/GFServer.hs23
-rw-r--r--src/www/minibar/about.html4
-rw-r--r--src/www/minibar/minibar.js7
-rw-r--r--src/www/minibar/minibar_online.js15
4 files changed, 34 insertions, 15 deletions
diff --git a/src/compiler/GFServer.hs b/src/compiler/GFServer.hs
index cebf08b82..149cb1864 100644
--- a/src/compiler/GFServer.hs
+++ b/src/compiler/GFServer.hs
@@ -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;"
diff --git a/src/www/minibar/about.html b/src/www/minibar/about.html
index 08f891bbc..ddf897073 100644
--- a/src/www/minibar/about.html
+++ b/src/www/minibar/about.html
@@ -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>
diff --git a/src/www/minibar/minibar.js b/src/www/minibar/minibar.js
index a94cc5629..e37b33a7c 100644
--- a/src/www/minibar/minibar.js
+++ b/src/www/minibar/minibar.js
@@ -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);
}
}
diff --git a/src/www/minibar/minibar_online.js b/src/www/minibar/minibar_online.js
index 1c15e87bf..e6693f7a0 100644
--- a/src/www/minibar/minibar_online.js
+++ b/src/www/minibar/minibar_online.js
@@ -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);