[Refactor code Joachim Breitner **20100828164523 Ignore-this: a8592e306c07765780dc0736c24acc2c ] hunk ./b18n-combined-cgi.hs 1 +{-# LANGUAGE RecordWildCards #-} hunk ./b18n-combined-cgi.hs 19 -page code scrollX scrollY pageContent = +data PageInfo = PageInfo + { scrollX :: Maybe String + , scrollY :: Maybe String + , viewFunction :: String + , exMode :: ExecMode + , outMode :: OutputMode + , showTypes :: Bool + , generatedModuleMB :: Maybe String + } + +page (PageInfo {..}) = hunk ./b18n-combined-cgi.hs 57 - hidden "scrollx" scrollX +++ - hidden "scrolly" scrollY +++ + hidden "scrollx" (fromMaybe "0" scrollX) +++ + hidden "scrolly" (fromMaybe "0" scrollY) +++ hunk ./b18n-combined-cgi.hs 67 - ! (if thisCode == code then [checked] else []) + ! (if thisCode == viewFunction then [checked] else []) hunk ./b18n-combined-cgi.hs 72 - textarea ! [name "code", cols "120", rows "7"] << code + textarea ! [name "code", cols "120", rows "7"] << viewFunction hunk ./b18n-combined-cgi.hs 76 - pageContent + {- p << astInfo mbAST +++ -} + maindiv ! [ identifier "output" ]<< ( + p << ( + "You can calculate a derived put function with various options:" ) +++ + p << ( "Execution mode: " +++ + concatHtml (map (\mode -> + radio "execMode" (show mode) + ! (guard (mode == exMode) >> return checked) + +++ show mode +++ " " + ) [Normal, Shapify, ShapifyPlus]) +++ br +++ + "Output mode: " +++ + concatHtml (map (\mode -> + radio "outputMode" (show mode) + ! (guard (mode == outMode) >> return checked) + +++ show mode +++ " " + ) [PseudoCode, HaskellCode, ForwardCode]) +++ br +++ + "Show types " +++ checkbox "showTypes" "showTypes" + ! (guard showTypes >> return checked) + +++ br +++ + mkSubmit True BiDi + ) +++ + ( htmlMB generatedModuleMB $ \ generatedModule -> + {- maybe noHtml outputErrors errors +++ -} + p << ("Result:"+++ br +++ + textarea ! [name "gencode", cols "120" + , rows (show (1 + length (lines generatedModule))) + ] << generatedModule + + ) + ) + ) hunk ./b18n-combined-cgi.hs 227 - todo <- fromMaybe Check . msum <$> sequence ( + todo <- msum <$> sequence ( hunk ./b18n-combined-cgi.hs 233 - let mbAST = parseString code - hunk ./b18n-combined-cgi.hs 234 - Load -> do loadWhat <- getInput "load" - return $ fromMaybe code $ loadWhat >>= flip lookup examples + Just Load -> do loadWhat <- getInput "load" + return $ fromMaybe code $ loadWhat >>= flip lookup examples hunk ./b18n-combined-cgi.hs 237 + + let mbAST = parseString code hunk ./b18n-combined-cgi.hs 241 - let genCode = case mbAST of - Left _ -> "" - Right ast -> render $ case exMode of - Normal -> outputCode conf False ast (typeInference ast) - Shapify -> outputCode conf False ast (shapify $ typeInference ast) - ShapifyPlus -> outputCode conf True ast (introNat $ shapify $ typeInference ast) + let genCode = case (todo,mbAST) of + (Just Load, _) -> Nothing + (Just _, Right ast) -> Just $ render $ case exMode of + Normal -> outputCode conf False ast (typeInference ast) + Shapify -> outputCode conf False ast (shapify $ typeInference ast) + ShapifyPlus -> outputCode conf True ast (introNat $ shapify $ typeInference ast) + _ -> Nothing hunk ./b18n-combined-cgi.hs 249 - scrollX <- fromMaybe "0" <$> getInput "scrollx" - scrollY <- fromMaybe "0" <$> getInput "scrolly" + scrollX <- getInput "scrollx" + scrollY <- getInput "scrolly" hunk ./b18n-combined-cgi.hs 252 - outputFPS $ fromString $ showHtml $ page code scrollX scrollY $ - {- p << astInfo mbAST +++ -} - maindiv ! [ identifier "output" ]<< ( - p << ( - "You can calculate a derived put function with various options:" ) +++ - p << ( "Execution mode: " +++ - concatHtml (map (\mode -> - radio "execMode" (show mode) - ! (if mode == exMode then [checked] else []) - +++ show mode +++ " " - ) [Normal, Shapify, ShapifyPlus]) +++ br +++ - "Output mode: " +++ - concatHtml (map (\mode -> - radio "outputMode" (show mode) - ! (if mode == outMode then [checked] else []) - +++ show mode +++ " " - ) [PseudoCode, HaskellCode, ForwardCode]) +++ br +++ - "Show types " +++ checkbox "showTypes" "showTypes" - ! (if showTypes then [checked] else []) - +++ br +++ - mkSubmit True BiDi - ) +++ - {- maybe noHtml outputErrors errors +++ -} - p << ("Result:"+++ br +++ - textarea ! [name "gencode", cols "120" - , rows (show (1 + length (lines genCode))) - ] << genCode + outputFPS $ fromString $ showHtml $ page (PageInfo scrollX scrollY code exMode outMode showTypes genCode) hunk ./b18n-combined-cgi.hs 254 - ) - ) - hunk ./b18n-combined-cgi.hs 310 + +htmlMB Nothing f = noHtml +htmlMB (Just x) f = f x