1
0
forked from GitHub/gf-rgl

Use Pandoc and introduce HTML template for synopsis

- Remove isLatex flag
- Plan to convert to Markdown and simply format
This commit is contained in:
John J. Camilleri
2018-11-09 09:08:30 +01:00
parent f70234b1da
commit ec9753e7b5
4 changed files with 157 additions and 29 deletions

5
doc/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
api-examples-*.txt
api-examples.gfs
categories-imagemap.html
synopsis.txt
synopsis.html

View File

@@ -24,9 +24,23 @@ SRC_FILES=$(S)/abstract/Common.gf $(S)/abstract/Cat.gf $(S)/api/Constructors.gf
EXAMPLES_OUT=$(patsubst %,api-examples-%.txt,$(LANGS))
INCLUDES=synopsis-intro.txt categories-intro.txt categories-imagemap.html synopsis-additional.txt synopsis-browse.txt synopsis-example.txt
synopsis.html: MkSynopsis.hs MkExxTable.hs $(INCLUDES) $(EXAMPLES_OUT) $(SRC_FILES)
synopsis.txt: MkSynopsis.hs MkExxTable.hs $(INCLUDES) $(EXAMPLES_OUT) $(SRC_FILES)
runghc -i.. MkSynopsis.hs
TMP=tmp.html
synopsis.html: synopsis.txt
txt2tags --target=html --no-headers --quiet --toc --outfile=$@ --infile=$^
pandoc \
--from=html \
--to=html5 \
--standalone \
--template=_template.html \
--metadata='title:"GF Resource Grammar Library: Synopsis"' \
--variable='rel-root:../..' \
--output=$(TMP) \
$@
mv $(TMP) $@
categories.png: categories.dot
dot -Tpng $^ > $@

View File

@@ -29,17 +29,13 @@ apiExxFiles = do
, langSynopsis lang
]
-- | This function puts together a txt2tags file which is then converted to HTML by the Makefile
main :: IO ()
main = do
xx <- getArgs
let isLatex = case xx of
"-tex":_ -> True
_ -> False
cs1 <- getCats commonAPI
cs2 <- getCats catAPI
let cs = sortCats (cs1 ++ cs2)
writeFile synopsis "GF Resource Grammar Library: Synopsis"
-- append "B. Bringert, T. Hallgren, and A. Ranta"
space
append "%!Encoding:utf-8"
append "%!style(html): ./revealpopup.css"
@@ -56,7 +52,7 @@ main = do
append "%!postproc(html): '#quicklinks' '<script src=\"quicklinks.js\"></script>'"
append "%!postproc(tex): '#quicklinks' ''"
delimit $ addToolTips cs
include "synopsis-intro.txt"
include "synopsis-intro.txt" -- TODO dynamic language list
title "Categories"
space
link "Source 1:" commonAPI
@@ -66,7 +62,7 @@ main = do
append "==A hierarchic view==\n"
include "categories-intro.txt"
append "==Explanations==\n"
delimit $ mkCatTable isLatex cs
delimit $ mkCatTable cs
space
title "Syntax Rules and Structural Words"
space
@@ -81,17 +77,17 @@ main = do
rs2 <- getRules apiExx structuralAPI
let rss = rs ++ rs2
--- mapM_ putStrLn [f ++ " " ++ e | (f,_,e) <- rss]
delimit $ mkSplitTables True isLatex apiExx cs rss
delimit $ mkSplitTables True apiExx cs rss
space
-- title "Structural Words"
-- space
-- link "Source:" structuralAPI
-- space
-- rs <- rulesTable False isLatex cs structuralAPI
-- rs <- rulesTable False cs structuralAPI
-- delimit rs
space
title "Lexical Paradigms"
paradigmFiles >>= mapM_ (putParadigms isLatex cs)
paradigmFiles >>= mapM_ (putParadigms cs)
space
include "synopsis-additional.txt"
space
@@ -107,9 +103,6 @@ main = do
space
append "#quicklinks"
space
let format = if isLatex then "tex" else "html"
system $ "txt2tags -t" ++ format ++ " " ++ " --toc " ++ synopsis
if isLatex then (system $ "pdflatex synopsis.tex") >> return () else return ()
addToolTips :: Cats -> [String]
addToolTips = map f
@@ -130,10 +123,10 @@ getCats file = do
(expl,ex) = span (/="e.g.") exp
_ -> getrs rs ss2
rulesTable :: ApiExx -> Bool -> Bool -> Cats -> FilePath -> IO [String]
rulesTable aexx hasEx isLatex cs file = do
rulesTable :: ApiExx -> Bool -> Cats -> FilePath -> IO [String]
rulesTable aexx hasEx cs file = do
rs <- getRules aexx file
return $ mkTable hasEx isLatex aexx cs rs
return $ mkTable hasEx aexx cs rs
getRules :: ApiExx -> FilePath -> IO Rules
@@ -161,14 +154,14 @@ getRules aexx file = do
n:ws | last n == '.' && not (null (init n)) && all isDigit (init n) -> ws
_ -> e
putParadigms :: Bool -> Cats -> (String, FilePath) -> IO ()
putParadigms isLatex cs (lang,file) = do
putParadigms :: Cats -> (String, FilePath) -> IO ()
putParadigms cs (lang,file) = do
stitle ("Paradigms for " ++ lang)
append "#LParadigms"
space
link "source" file
space
rs <- rulesTable M.empty False isLatex cs file
rs <- rulesTable M.empty False cs file
space
delimit rs
space
@@ -180,23 +173,23 @@ inChunks i f = concat . intersperse ["\n\n"] . map f . chunks i where
-- Makes one table per result category.
-- Adds a subsection header for each table.
mkSplitTables :: Bool -> Bool -> ApiExx -> Cats -> Rules -> [String]
mkSplitTables hasEx isLatex aexx cs = concatMap t . addLexicalCats cs . sortRules
mkSplitTables :: Bool -> ApiExx -> Cats -> Rules -> [String]
mkSplitTables hasEx aexx cs = concatMap t . addLexicalCats cs . sortRules
where t (c, xs) = [subtitle c expl] ++ tableOrLink
where
expl = case [e | (n,e,_) <- cs, n == c] of
[] -> ""
e:_ -> e
tableOrLink = if null xs then parad else mkTable hasEx isLatex aexx cs xs
tableOrLink = if null xs then parad else mkTable hasEx aexx cs xs
parad = [
"Lexical category, constructors given in",
"[lexical paradigms #RParadigms]."
]
mkTable :: Bool -> Bool -> ApiExx -> Cats -> Rules -> [String]
mkTable hasEx isLatex aexx cs = inChunks chsize (\rs -> header : map (unwords . row) rs)
mkTable :: Bool -> ApiExx -> Cats -> Rules -> [String]
mkTable hasEx aexx cs = inChunks chsize (\rs -> header : map (unwords . row) rs)
where
chsize = if isLatex then 40 else 1000
chsize = 1000
header = if hasEx then "|| Function | Type | Example ||"
else "|| Function | Type | Explanation ||"
row (name,typ,ex) =
@@ -235,11 +228,11 @@ mkIdent = concatMap unspec where
':' -> "-"
_ -> [c]
mkCatTable :: Bool -> Cats -> [String]
mkCatTable isLatex cs = inChunks chsize (\rs -> header ++ map mk1 rs) cs
mkCatTable :: Cats -> [String]
mkCatTable cs = inChunks chsize (\rs -> header ++ map mk1 rs) cs
where
header = ["|| Category | Explanation | Example ||"]
chsize = if isLatex then 40 else 1000
chsize = 1000
mk1 (name,expl,ex) = unwords ["|", showCat cs name, "|", expl, "|", typo ex, "|"]
typo ex = if take 1 ex == "\"" then itf (init (tail ex)) else ex

