Skip to content

Commit

Permalink
removed old language. switching to all latex
Browse files Browse the repository at this point in the history
  • Loading branch information
imeckler committed Sep 27, 2014
1 parent bfa5eec commit ca1d04b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 571 deletions.
62 changes: 22 additions & 40 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ module Main where
import Prelude hiding (FilePath)
import Data.String (fromString)
import Data.Maybe (fromMaybe)
import Parse
import Text.Parsec.String
import Compile
import Control.Arrow
import Control.Monad
import Control.Monad.Except
import Control.Monad.Catch
import Control.Concurrent (threadDelay)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Options.Applicative hiding (Parser)
import Text.LaTeX.Base.Parser
Expand All @@ -30,8 +27,6 @@ data AppData = AppData
, watch :: Bool
}

data Format = Proof | Tex deriving (Show)

opts :: ParserInfo AppData
opts = info (helper <*> optParser)
( fullDesc
Expand All @@ -50,18 +45,9 @@ opts = info (helper <*> optParser)
path :: Monad m => String -> m FilePath
path = liftM fromString . str

fileFormat :: Monad m => FilePath -> Err m Format
fileFormat s = case fromMaybe "no extension" (extension s) of
"proof" -> return Proof
"tex" -> return Tex
e -> throwError (T.unpack e)

outputPath :: FilePath -> FilePath
outputPath p = replaceExtension p "html"

proofReader :: MonadIO m => FilePath -> Err m RawDocument
proofReader = ExceptT . liftIO . fmap (left show) . parseFromFile document . encodeString

texReader :: (MonadIO m, Functor m) => FilePath -> Err m RawDocument
texReader = (ExceptT . liftIO . fmap (left show) . parseLaTeXFile . encodeString) >=> decorate >=> translate

Expand Down Expand Up @@ -96,37 +82,27 @@ loadResources =
readDataFile = (`catch` (\(_::IOError) ->throwError "Could not read data files"))
. liftIO . (T.readFile <=< getDataFileName)

pkgPath :: FilePath -> FilePath -> FilePath
pkgPath inputPath outputDir = outputDir </> addExtension (basename inputPath) "proofpkg"

compileAndOutput :: (MonadIO m, MonadCatch m, Applicative m) => FilePath -> FilePath -> Err m ()
compileAndOutput inputPath outputDir =
fileFormat inputPath >>= \case
Proof -> go proofReader
Tex -> go texReader
compileAndOutput inputPath outputDir = do
let p = pkgPath inputPath outputDir
htmlPath = p </> "index.html"
html <- join (compile <$> loadResources <*> texReader inputPath)
-- TODO: Dangerous to remove directories. Remove when you merge

liftIO $ do
isDirectory p >>= flip when (removeTree p)
createDirectory False p

liftIO (getDataFilePath "lib") >>= \l -> copyDirectory l p
liftIO $ do
forM_ ["src/js/proof.js", "src/css/proof.css"] $ \q ->
getDataFilePath q >>= \q' -> copyFile q' (p </> filename q)
T.writeFile (encodeString htmlPath) html
where
getDataFilePath :: FilePath -> IO FilePath
getDataFilePath = fmap decodeString . getDataFileName . encodeString
go reader = do
let p = pkgPath inputPath outputDir
htmlPath = p </> "index.html"
html <- join (compile <$> loadResources <*> reader inputPath)
-- TODO: Dangerous to remove directories. Remove when you merge

liftIO $ do
isDirectory p >>= flip when (removeTree p)
createDirectory False p

liftIO (getDataFilePath "lib") >>= \l -> copyDirectory l p
liftIO $ do
forM_ ["src/js/proof.js", "src/css/proof.css"] $ \q ->
getDataFilePath q >>= \q' -> copyFile q' (p </> filename q)
T.writeFile (encodeString htmlPath) html

run inputPath outputDir =
runExceptT (compileAndOutput inputPath out) >>= \case
Left e -> putStrLn e
Right _ -> return ()
where out = fromMaybe (directory inputPath) outputDir

main :: IO ()
main = do
Expand All @@ -144,3 +120,9 @@ main = do
where
fEvent = \case { Modified p _ -> p == inputPath; _ -> False }

run inputPath outputDir =
runExceptT (compileAndOutput inputPath out) >>= \case
Left e -> putStrLn e
Right _ -> return ()
where out = fromMaybe (directory inputPath) outputDir

152 changes: 0 additions & 152 deletions Parse.hs

This file was deleted.

Loading

0 comments on commit ca1d04b

Please sign in to comment.