forked from GitHub/gf-core
Changed gfdoc to: include modification time of the gf file, instead of document generation time; ignore pragmas at the start of the GF file; not put note about txt2tags in the generated html.
This commit is contained in:
@@ -15,9 +15,14 @@
|
|||||||
|
|
||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
|
||||||
import List
|
|
||||||
import System
|
import Data.Char
|
||||||
import Char
|
import Data.List
|
||||||
|
import System.Cmd
|
||||||
|
import System.Directory
|
||||||
|
import System.Environment
|
||||||
|
import System.Locale
|
||||||
|
import System.Time
|
||||||
|
|
||||||
-- to read files and write a file
|
-- to read files and write a file
|
||||||
|
|
||||||
@@ -37,8 +42,9 @@ main = do
|
|||||||
putStrLn help
|
putStrLn help
|
||||||
else flip mapM_ names (\name -> do
|
else flip mapM_ names (\name -> do
|
||||||
ss <- readFile name
|
ss <- readFile name
|
||||||
|
time <- modTime name
|
||||||
let outfile = fileFormat typ name
|
let outfile = fileFormat typ name
|
||||||
writeFile outfile $ format $ pDoc $ ss)
|
writeFile outfile $ format $ pDoc time ss)
|
||||||
case typ of
|
case typ of
|
||||||
2 ->
|
2 ->
|
||||||
mapM_ (\name -> system $ "htmls " ++ (fileFormat typ name)) names
|
mapM_ (\name -> system $ "htmls " ++ (fileFormat typ name)) names
|
||||||
@@ -48,6 +54,14 @@ main = do
|
|||||||
_ -> return ()
|
_ -> return ()
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
modTime :: FilePath -> IO ModTime
|
||||||
|
modTime name =
|
||||||
|
do
|
||||||
|
t <- getModificationTime name
|
||||||
|
ct <- toCalendarTime t
|
||||||
|
let timeFmt = "%Y-%m-%d %H:%M:%S %Z"
|
||||||
|
return $ formatCalendarTime defaultTimeLocale timeFmt ct
|
||||||
|
|
||||||
welcome = unlines [
|
welcome = unlines [
|
||||||
"",
|
"",
|
||||||
"gfdoc - a rudimentary GF document generator.",
|
"gfdoc - a rudimentary GF document generator.",
|
||||||
@@ -98,7 +112,9 @@ fileFormat typ x = body ++ suff where
|
|||||||
|
|
||||||
-- the document datatype
|
-- the document datatype
|
||||||
|
|
||||||
data Doc = Doc Title [Paragraph]
|
data Doc = Doc Title ModTime [Paragraph]
|
||||||
|
|
||||||
|
type ModTime = String
|
||||||
|
|
||||||
type Title = [TextItem]
|
type Title = [TextItem]
|
||||||
|
|
||||||
@@ -120,10 +136,10 @@ data TextItem =
|
|||||||
|
|
||||||
-- parse document
|
-- parse document
|
||||||
|
|
||||||
pDoc :: String -> Doc
|
pDoc :: ModTime -> String -> Doc
|
||||||
pDoc s = case lines s of
|
pDoc time s = case dropWhile emptyOrPragma (lines s) of
|
||||||
('-':'-':'1':title) : paras -> Doc (pItems title) (map pPara (grp paras))
|
('-':'-':'1':title) : paras -> Doc (pItems title) time (map pPara (grp paras))
|
||||||
paras -> Doc [] (map pPara (grp paras))
|
paras -> Doc [] time (map pPara (grp paras))
|
||||||
where
|
where
|
||||||
grp ss = case ss of
|
grp ss = case ss of
|
||||||
s : rest --- | ignore s -> grp rest
|
s : rest --- | ignore s -> grp rest
|
||||||
@@ -161,11 +177,12 @@ pDoc s = case lines s of
|
|||||||
'-':'-':'.':_ -> True
|
'-':'-':'.':_ -> True
|
||||||
_ -> False
|
_ -> False
|
||||||
|
|
||||||
|
emptyOrPragma s = all isSpace s || "--#" `isPrefixOf` s
|
||||||
|
|
||||||
-- render in html
|
-- render in html
|
||||||
|
|
||||||
doc2html :: Doc -> String
|
doc2html :: Doc -> String
|
||||||
doc2html (Doc title paras) = unlines $
|
doc2html (Doc title time paras) = unlines $
|
||||||
tagXML "html" $
|
tagXML "html" $
|
||||||
tagXML "body" $
|
tagXML "body" $
|
||||||
unwords (tagXML "i" ["Produced by " ++ welcome]) :
|
unwords (tagXML "i" ["Produced by " ++ welcome]) :
|
||||||
@@ -206,7 +223,7 @@ elimLt s = case s of
|
|||||||
-- render in latex
|
-- render in latex
|
||||||
|
|
||||||
doc2latex :: Doc -> String
|
doc2latex :: Doc -> String
|
||||||
doc2latex (Doc title paras) = unlines $
|
doc2latex (Doc title time paras) = unlines $
|
||||||
preludeLatex :
|
preludeLatex :
|
||||||
funLatex "title" [concat (map item2latex title)] :
|
funLatex "title" [concat (map item2latex title)] :
|
||||||
funLatex "author" [fontLatex "footnotesize" (welcome)] :
|
funLatex "author" [fontLatex "footnotesize" (welcome)] :
|
||||||
@@ -277,10 +294,11 @@ preludeLatex = unlines $ [
|
|||||||
-- render in txt2tags
|
-- render in txt2tags
|
||||||
|
|
||||||
doc2txt :: Doc -> String
|
doc2txt :: Doc -> String
|
||||||
doc2txt (Doc title paras) = unlines $
|
doc2txt (Doc title time paras) = unlines $
|
||||||
let tit = concat (map item2txt title) in
|
let tit = concat (map item2txt title) in
|
||||||
tit:
|
tit:
|
||||||
"Last update: %%date(%c)":
|
("Last update: " ++ time):
|
||||||
|
"":
|
||||||
"% NOTE: this is a txt2tags file.":
|
"% NOTE: this is a txt2tags file.":
|
||||||
"% Create an html file from this file using:":
|
"% Create an html file from this file using:":
|
||||||
("% txt2tags " ++ tit):
|
("% txt2tags " ++ tit):
|
||||||
|
|||||||
Reference in New Issue
Block a user