116
doc/_template.html Normal file
View File

@@ -0,0 +1,116 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="$lang$" xml:lang="$lang$"$if(dir)$ dir="$dir$"$endif$>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
$for(author-meta)$
<meta name="author" content="$author-meta$" />
$endfor$
$if(date-meta)$
<meta name="dcterms.date" content="$date-meta$" />
$endif$
$if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$" />
$endif$
<title>$if(title-prefix)$$title-prefix$ $endif$$pagetitle$</title>
$for(css)$
<link rel="stylesheet" href="$css$" />
$endfor$
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
$if(math)$
$math$
$endif$
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
$for(header-includes)$
$header-includes$
$endfor$
</head>
<body>
<div class="container my-5">
$if(title)$
<header id="title-block-header">
<a href="$rel-root$" title="Home">
<img src="$rel-root$/doc/Logos/gf1.svg" height="200px" class="float-md-right mb-3 bg-white" alt="GF Logo">
</a>
<h1 class="title">$title$</h1>
$if(subtitle)$
<p class="subtitle">$subtitle$</p>
$endif$
$for(author)$
<p class="author">$author$</p>
$endfor$
$if(date)$
<p class="date">$date$</p>
$endif$
</header>
$endif$
$if(toc)$
<nav id="$idprefix$TOC">
$table-of-contents$
</nav>
$endif$
$body$
</div><!-- .container -->
<footer class="bg-light mt-5 py-5">
<div class="container">
<div class="row">
<div class="col-3">
<a href="$rel-root$">
<i class="fas fa-home"></i>
Home
</a>
<h6 class="text-muted mt-3">Use</h6>
<ul class="list-unstyled">
<li><a href="$rel-root$/demos">Demos</a></li>
<li><a href="$rel-root$/download">Download GF</a></li>
</ul>
</div>
<div class="col-3">
<h6 class="text-muted">Documentation</h6>
<ul class="list-unstyled">
<li><a href="$rel-root$/doc/gf-shell-reference.html">GF Shell Reference</a></li>
<li><a href="$rel-root$/lib/doc/synopsis.html">RGL Library Synopsis</a></li>
<li><a href="$rel-root$/gf-book">The GF Book</a></li>
<li><a href="$rel-root$/doc/gf-refman.html">Reference Manual</a></li>
<li><a href="$rel-root$/doc/tutorial/gf-tutorial.html">Tutorial</a></li>
</ul>
</div>
<div class="col-3">
<h6 class="text-muted">Reference</h6>
<ul class="list-unstyled">
<li><a href="http://hackage.haskell.org/package/gf/docs/PGF.html">PGF library API (Haskell runtime)</a></li>
<li><a href="$rel-root$/doc/runtime-api.html">PGF library API (C runtime)</a></li>
<li><a href="http://hackage.haskell.org/package/gf/docs/GF.html">GF compiler API</a></li>
</ul>
</div>
<div class="col-3">
<h6 class="text-muted">
Repositories
<i class="fab fa-github"></i>
</h6>
<ul class="list-unstyled">
<li><a href="https://github.com/GrammaticalFramework/gf-core">GF Core</a></li>
<li><a href="https://github.com/GrammaticalFramework/gf-rgl">RGL</a></li>
<li><a href="https://github.com/GrammaticalFramework/gf-contrib">Contrib</a></li>
</ul>
</div>
<div>
<div>
</footer>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-7811807-3");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>