Simplified build process using template haskell.

+ Text/Pandoc/ASCIIMathML.hs, Text/Pandoc/DefaultHeaders.hs,
  and Text/Pandoc/Writers/S5.hs are no longer built in Setup.hs
  from templates in the templates/ directory.
+ Instead, they use template haskell to read data at compile
  time from the relevant files in data/.
+ Setup.hs is back to the default simple configuration.
+ Removed old templates and Extra-Tmp-Files field from
  pandoc.cabal.


git-svn-id: https://pandoc.googlecode.com/svn/trunk@1357 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
fiddlosopher 2008-08-01 06:35:42 +00:00
parent 04e09cf031
commit ba32c2ec42
29 changed files with 52 additions and 121 deletions

View file

@ -189,14 +189,6 @@ uninstall-doc:
-for f in $(man_all); do rm -f $(MANPATH)/$$f; done
rmdir $(PKGDOCPATH) 2>/dev/null ||:
# Data file installation.
.PHONY: install-data uninstall-data
install-data: $(ODTREF)
$(INSTALL) -d $(PKGDATAPATH) && $(INSTALL_DATA) $(ODTREF) $(PKGDATAPATH)/
uninstall-data:
-rm -f $(PKGDATAPATH)/$(notdir $(ODTREF))
rmdir $(PKGDATAPATH) 2>/dev/null ||:
# Program only installation.
.PHONY: install-exec uninstall-exec
install-exec: build-exec
@ -213,8 +205,8 @@ uninstall-exec:
# Program + user documents installation.
.PHONY: install-program uninstall-program
install-program: install-exec install-data install-doc
uninstall-program: uninstall-exec uninstall-doc uninstall-data
install-program: install-exec install-doc
uninstall-program: uninstall-exec uninstall-doc
.PHONY: install-all uninstall-all
# Full installation through Cabal: main + wrappers + user docs + lib + lib docs

View file

@ -1,70 +1,3 @@
import Distribution.Simple
import Distribution.Simple.Setup
import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
import System.FilePath (combine, joinPath, takeFileName, takeExtension)
import System.Directory (getDirectoryContents, removeFile, copyFile)
import System.IO (readFile, writeFile)
import Control.Monad (foldM)
import Data.List (isPrefixOf)
main = defaultMainWithHooks $ simpleUserHooks { postConf = myPostConf }
pandocPath = combine "Text" "Pandoc"
-- Builds Text/Pandoc/ASCIIMathML.hs, Text/Pandoc/Writers/S5.hs, and
-- Text/Pandoc/Writers/DefaultHeaders.hs from templates and data.
myPostConf :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
myPostConf _ configFlags pkgDescription buildInfo = do
putStrLn "Generating source files from templates..."
fillAsciiMathMLTemplate
fillS5WriterTemplate
fillDefaultHeadersTemplate
-- Fill templateFile with data in dataFiles and write to outputFile.
fillTemplate :: [FilePath] -> FilePath -> FilePath -> IO ()
fillTemplate dataFiles templateFile outputFile = do
template <- readFile (combine "templates" templateFile)
filled <- foldM processFile template $ map (combine "templates") dataFiles
writeTemplate (combine pandocPath outputFile) filled
fillAsciiMathMLTemplate :: IO ()
fillAsciiMathMLTemplate =
fillTemplate ["ASCIIMathML.js.comment", "ASCIIMathML.js.packed"] "ASCIIMathML.hs" "ASCIIMathML.hs"
fillS5WriterTemplate :: IO ()
fillS5WriterTemplate =
let s5Path = joinPath ["ui", "default"]
files = map (combine s5Path) ["slides.js.comment", "slides.js.packed", "s5-core.css",
"framing.css", "pretty.css", "opera.css", "outline.css", "print.css"]
in fillTemplate files "S5.hs" (combine "Writers" "S5.hs")
fillDefaultHeadersTemplate :: IO ()
fillDefaultHeadersTemplate = do
files <- getDirectoryContents (combine "templates" "headers") >>=
return . map (combine "headers") . filter (\x -> takeExtension x == ".header")
fillTemplate files "DefaultHeaders.hs" "DefaultHeaders.hs"
-- Write the filled template file and print an explanatory message.
writeTemplate :: FilePath -> String -> IO ()
writeTemplate outfile contents = do
putStrLn $ " " ++ outfile
let warning = "-- This file is generated from a template in the templates subdirectory.\n" ++
"-- Modify that file, not this one.\n"
writeFile outfile (warning ++ contents)
-- Read contents of fpath and insert in template replacing @fpath@.
processFile :: String -> FilePath -> IO String
processFile template fpath = do
contents <- readFile fpath >>= return . show
return $ substitute ("@" ++ takeFileName fpath ++ "@") contents template
-- Replace each occurrence of one sublist in a list with another.
substitute :: (Eq a) => [a] -> [a] -> [a] -> [a]
substitute _ _ [] = []
substitute [] _ lst = lst
substitute target replacement lst =
if target `isPrefixOf` lst
then replacement ++ (substitute target replacement $ drop (length target) lst)
else (head lst):(substitute target replacement $ tail lst)
main = defaultMain

