git.iko.soy/typeable/pandoc
on master help sign in
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

commitba32c2ec42182bcd7bdb995f90cd1405353fa400 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateFri 1 Aug 2008, 06:35 (18 years ago) parent04e09cf
29 files changed+52−121
Makefile+2−10 Setup.hs+1−68 Text/Pandoc/ASCIIMathML.hs+11 templates/DefaultHeaders.hs → Text/Pandoc/DefaultHeaders.hs+8−5 templates/S5.hs → Text/Pandoc/Writers/S5.hs+12−8 templates/ASCIIMathML.js → data/ASCIIMathML.js templates/ASCIIMathML.js.comment → data/ASCIIMathML.js.comment templates/ASCIIMathML.js.packed → data/ASCIIMathML.js.packed templates/headers/ConTeXt.header → data/headers/ConTeXt.header templates/headers/Docbook.header → data/headers/Docbook.header templates/headers/LaTeX.header → data/headers/LaTeX.header templates/headers/OpenDocument.header → data/headers/OpenDocument.header templates/headers/RTF.header → data/headers/RTF.header templates/headers/S5.header → data/headers/S5.header templates/ui/default/blank.gif → data/ui/default/blank.gif templates/ui/default/bodybg.gif → data/ui/default/bodybg.gif templates/ui/default/framing.css → data/ui/default/framing.css templates/ui/default/iepngfix.htc → data/ui/default/iepngfix.htc templates/ui/default/opera.css → data/ui/default/opera.css templates/ui/default/outline.css → data/ui/default/outline.css templates/ui/default/pretty.css → data/ui/default/pretty.css templates/ui/default/print.css → data/ui/default/print.css templates/ui/default/s5-core.css → data/ui/default/s5-core.css templates/ui/default/slides.css → data/ui/default/slides.css templates/ui/default/slides.js → data/ui/default/slides.js templates/ui/default/slides.js.comment → data/ui/default/slides.js.comment templates/ui/default/slides.js.packed → data/ui/default/slides.js.packed pandoc.cabal+18−23 templates/ASCIIMathML.hs−7
Makefile+2−10
@@ -189,14 +189,6 @@ uninstall-doc:
189189 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
190190 rmdir $(PKGDOCPATH) 2>/dev/null ||:
191191
192−# Data file installation.
193−.PHONY: install-data uninstall-data
194−install-data: $(ODTREF)
195− $(INSTALL) -d $(PKGDATAPATH) && $(INSTALL_DATA) $(ODTREF) $(PKGDATAPATH)/
196−uninstall-data:
197− -rm -f $(PKGDATAPATH)/$(notdir $(ODTREF))
198− rmdir $(PKGDATAPATH) 2>/dev/null ||:
199−
200192# Program only installation.
201193.PHONY: install-exec uninstall-exec
202194install-exec: build-exec
@@ -213,8 +205,8 @@ uninstall-exec:
213205
214206# Program + user documents installation.
215207.PHONY: install-program uninstall-program
216−install-program: install-exec install-data install-doc
217−uninstall-program: uninstall-exec uninstall-doc uninstall-data
208+install-program: install-exec install-doc
209+uninstall-program: uninstall-exec uninstall-doc
218210
219211.PHONY: install-all uninstall-all
220212# Full installation through Cabal: main + wrappers + user docs + lib + lib docs
Setup.hs+1−68
@@ -1,70 +1,3 @@
11import Distribution.Simple
2−import Distribution.Simple.Setup
3−import Distribution.PackageDescription
4−import Distribution.Simple.LocalBuildInfo
5−import System.FilePath (combine, joinPath, takeFileName, takeExtension)
6−import System.Directory (getDirectoryContents, removeFile, copyFile)
7−import System.IO (readFile, writeFile)
8−import Control.Monad (foldM)
9−import Data.List (isPrefixOf)
10−
11−main = defaultMainWithHooks $ simpleUserHooks { postConf = myPostConf }
12−
13−pandocPath = combine "Text" "Pandoc"
14−
15−-- Builds Text/Pandoc/ASCIIMathML.hs, Text/Pandoc/Writers/S5.hs, and
16−-- Text/Pandoc/Writers/DefaultHeaders.hs from templates and data.
17−myPostConf :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO ()
18−myPostConf _ configFlags pkgDescription buildInfo = do
19− putStrLn "Generating source files from templates..."
20− fillAsciiMathMLTemplate
21− fillS5WriterTemplate
22− fillDefaultHeadersTemplate
23−
24−-- Fill templateFile with data in dataFiles and write to outputFile.
25−fillTemplate :: [FilePath] -> FilePath -> FilePath -> IO ()
26−fillTemplate dataFiles templateFile outputFile = do
27− template <- readFile (combine "templates" templateFile)
28− filled <- foldM processFile template $ map (combine "templates") dataFiles
29− writeTemplate (combine pandocPath outputFile) filled
30−
31−fillAsciiMathMLTemplate :: IO ()
32−fillAsciiMathMLTemplate =
33− fillTemplate ["ASCIIMathML.js.comment", "ASCIIMathML.js.packed"] "ASCIIMathML.hs" "ASCIIMathML.hs"
34−
35−fillS5WriterTemplate :: IO ()
36−fillS5WriterTemplate =
37− let s5Path = joinPath ["ui", "default"]
38− files = map (combine s5Path) ["slides.js.comment", "slides.js.packed", "s5-core.css",
39− "framing.css", "pretty.css", "opera.css", "outline.css", "print.css"]
40− in fillTemplate files "S5.hs" (combine "Writers" "S5.hs")
41−
42−fillDefaultHeadersTemplate :: IO ()
43−fillDefaultHeadersTemplate = do
44− files <- getDirectoryContents (combine "templates" "headers") >>=
45− return . map (combine "headers") . filter (\x -> takeExtension x == ".header")
46− fillTemplate files "DefaultHeaders.hs" "DefaultHeaders.hs"
47−
48−-- Write the filled template file and print an explanatory message.
49−writeTemplate :: FilePath -> String -> IO ()
50−writeTemplate outfile contents = do
51− putStrLn $ " " ++ outfile
52− let warning = "-- This file is generated from a template in the templates subdirectory.\n" ++
53− "-- Modify that file, not this one.\n"
54− writeFile outfile (warning ++ contents)
55−
56−-- Read contents of fpath and insert in template replacing @fpath@.
57−processFile :: String -> FilePath -> IO String
58−processFile template fpath = do
59− contents <- readFile fpath >>= return . show
60− return $ substitute ("@" ++ takeFileName fpath ++ "@") contents template
61−
62−-- Replace each occurrence of one sublist in a list with another.
63−substitute :: (Eq a) => [a] -> [a] -> [a] -> [a]
64−substitute _ _ [] = []
65−substitute [] _ lst = lst
66−substitute target replacement lst =
67− if target `isPrefixOf` lst
68− then replacement ++ (substitute target replacement $ drop (length target) lst)
69− else (head lst):(substitute target replacement $ tail lst)
2+main = defaultMain
703
Text/Pandoc/ASCIIMathML.hsnew file+11
@@ -0,0 +1,11 @@
1+{-# LANGUAGE TemplateHaskell #-}
2+-- | Definitions for use of ASCIIMathML in HTML.
3+-- (See <http://www1.chapman.edu/~jipsen/mathml/asciimath.html>.)
4+module Text.Pandoc.ASCIIMathML ( asciiMathMLScript ) where
5+import Text.Pandoc.Shared ( contentsOf )
6+
7+-- | String containing ASCIIMathML javascript.
8+asciiMathMLScript :: String
9+asciiMathMLScript = "<script type=\"text/javascript\">\n" ++
10+ $(contentsOf $ "data/ASCIIMathML.js.comment") ++
11+ $(contentsOf $ "data/ASCIIMathML.js.packed") ++ "</script>\n"
templates/DefaultHeaders.hs → Text/Pandoc/DefaultHeaders.hsrenamed+8−5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE TemplateHaskell #-}
12{-
23Copyright (C) 2006-7 John MacFarlane <jgm@berkeley.edu>
34
@@ -36,21 +37,23 @@ module Text.Pandoc.DefaultHeaders (
3637 defaultRTFHeader
3738 ) where
3839import Text.Pandoc.Writers.S5
40+import System.FilePath ( (</>) )
41+import Text.Pandoc.Shared ( contentsOf )
3942
4043defaultLaTeXHeader :: String
41−defaultLaTeXHeader = @LaTeX.header@
44+defaultLaTeXHeader = $(contentsOf $ "data" </> "headers" </> "LaTeX.header")
4245
4346defaultConTeXtHeader :: String
44−defaultConTeXtHeader = @ConTeXt.header@
47+defaultConTeXtHeader = $(contentsOf $ "data" </> "headers" </> "ConTeXt.header")
4548
4649defaultDocbookHeader :: String
47−defaultDocbookHeader = @Docbook.header@
50+defaultDocbookHeader = $(contentsOf $ "data" </> "headers" </> "Docbook.header")
4851
4952defaultOpenDocumentHeader :: String
50−defaultOpenDocumentHeader = @OpenDocument.header@
53+defaultOpenDocumentHeader = $(contentsOf $ "data" </> "headers" </> "OpenDocument.header")
5154
5255defaultS5Header :: String
5356defaultS5Header = s5Meta ++ s5CSS ++ s5Javascript
5457
5558defaultRTFHeader :: String
56−defaultRTFHeader = @RTF.header@
59+defaultRTFHeader = $(contentsOf $ "data" </> "headers" </> "RTF.header")
templates/S5.hs → Text/Pandoc/Writers/S5.hsrenamed+12−8
@@ -1,3 +1,4 @@
1+{-# LANGUAGE TemplateHaskell #-}
12{-
23Copyright (C) 2006-7 John MacFarlane <jgm@berkeley.edu>
34
@@ -39,34 +40,37 @@ module Text.Pandoc.Writers.S5 (
3940 writeS5String,
4041 insertS5Structure
4142 ) where
42−import Text.Pandoc.Shared ( joinWithSep, WriterOptions )
43+import Text.Pandoc.Shared ( joinWithSep, WriterOptions, contentsOf )
4344import Text.Pandoc.Writers.HTML ( writeHtml, writeHtmlString )
4445import Text.Pandoc.Definition
4546import Text.XHtml.Strict
47+import System.FilePath ( (</>) )
4648
4749s5Meta :: String
4850s5Meta = "<!-- configuration parameters -->\n<meta name=\"defaultView\" content=\"slideshow\" />\n<meta name=\"controlVis\" content=\"hidden\" />\n"
4951
5052s5Javascript :: String
51−s5Javascript = "<script type=\"text/javascript\">\n" ++ @slides.js.comment@ ++ @slides.js.packed@ ++ "</script>\n"
53+s5Javascript = "<script type=\"text/javascript\">\n" ++
54+ $(contentsOf $ "data" </> "ui" </> "default" </> "slides.js.comment") ++
55+ $(contentsOf $ "data" </> "ui" </> "default" </> "slides.js.packed") ++ "</script>\n"
5256
5357s5CoreCSS :: String
54−s5CoreCSS = @s5-core.css@
58+s5CoreCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "s5-core.css")
5559
5660s5FramingCSS :: String
57−s5FramingCSS = @framing.css@
61+s5FramingCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "framing.css")
5862
5963s5PrettyCSS :: String
60−s5PrettyCSS = @pretty.css@
64+s5PrettyCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "pretty.css")
6165
6266s5OperaCSS :: String
63−s5OperaCSS = @opera.css@
67+s5OperaCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "opera.css")
6468
6569s5OutlineCSS :: String
66−s5OutlineCSS = @outline.css@
70+s5OutlineCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "outline.css")
6771
6872s5PrintCSS :: String
69−s5PrintCSS = @print.css@
73+s5PrintCSS = $(contentsOf $ "data" </> "ui" </> "default" </> "print.css")
7074
7175s5CSS :: String
7276s5CSS = "<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"
templates/ASCIIMathML.js → data/ASCIIMathML.jsrenamed

