packages feed

Bookshelf 0.3.1 → 0.4

raw patch · 7 files changed

+91/−79 lines, 7 filesdep +containersdep +pandoc-citeprocdep −citeproc-hsdep ~pandocdep ~pandoc-types

Dependencies added: containers, pandoc-citeproc

Dependencies removed: citeproc-hs

Dependency ranges changed: pandoc, pandoc-types

Files

Bookshelf.cabal view
@@ -1,5 +1,5 @@ name:           Bookshelf-version:        0.3.1+version:        0.4 synopsis:       A simple document organizer with some wiki functionality description:    A simple document organizer with some wiki functionality category:       Text@@ -13,7 +13,7 @@ bug-reports:    http://hub.darcs.net/emax/Bookshelf/issues build-type:     Simple cabal-version:  >= 1.8-tested-with:    GHC==7.4.2+tested-with:    GHC==7.4.2, GHC==7.6.1  data-files:   bookshelf.css@@ -29,7 +29,7 @@   location:  http://hub.darcs.net/emax/Bookshelf  executable bookshelf-  build-depends:  base < 5, citeproc-hs, directory, filepath, pandoc >= 1.10, pandoc-types >= 1.10, parseargs+  build-depends:  base < 5, containers, directory, filepath, pandoc >= 1.12, pandoc-types >= 1.12, pandoc-citeproc >= 0.2, parseargs   main-is:        Bookshelf.hs   extensions:     PatternGuards 
Bookshelf.hs view
@@ -32,9 +32,10 @@  import System.Console.ParseArgs -import Text.CSL-import Text.Pandoc-import Text.Pandoc.Shared+import Text.CSL (parseCSL, readBiblioFile)+import Text.CSL.Data (getDefaultCSL)+import Text.Pandoc (getDefaultTemplate)+import Text.Pandoc.UTF8 (toStringLazy)  import Types import Generate@@ -84,7 +85,7 @@      return (dirs,files)   where-    relevant x = not $ "." `isPrefixOf` x+    relevant x = not ("." `isPrefixOf` x)   @@ -149,20 +150,21 @@     forM_ links $ \link -> do       existsFile <- doesFileExist link       existsDir  <- doesDirectoryExist link-      unless (existsFile || existsDir) $ putStrLn $ warning link+      unless (existsFile || existsDir) $ warn link     return meta   where-    warning link-       = "*Warning: link '"-      ++ link-      ++ "' does not exist in '"-      ++ (relPath shelfInfo </> shelfDocument shelfInfo)-      ++ "'."+    warn link = putStrLn $ concat+      [ "*Warning: link '"+      , link+      , "' does not exist in '"+      , (relPath shelfInfo </> shelfDocument shelfInfo)+      , "'."+      ]    -- | Generates the (sub-)bookshelf in the directory @rootPath\</\>relPath@ (see--- `Context`).+-- 'Context'). generateBookshelf :: Context -> IO () generateBookshelf context = do     clearPreviouslyGenerated path@@ -243,9 +245,9 @@     let bib = getArg args "Bib"         csl = getArg args "CSL" -    cStyle <- parseCSL =<< case csl of+    cStyle <- fmap parseCSL $ case csl of         Just cslFile -> readFile cslFile-        _            -> readDataFileUTF8 Nothing "default.csl"+        _            -> fmap toStringLazy getDefaultCSL      refs <- case bib of         Nothing -> return []
+ Documentation/Test/Document3.txt view
@@ -0,0 +1,1 @@+This is a text file. It could have been any other document type. The web browser chooses how to display it.
Documentation/Test/Notes.shelf view
@@ -7,15 +7,16 @@  These are interesting references: [@tyler2001], [@hobbs2009], [@goddard2009] +Math can look like this:++> $$ \sum a_i \cdot b_i $$+ Heading 2 =========    * Bullet 1   * Bullet 2-      * Bullet 2.1-      * Bullet 2.2-      * Bullet 2.3-  * Bullet 3+      * Sub-bullet  References ==========
Documentation/papers.bib view
@@ -1,13 +1,13 @@ @article{tyler2001,   title={Paper 1},-  author={Charles Tyler, Alice Kelly, Kyle Horton},+  author={Charles Tyler and Alice Kelly and Kyle Horton},   journal={Some journal},   year={2001} }  @article{hobbs2009,   title={Paper 2},-  author={Lara Hobbs, Lauren Simmons, Edward Burgess},+  author={Lara Hobbs and Lauren Simmons and Edward Burgess},   journal={Some journal},   year={2009} }
Generate.hs view
@@ -32,6 +32,7 @@ import Data.List import System.FilePath +import Text.CSL.Pandoc (processCites) import Text.Pandoc  import Types@@ -91,8 +92,11 @@ pandocStr :: String -> [Inline] pandocStr = intersperse Space . map Str . words +rawHtml :: String -> Block+rawHtml = RawBlock (Format "html")  + -- | Displays the relative path, with each directory name linked to its index -- file. If the `shelfDocument` field is not empty, a link to the document -- source will be added at the end of the relative path.@@ -142,9 +146,7 @@  -- | Extracts title block information. extractMeta :: Pandoc -> MetaInfo-extractMeta (Pandoc meta _) = MetaInfo title authors date [] []-  where-    Meta title authors date = meta+extractMeta (Pandoc meta _) = MetaInfo (docTitle meta) (docAuthors meta) (docDate meta) [] []   @@ -234,20 +236,21 @@ markdownToHtml :: ShelfInfo -> String -> (String, [FilePath], MetaInfo) markdownToHtml shelfInfo markdown = (html,links,meta)   where-    pandoc   = readMarkdown rOpts markdown+    pandoc   = readMarkdown def{readerSmart=True} markdown     links    = queryWith localLink pandoc     thisMeta = extractMeta pandoc     mainMeta = parseMainMeta pandoc      contextBlocks-      =  [RawBlock "html" "<div class=\"bookshelf-meta\">", makeContextPath shelfInfo]+      =  [rawHtml "<div class=\"bookshelf-meta\">", makeContextPath shelfInfo]       ++ makeMainLink shelfInfo-      ++ [RawBlock "html" "</div>"]+      ++ [rawHtml "</div>"] -    before = writeHtmlString def (Pandoc (Meta [] [] []) contextBlocks)+    before = writeHtmlString def (Pandoc nullMeta contextBlocks)      html       = writeHtmlString wOpts+      $ processCites style refs       $ bottomUp redirectLink       $ pandoc @@ -255,12 +258,8 @@       Nothing -> thisMeta       _       -> mainMeta -    rOpts = def-      { readerSmart         = True-      , readerReferences    = references $ shelfContext shelfInfo-      , readerCitationStyle = Just $ cslStyle $ shelfContext shelfInfo-      }-+    refs       = references $ shelfContext shelfInfo+    style      = cslStyle $ shelfContext shelfInfo     after      = bookshelfCreds     cssInclude = makeCss $ shelfContext shelfInfo     mathMethod = makeMath $ shelfContext shelfInfo@@ -276,6 +275,7 @@       , writerVariables       = wVars       , writerTableOfContents = True       , writerHTMLMathMethod  = mathMethod+      , writerHighlight       = True       }  @@ -317,6 +317,44 @@   +-- | Makes an item for a shelf document to be displayed in the directory index+listShelfDoc :: (FilePath, MetaInfo) -> [Block]+listShelfDoc (doc,meta) = listDocument docShelfHtml meta' doc' []+  where+    doc'         = dropExtension doc+    docShelfHtml = doc `addExtension` ".html"+    meta'        = fixTitle meta doc'++-- | Makes an item for an ordinary document with meta info to be displayed in the directory index+listInfoDoc :: (FilePath, MetaInfo) -> [Block]+listInfoDoc (doc,meta) = listDocument doc meta' doc info+  where+    meta'        = fixTitle meta doc+    docShelfHtml = replaceExtension doc ".shelf" `addExtension` ".html"+    info =+      [ Str "("+      , Link+         (pandocStr "info")+         (docShelfHtml, "View document information")+      , Str ")"+      ]++-- | Makes an item for an ordinary document without meta info to be displayed in the directory index+listOrdDoc :: Monad m => String -> m Block+listOrdDoc doc = return $ Plain+  [Link (pandocStr doc) (doc, "View '" ++ doc ++ "'")]++-- | Makes an item for an sub-directory to be displayed in the directory index+listDir :: Monad m => String -> m Block+listDir dir = return $ Plain+  [ Link+      (pandocStr dir)+      (dir </> "index.html", "Go to directory '" ++ dir ++ "'")+  , LineBreak+  ]+++ -- | @makeIndex context shelfs infos ords dirs@: -- -- Makes an HTML file with the index of the current directory. @shelfs@ is a@@ -335,14 +373,13 @@ makeIndex context shelfs infos ords dirs = writeHtmlString wOpts pandoc   where     contextBlocks =-      [ RawBlock "html" "<div class=\"bookshelf-meta\">"+      [ rawHtml "<div class=\"bookshelf-meta\">"       , makeContextPath (ShelfInfo context Nothing "")-      , RawBlock "html" "</div>"+      , rawHtml "</div>"       ] -    before = writeHtmlString def (Pandoc (Meta [] [] []) contextBlocks)--    after = bookshelfCreds+    before = writeHtmlString def (Pandoc nullMeta contextBlocks)+    after  = bookshelfCreds      wVars =       [ ("include-before", before)@@ -357,7 +394,9 @@       , writerHTMLMathMethod  = makeMath context       } -    pandoc = Pandoc (Meta [] [] []) ([Para [LineBreak]] ++ docBlocks ++ dirBlocks)+    shelfBlocks = map listShelfDoc $ sortBy (compare `on` fst) shelfs+    infoBlocks  = map listInfoDoc  $ sortBy (compare `on` fst) infos+    ordBlocks   = map listOrdDoc   $ sort ords      docBlocks = do       guard (0 < length shelfs + length infos + length ords)@@ -367,40 +406,9 @@        , BulletList ordBlocks        ] -    shelfBlocks = map listShelfDoc $ sortBy (compare `on` fst) shelfs-    infoBlocks  = map listInfoDoc  $ sortBy (compare `on` fst) infos-    ordBlocks   = map listOrdDoc   $ sort ords-     dirBlocks = do       guard (not $ null dirs)       [Header 2 nullAttr [Str "Directories"]] ++ [BulletList $ map listDir $ sort dirs] -    listShelfDoc (doc,meta) = listDocument docShelfHtml meta' doc' []-      where-        doc'         = dropExtension doc-        docShelfHtml = doc `addExtension` ".html"-        meta'        = fixTitle meta doc'--    listInfoDoc (doc,meta) = listDocument doc meta' doc info-      where-        meta'        = fixTitle meta doc-        docShelfHtml = replaceExtension doc ".shelf" `addExtension` ".html"-        info =-          [ Str "("-          , Link-             (pandocStr "info")-             (docShelfHtml, "View document information")-          , Str ")"-          ]---    listOrdDoc doc = return $ Plain-      [Link (pandocStr doc) (doc, "View '" ++ doc ++ "'")]--    listDir dir = return $ Plain-      [ Link-          (pandocStr dir)-          (dir </> "index.html", "Go to directory '" ++ dir ++ "'")-      , LineBreak-      ]+    pandoc = Pandoc nullMeta ([Para [LineBreak]] ++ docBlocks ++ dirBlocks) 
bookshelf.css view
@@ -9,9 +9,9 @@   padding-bottom: 0.5em;   padding-right: 1em;   padding-left: 1em;-  border-right: 2px solid #AAF;-  border-left: 2px solid #AAF;-  border-bottom: 1px solid #888;+  border-right: 3px solid #8AC;+  border-left: 3px solid #8AC;+  border-bottom: 1px solid #89A;   max-width: 56em;   font-family: verdana, sans-serif;   font-size: 85%;@@ -20,7 +20,8 @@ }  pre {-  border: 1px dotted gray;+  border: 1px solid #CCC;+  border-left: 3px solid gray;   background-color: #ececec;   color: #1111111;   padding: 0.5em;@@ -29,7 +30,6 @@  code {   font-family: monospace;-  font-size: 115%;   white-space: pre-wrap; }