View file

@ -0,0 +1,11 @@
{-# LANGUAGE TemplateHaskell #-}
-- | Definitions for use of ASCIIMathML in HTML.
-- (See <http://www1.chapman.edu/~jipsen/mathml/asciimath.html>.)
module Text.Pandoc.ASCIIMathML ( asciiMathMLScript ) where
import Text.Pandoc.Shared ( contentsOf )
-- | String containing ASCIIMathML javascript.
asciiMathMLScript :: String
asciiMathMLScript = "<script type=\"text/javascript\">\n" ++
$(contentsOf $ "data/ASCIIMathML.js.comment") ++
$(contentsOf $ "data/ASCIIMathML.js.packed") ++ "</script>\n"

View file

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-
Copyright (C) 2006-7 John MacFarlane <jgm@berkeley.edu>
@ -36,21 +37,23 @@ module Text.Pandoc.DefaultHeaders (
defaultRTFHeader
) where
import Text.Pandoc.Writers.S5
import System.FilePath ( (</>) )
import Text.Pandoc.Shared ( contentsOf )
defaultLaTeXHeader :: String
defaultLaTeXHeader = @LaTeX.header@
defaultLaTeXHeader = $(contentsOf $ "data" </> "headers" </> "LaTeX.header")
defaultConTeXtHeader :: String
defaultConTeXtHeader = @ConTeXt.header@
defaultConTeXtHeader = $(contentsOf $ "data" </> "headers" </> "ConTeXt.header")
defaultDocbookHeader :: String
defaultDocbookHeader = @Docbook.header@
defaultDocbookHeader = $(contentsOf $ "data" </> "headers" </> "Docbook.header")
defaultOpenDocumentHeader :: String
defaultOpenDocumentHeader = @OpenDocument.header@
defaultOpenDocumentHeader = $(contentsOf $ "data" </> "headers" </> "OpenDocument.header")
defaultS5Header :: String
defaultS5Header = s5Meta ++ s5CSS ++ s5Javascript
defaultRTFHeader :: String
defaultRTFHeader = @RTF.header@
defaultRTFHeader = $(contentsOf $ "data" </> "headers" </> "RTF.header")

View file

@ -1,3 +1,4 @@
{-# LANGUAGE TemplateHaskell #-}
{-
Copyright (C) 2006-7 John MacFarlane <jgm@berkeley.edu>
@ -39,34 +40,37 @@ module Text.Pandoc.Writers.S5 (
writeS5String,
insertS5Structure
) where
import Text.Pandoc.Shared ( joinWithSep, WriterOptions )
import Text.Pandoc.Shared ( joinWithSep, WriterOptions, contentsOf )
import Text.Pandoc.Writers.HTML ( writeHtml, writeHtmlString )
import Text.Pandoc.Definition
import Text.XHtml.Strict
import System.FilePath ( (</>) )
s5Meta :: String
s5Meta = "<!-- configuration parameters -->\n<meta name=\"defaultView\" content=\"slideshow\" />\n<meta name=\"controlVis\" content=\"hidden\" />\n"
s5Javascript :: String
s5Javascript = "<script type=\"text/javascript\">\n" ++ @slides.js.comment@ ++ @slides.js.packed@ ++ "</script>\n"
s5Javascript = "<script type=\"text/javascript\">\n" ++
$(contentsOf $ "data" </> "ui" </> "default" </> "slides.js.comment") ++
$(contentsOf $ "data" </> "ui" </> "default" </> "slides.js.packed") ++ "</script>\n"
s5CoreCSS :: String
s5CoreCSS = @s5-core.css@
s5CoreCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "s5-core.css")
s5FramingCSS :: String
s5FramingCSS = @framing.css@
s5FramingCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "framing.css")
s5PrettyCSS :: String
s5PrettyCSS = @pretty.css@
s5PrettyCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "pretty.css")
s5OperaCSS :: String
s5OperaCSS = @opera.css@
s5OperaCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "opera.css")
s5OutlineCSS :: String
s5OutlineCSS = @outline.css@
s5OutlineCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "outline.css")
s5PrintCSS :: String
s5PrintCSS = @print.css@
s5PrintCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "print.css")
s5CSS :: String
s5CSS = "<style type=\"text/css\" media=\"projection\" id=\"slideProj\">\n" ++ s5CoreCSS ++ "\n" ++ s5FramingCSS ++ "\n" ++ s5PrettyCSS ++ "\n</style>\n<style type=\"text/css\" media=\"projection\" id=\"operaFix\">\n" ++ s5OperaCSS ++ "\n</style>\n<style type=\"text/css\" media=\"screen\" id=\"outlineStyle\">\n" ++ s5OutlineCSS ++ "\n</style>\n<style type=\"text/css\" media=\"print\" id=\"slidePrint\">\n" ++ s5PrintCSS ++ "\n</style>\n"