The content is the same.

templates/ASCIIMathML.js.comment → data/ASCIIMathML.js.commentrenamed

The content is the same.

templates/ASCIIMathML.js.packed → data/ASCIIMathML.js.packedrenamed

The content is the same.

templates/headers/ConTeXt.header → data/headers/ConTeXt.headerrenamed

The content is the same.

templates/headers/Docbook.header → data/headers/Docbook.headerrenamed

The content is the same.

templates/headers/LaTeX.header → data/headers/LaTeX.headerrenamed

The content is the same.

templates/headers/OpenDocument.header → data/headers/OpenDocument.headerrenamed

The content is the same.

templates/headers/RTF.header → data/headers/RTF.headerrenamed

The content is the same.

templates/headers/S5.header → data/headers/S5.headerrenamed

The content is the same.

templates/ui/default/blank.gif → data/ui/default/blank.gifrenamed

Binary file not shown.

templates/ui/default/bodybg.gif → data/ui/default/bodybg.gifrenamed

Binary file not shown.

templates/ui/default/framing.css → data/ui/default/framing.cssrenamed

The content is the same.

templates/ui/default/iepngfix.htc → data/ui/default/iepngfix.htcrenamed

The content is the same.

templates/ui/default/opera.css → data/ui/default/opera.cssrenamed

