git.iko.soy/typeable/pandoc
on master help sign in
Use template haskell to store reference.odt as blob in pandoc.

+ Added contentsOf to Text.Pandoc.Shared. + Use this to get contents of reference.odt at compile time in Text.Pandoc.ODT + Added bytestring and template-haskell dependencies to pandoc.cabal. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1355 788f1e2b-df1e-0410-8736-df70ead52e1b

commit5abc79cff1877eeef4dfc1c688023c62f78858dc authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateFri 1 Aug 2008, 06:34 (18 years ago) parentc45833a
3 files changed+22−7
Text/Pandoc/ODT.hs+6−3 Text/Pandoc/Shared.hs+13−1 pandoc.cabal+3−3
Text/Pandoc/ODT.hs+6−3
@@ -1,3 +1,4 @@
1+{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}
12{-
23Copyright (C) 2008 John MacFarlane <jgm@berkeley.edu>
34
@@ -28,6 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2829Functions for producing an ODT file from OpenDocument XML.
2930-}
3031module Text.Pandoc.ODT ( saveOpenDocumentAsODT ) where
32+import Text.Pandoc.Shared ( contentsOf )
3133import Data.Maybe ( fromJust )
3234import Data.List ( partition, intersperse )
3335import Prelude hiding ( writeFile, readFile )
@@ -41,7 +43,7 @@ import Text.XML.Light
4143import Text.XML.Light.Cursor
4244import Text.Pandoc.Shared ( withTempDir )
4345import Network.URI ( isURI )
44−import Paths_pandoc
46+import qualified Data.ByteString.Char8 as B ( writeFile )
4547
4648-- | Produce an ODT file from OpenDocument XML.
4749saveOpenDocumentAsODT :: FilePath -- ^ Pathname of ODT file to be produced.
@@ -59,10 +61,10 @@ saveOpenDocumentAsODT destinationODTPath sourceDirRelative xml = do
5961 "It can be obtained from http://www.info-zip.org/Zip.html\n" ++
6062 "Debian (and Debian-based) linux: apt-get install zip\n" ++
6163 "Windows: See http://gnuwin32.sourceforge.net/packages/zip.htm"
62− referenceODTPath <- getDataFileName "reference.odt"
6364 withTempDir "pandoc-odt" $ \tempDir -> do
6465 let tempODT = tempDir </> "reference.odt"
65− copyFile referenceODTPath tempODT
66+ copyFile "odt-styles/reference.odt" tempODT
67+ B.writeFile tempODT $(contentsOf "odt-styles/reference.odt")
6668 createDirectory $ tempDir </> "Pictures"
6769 xml' <- handlePictures tempODT sourceDirRelative xml
6870 writeFile (tempDir </> "content.xml") xml'
@@ -138,3 +140,4 @@ handleContent tempODT sourceDirRelative content@(Elem el) = do
138140 else return content
139141
140142handleContent _ _ c = return c -- not Element
143+
Text/Pandoc/Shared.hs+13−1
@@ -100,7 +100,9 @@ module Text.Pandoc.Shared (
100100 WriterOptions (..),
101101 defaultWriterOptions,
102102 -- * File handling
103− withTempDir
103+ withTempDir,
104+ -- * Template haskell
105+ contentsOf
104106 ) where
105107
106108import Text.Pandoc.Definition
@@ -115,6 +117,9 @@ import Network.URI ( parseURI, URI (..), isAllowedInURI )
115117import System.FilePath ( (</>), (<.>) )
116118import System.IO.Error ( catch, ioError, isAlreadyExistsError )
117119import System.Directory
120+import Language.Haskell.TH
121+import Language.Haskell.TH.Syntax (Lift (..))
122+import qualified Data.ByteString.Char8 as B
118123
119124--
120125-- List processing
@@ -924,3 +929,10 @@ createTempDir num baseName = do
924929 then createTempDir (num + 1) baseName
925930 else ioError e
926931
932+-- | Template haskell function to insert bytestring contents of file into a template.
933+contentsOf :: FilePath -> ExpQ
934+contentsOf p = lift =<< runIO (B.readFile p)
935+
936+instance Lift B.ByteString where
937+ lift x = return (LitE (StringL $ B.unpack x))
938+
pandoc.cabal+3−3
@@ -53,11 +53,11 @@ Extra-Source-Files: README, INSTALL, COPYRIGHT, COPYING,
5353 templates/ui/default/pretty.css,
5454 templates/ui/default/opera.css,
5555 templates/ui/default/outline.css,
56− templates/ui/default/print.css
56+ templates/ui/default/print.css,
57+ odt-styles/reference.odt
5758Extra-Tmp-Files: Text/Pandoc/ASCIIMathML.hs,
5859 Text/Pandoc/DefaultHeaders.hs,
5960 Text/Pandoc/Writers/S5.hs
60−Data-Files: odt-styles/reference.odt
6161Flag splitBase
6262 Description: Choose the new, smaller, split-up base package.
6363 Default: True
@@ -79,7 +79,7 @@ Library
7979 if flag(highlighting)
8080 Build-depends: highlighting-kate
8181 cpp-options: -DHIGHLIGHTING
82− Build-Depends: parsec < 3, xhtml, mtl, network, filepath, process, directory, utf8-string
82+ Build-Depends: parsec < 3, xhtml, mtl, network, filepath, process, directory, utf8-string, template-haskell, bytestring
8383 Hs-Source-Dirs: .
8484 Exposed-Modules: Text.Pandoc,
8585 Text.Pandoc.Blocks,