View file

Before

Width:  |  Height:  |  Size: 49 B

After

Width:  |  Height:  |  Size: 49 B

View file

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

View file

@ -1,7 +1,7 @@
Name: pandoc
Version: 0.47
Cabal-Version: >= 1.2
Build-Type: Custom
Build-Type: Simple
License: GPL
License-File: COPYING
Copyright: (c) 2006-2008 John MacFarlane
@ -35,29 +35,23 @@ Description: Pandoc is a Haskell library for converting from one markup
format. Thus, adding an input or output format requires
only adding a reader or writer.
Extra-Source-Files: README, INSTALL, COPYRIGHT, COPYING,
templates/ASCIIMathML.js.comment,
templates/ASCIIMathML.js.packed,
templates/ASCIIMathML.hs,
templates/S5.hs,
templates/DefaultHeaders.hs,
templates/headers/ConTeXt.header,
templates/headers/Docbook.header,
templates/headers/LaTeX.header,
templates/headers/OpenDocument.header,
templates/headers/RTF.header,
templates/headers/S5.header,
templates/ui/default/slides.js.comment,
templates/ui/default/slides.js.packed,
templates/ui/default/s5-core.css,
templates/ui/default/framing.css,
templates/ui/default/pretty.css,
templates/ui/default/opera.css,
templates/ui/default/outline.css,
templates/ui/default/print.css,
data/ASCIIMathML.js.comment,
data/ASCIIMathML.js.packed,
data/headers/ConTeXt.header,
data/headers/Docbook.header,
data/headers/LaTeX.header,
data/headers/OpenDocument.header,
data/headers/RTF.header,
data/headers/S5.header,
data/ui/default/slides.js.comment,
data/ui/default/slides.js.packed,
data/ui/default/s5-core.css,
data/ui/default/framing.css,
data/ui/default/pretty.css,
data/ui/default/opera.css,
data/ui/default/outline.css,
data/ui/default/print.css,
odt-styles/reference.odt
Extra-Tmp-Files: Text/Pandoc/ASCIIMathML.hs,
Text/Pandoc/DefaultHeaders.hs,
Text/Pandoc/Writers/S5.hs
Flag splitBase
Description: Choose the new, smaller, split-up base package.
Default: True
@ -112,6 +106,7 @@ Library
Text.XML.Light.Types,
Text.XML.Light.Output,
Text.XML.Light.Input,
Text.XML.Light.Proc,
Text.XML.Light.Cursor
Ghc-Options: -O2 -Wall -threaded
Ghc-Prof-Options: -auto-all

View file

@ -1,7 +0,0 @@
-- | Definitions for use of ASCIIMathML in HTML.
-- (See <http://www1.chapman.edu/~jipsen/mathml/asciimath.html>.)
module Text.Pandoc.ASCIIMathML ( asciiMathMLScript ) where
-- | String containing ASCIIMathML javascript.
asciiMathMLScript :: String
asciiMathMLScript = "<script type=\"text/javascript\">\n" ++ @ASCIIMathML.js.comment@ ++ @ASCIIMathML.js.packed@ ++ "</script>\n"