packages feed

yesod-content-pdf 0.1.0.1 → 0.1.0.2

raw patch · 2 files changed

+20/−22 lines, 2 filesdep +blaze-builderdep +conduitPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: blaze-builder, conduit

API changes (from Hackage documentation)

- Yesod.Content.PDF: instance HasContentType (IO PDF)
- Yesod.Content.PDF: instance HasContentType PDF
- Yesod.Content.PDF: instance ToContent (IO PDF)
- Yesod.Content.PDF: instance ToTypedContent (IO PDF)
- Yesod.Content.PDF: instance ToTypedContent PDF
- Yesod.Content.PDF: type PDF = ByteString
+ Yesod.Content.PDF: PDF :: ByteString -> PDF
+ Yesod.Content.PDF: instance Yesod.Core.Content.HasContentType Yesod.Content.PDF.PDF
+ Yesod.Content.PDF: instance Yesod.Core.Content.ToContent Yesod.Content.PDF.PDF
+ Yesod.Content.PDF: instance Yesod.Core.Content.ToTypedContent Yesod.Content.PDF.PDF
+ Yesod.Content.PDF: newtype PDF

Files

src/Yesod/Content/PDF.hs view
@@ -1,4 +1,3 @@-{-# OPTIONS -fno-warn-orphans #-} -- | Utilities for serving PDF from Yesod --   Uses and depends on command line utility wkhtmltopdf to render PDF from HTML @@ -8,13 +7,14 @@ import Data.ByteString import Text.Blaze.Html import Text.Blaze.Html.Renderer.String+import Blaze.ByteString.Builder.ByteString import System.Process import System.IO.Temp import System.IO-import System.IO.Unsafe import Network.URI+import Data.Conduit -type PDF = ByteString+newtype PDF = PDF ByteString  -- | Provide MIME type "application/pdf" as a ContentType for Yesod typePDF :: ContentType@@ -26,36 +26,31 @@ instance ToTypedContent PDF where   toTypedContent = TypedContent typePDF . toContent -instance HasContentType (IO PDF) where-  getContentType _ = typePDF--instance ToTypedContent (IO PDF) where-  toTypedContent = TypedContent typePDF . toContent--instance ToContent (IO PDF) where-  toContent = toContent . unsafePerformIO+instance ToContent PDF where+  toContent (PDF bs) = ContentSource $ do+    yield $ Chunk $ fromByteString bs  -- | Use wkhtmltopdf to render a PDF given the URI pointing to an HTML document uri2PDF :: URI -> IO PDF uri2PDF uri = withSystemTempFile "output.pdf" $ uri2PDF' uri   where     uri2PDF' :: URI -> FilePath -> Handle -> IO PDF-    uri2PDF' uri tempPDFFile tempHandle = do+    uri2PDF' uri' tempPDFFile tempHandle = do       hClose tempHandle-      (_,_,_, pHandle) <- createProcess (proc "wkhtmltopdf" ["--quiet", show uri, tempPDFFile])+      (_,_,_, pHandle) <- createProcess (proc "wkhtmltopdf" ["--quiet", show uri', tempPDFFile])       _ <- waitForProcess pHandle-      Data.ByteString.readFile tempPDFFile+      PDF <$> Data.ByteString.readFile tempPDFFile  -- | Use wkhtmltopdf to render a PDF from an HTML (Text.Blaze.Html) type html2PDF :: Html -> IO PDF html2PDF html = withSystemTempFile "output.pdf" (html2PDF' html)   where     html2PDF' :: Html -> FilePath -> Handle -> IO PDF-    html2PDF' html tempPDFFile tempPDFHandle = do+    html2PDF' html' tempPDFFile tempPDFHandle = do       hClose tempPDFHandle       withSystemTempFile "input.html" $ \tempHtmlFile tempHtmlHandle -> do-        System.IO.hPutStrLn tempHtmlHandle $ renderHtml html+        System.IO.hPutStrLn tempHtmlHandle $ renderHtml html'         hClose tempHtmlHandle         (_,_,_, pHandle) <- createProcess (proc "wkhtmltopdf" ["--quiet", tempHtmlFile, tempPDFFile])         _ <- waitForProcess pHandle-        Data.ByteString.readFile tempPDFFile+        PDF <$> Data.ByteString.readFile tempPDFFile
yesod-content-pdf.cabal view
@@ -1,5 +1,5 @@ name:                yesod-content-pdf-version:             0.1.0.1+version:             0.1.0.2 synopsis:            PDF Content Type for Yesod description:         Please see README.md homepage:            https://github.com/alexkyllo/yesod-content-pdf#readme@@ -21,13 +21,16 @@                      , FlexibleInstances    build-depends:       base >= 4.7 && < 5-                     , yesod-core-                     , process-                     , bytestring+                     , blaze-builder                      , blaze-html-                     , temporary+                     , bytestring                      , directory                      , network-uri+                     , process+                     , temporary+                     , yesod-core+                     , conduit+   default-language:    Haskell2010  test-suite yesod-content-pdf-test