The content is the same.

templates/ui/default/outline.css → data/ui/default/outline.cssrenamed

The content is the same.

templates/ui/default/pretty.css → data/ui/default/pretty.cssrenamed

The content is the same.

templates/ui/default/print.css → data/ui/default/print.cssrenamed

The content is the same.

templates/ui/default/s5-core.css → data/ui/default/s5-core.cssrenamed

The content is the same.

templates/ui/default/slides.css → data/ui/default/slides.cssrenamed

The content is the same.

templates/ui/default/slides.js → data/ui/default/slides.jsrenamed

The content is the same.

templates/ui/default/slides.js.comment → data/ui/default/slides.js.commentrenamed

The content is the same.

templates/ui/default/slides.js.packed → data/ui/default/slides.js.packedrenamed

The content is the same.

pandoc.cabal+18−23
@@ -1,7 +1,7 @@
11Name: pandoc
22Version: 0.47
33Cabal-Version: >= 1.2
4−Build-Type: Custom
4+Build-Type: Simple
55License: GPL
66License-File: COPYING
77Copyright: (c) 2006-2008 John MacFarlane
@@ -35,29 +35,23 @@ Description: Pandoc is a Haskell library for converting from one markup
3535 format. Thus, adding an input or output format requires
3636 only adding a reader or writer.
3737Extra-Source-Files: README, INSTALL, COPYRIGHT, COPYING,
38− templates/ASCIIMathML.js.comment,
39− templates/ASCIIMathML.js.packed,
40− templates/ASCIIMathML.hs,
41− templates/S5.hs,
42− templates/DefaultHeaders.hs,
43− templates/headers/ConTeXt.header,
44− templates/headers/Docbook.header,
45− templates/headers/LaTeX.header,
46− templates/headers/OpenDocument.header,
47− templates/headers/RTF.header,
48− templates/headers/S5.header,
49− templates/ui/default/slides.js.comment,
50− templates/ui/default/slides.js.packed,
51− templates/ui/default/s5-core.css,
52− templates/ui/default/framing.css,
53− templates/ui/default/pretty.css,
54− templates/ui/default/opera.css,
55− templates/ui/default/outline.css,
56− templates/ui/default/print.css,
38+ data/ASCIIMathML.js.comment,
39+ data/ASCIIMathML.js.packed,
40+ data/headers/ConTeXt.header,
41+ data/headers/Docbook.header,
42+ data/headers/LaTeX.header,
43+ data/headers/OpenDocument.header,
44+ data/headers/RTF.header,
45+ data/headers/S5.header,
46+ data/ui/default/slides.js.comment,
47+ data/ui/default/slides.js.packed,
48+ data/ui/default/s5-core.css,
49+ data/ui/default/framing.css,
50+ data/ui/default/pretty.css,
51+ data/ui/default/opera.css,
52+ data/ui/default/outline.css,
53+ data/ui/default/print.css,
5754 odt-styles/reference.odt
58−Extra-Tmp-Files: Text/Pandoc/ASCIIMathML.hs,
59− Text/Pandoc/DefaultHeaders.hs,
60− Text/Pandoc/Writers/S5.hs
6155Flag splitBase
6256 Description: Choose the new, smaller, split-up base package.
6357 Default: True
@@ -112,6 +106,7 @@ Library
112106 Text.XML.Light.Types,
113107 Text.XML.Light.Output,
114108 Text.XML.Light.Input,
109+ Text.XML.Light.Proc,
115110 Text.XML.Light.Cursor
116111 Ghc-Options: -O2 -Wall -threaded
117112 Ghc-Prof-Options: -auto-all
templates/ASCIIMathML.hsdeleted−7
@@ -1,7 +0,0 @@
1−-- | Definitions for use of ASCIIMathML in HTML.
2−-- (See <http://www1.chapman.edu/~jipsen/mathml/asciimath.html>.)
3−module Text.Pandoc.ASCIIMathML ( asciiMathMLScript ) where
4−
5−-- | String containing ASCIIMathML javascript.
6−asciiMathMLScript :: String
7−asciiMathMLScript = "<script type=\"text/javascript\">\n" ++ @ASCIIMathML.js.comment@ ++ @ASCIIMathML.js.packed@ ++ "</script>\n"