From 6b29296060a0fcbc32ddb27fe56325bccff144e0 Mon Sep 17 00:00:00 2001 From: hallgren Date: Fri, 10 Feb 2012 15:24:59 +0000 Subject: 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. --- src/compiler/GFServer.hs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/compiler') 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 $ "": "Uploaded": "": "

Uploaded

": - "
":escape cmd:"":escape stderr:escape stdout:
+    "
":escape cmd:"":escape (rel stderr):escape (rel stdout):
     "
": (if ecode==ExitSuccess then "

OK

":links else "

Error

":listing) where links = "
": - ("
Minibar"): + ("
Minibar"): "
Back to Editor": "
": [] + 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 '<' = "<" escape1 '&' = "&" -- cgit v1.2.3