packages feed

yesod-content-pdf 0.1.0.0 → 0.1.0.1

raw patch · 2 files changed

+25/−22 lines, 2 filesdep +network-uriPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: network-uri

API changes (from Hackage documentation)

- Yesod.Content.PDF: html2PDF' :: Html -> FilePath -> Handle -> IO PDF
- Yesod.Content.PDF: url2PDF :: String -> IO PDF
- Yesod.Content.PDF: url2PDF' :: String -> FilePath -> Handle -> IO PDF
+ Yesod.Content.PDF: uri2PDF :: URI -> IO PDF

Files

src/Yesod/Content/PDF.hs view
@@ -12,9 +12,11 @@ import System.IO.Temp import System.IO import System.IO.Unsafe+import Network.URI  type PDF = ByteString +-- | Provide MIME type "application/pdf" as a ContentType for Yesod typePDF :: ContentType typePDF = "application/pdf" @@ -28,32 +30,32 @@   getContentType _ = typePDF  instance ToTypedContent (IO PDF) where-  toTypedContent ioPDF = TypedContent typePDF $ toContent ioPDF+  toTypedContent = TypedContent typePDF . toContent  instance ToContent (IO PDF) where   toContent = toContent . unsafePerformIO --- | Use wkhtmltopdf to render a PDF given the URL to an HTML document-url2PDF :: String -> IO PDF-url2PDF url = withSystemTempFile "output.pdf" (url2PDF' url)--url2PDF' :: String -> FilePath -> Handle -> IO PDF-url2PDF' url tempPDFFile tempHandle = do-  hClose tempHandle-  (_,_,_, pHandle) <- createProcess (proc "wkhtmltopdf" ["--quiet", url, tempPDFFile])-  _ <- waitForProcess pHandle-  Data.ByteString.readFile tempPDFFile+-- | 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+      hClose tempHandle+      (_,_,_, pHandle) <- createProcess (proc "wkhtmltopdf" ["--quiet", show uri, tempPDFFile])+      _ <- waitForProcess pHandle+      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)--html2PDF' :: Html -> FilePath -> Handle -> IO PDF-html2PDF' html tempPDFFile tempPDFHandle = do-  hClose tempPDFHandle-  withSystemTempFile "input.html" $ \tempHtmlFile tempHtmlHandle -> do-    System.IO.hPutStrLn tempHtmlHandle $ renderHtml html-    hClose tempHtmlHandle-    (_,_,_, pHandle) <- createProcess (proc "wkhtmltopdf" ["--quiet", tempHtmlFile, tempPDFFile])-    _ <- waitForProcess pHandle-    Data.ByteString.readFile tempPDFFile+  where+    html2PDF' :: Html -> FilePath -> Handle -> IO PDF+    html2PDF' html tempPDFFile tempPDFHandle = do+      hClose tempPDFHandle+      withSystemTempFile "input.html" $ \tempHtmlFile tempHtmlHandle -> do+        System.IO.hPutStrLn tempHtmlHandle $ renderHtml html+        hClose tempHtmlHandle+        (_,_,_, pHandle) <- createProcess (proc "wkhtmltopdf" ["--quiet", tempHtmlFile, tempPDFFile])+        _ <- waitForProcess pHandle+        Data.ByteString.readFile tempPDFFile
yesod-content-pdf.cabal view
@@ -1,5 +1,5 @@ name:                yesod-content-pdf-version:             0.1.0.0+version:             0.1.0.1 synopsis:            PDF Content Type for Yesod description:         Please see README.md homepage:            https://github.com/alexkyllo/yesod-content-pdf#readme@@ -27,6 +27,7 @@                      , blaze-html                      , temporary                      , directory+                     , network-uri   default-language:    Haskell2010  test-suite yesod-content-pdf-test