Skip to content

Commit

Permalink
added epub-cover-image support
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Soares committed Dec 27, 2011
1 parent 501ec60 commit bc5e1da
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ BUGS:
No template can access the book title in 'vars'

TODO:
add a 'epub-cover-image' option
add a 'silent' option
clean up environment handling in section
clean up pandoc format handling
Expand Down
1 change: 1 addition & 0 deletions bookbuilder.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Executable bookbuilder
base >= 4 && < 5,
Dangerous >= 0.2.2,
Focus >= 0.1.2,
MissingH >= 1.1,
Configger >= 0.1,
Limit >= 1.0,
bytestring >= 0.9,
Expand Down
17 changes: 13 additions & 4 deletions src/Target/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Control.Monad.Trans
import Control.Monad.Loops
import Control.Dangerous hiding ( Warning )
import Data.Char
import Data.List.Utils hiding ( merge )
import qualified Data.Configger as Configger
import Data.Configger ( Config )
import Data.Maybe
Expand All @@ -33,9 +34,10 @@ import Text.Printf
configFile :: String
configFile = "config"

variableSection, optionSection :: String
variableSection, optionSection, localSection :: String
variableSection = "VARIABLES"
optionSection = "OPTIONS"
localSection = "LOCAL"

styleFile, resourceFile, metadataFile :: String
styleFile = "style.css"
Expand All @@ -54,8 +56,12 @@ debugOption = "debug"

-- | Config file loading and manipulation

isCover :: String -> Bool
isCover f = startswith "cover-image." name || startswith "cover." name
where name = takeFileName f

isSpecial :: FilePath -> Bool
isSpecial = flip elem special . takeFileName where
isSpecial f = isCover f || (takeFileName f) `elem` special where
special = [configFile, styleFile, resourceFile, metadataFile]

isConfig :: FilePath -> Bool
Expand All @@ -75,7 +81,7 @@ load path = do
hasStyle <- liftIO $ doesFileExist sfile
hasResources <- liftIO $ doesFileExist rfile
hasMetadata <- liftIO $ doesFileExist mfile
conf <- raw path
basic <- raw path
let setStyle c = do
css <- liftIO $ readFile sfile
return $ setOption styleOption css c
Expand All @@ -86,7 +92,10 @@ load path = do
let setters = [setStyle | hasStyle] ++
[setResources | hasResources] ++
[setMetadata | hasMetadata]
concatM setters conf
conf <- concatM setters basic
let locals = Configger.items localSection conf
let mapped = map (\(x, y) -> (x, path </> y)) locals
return $ Configger.mergeSection (variableSection, mapped) conf

merge :: Config -> FilePath -> String -> DangerousT IO Config
merge conf dir fmt = let name = takeFileName dir in do
Expand Down
4 changes: 3 additions & 1 deletion src/Target/Pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ write format conf dest doc = case lookup format writers of
Nothing -> writeFile dest $ defaultWriter opts doc'
Just r -> writeFile dest $ r opts doc'
where opts = defaultWriterOptions
epubOpts = opts{ writerEPUBMetadata = metadata }
epubOpts = opts{ writerEPUBMetadata = metadata
, writerVariables = [("epub-cover-image", cover) |
cover <- Config.values "epub-cover-image" conf] }
metadata = fromMaybe "" (Config.metadata conf)
doc' = doc `withDefaultData` conf

Expand Down

0 comments on commit bc5e1da

Please sign in to comment.