web-output (empty) → 0.3.0.0
raw patch · 5 files changed
+106/−0 lines, 5 filesdep +basedep +directorydep +filepathsetup-changed
Dependencies added: base, directory, filepath, open-browser, temporary, text
Files
- LICENSE +16/−0
- Setup.hs +2/−0
- WebOutput.hs +36/−0
- test.hs +7/−0
- web-output.cabal +45/−0
+ LICENSE view
@@ -0,0 +1,16 @@+Poetic License+==============++© 2014 Francesco Occhipinti++This work ‘as-is’ I provide.+No warranty express or implied.+ For no purpose fit,+ not even a wee bit.+Liability for damages denied.++Permission is granted hereby,+to copy, share, and modify.+ Use it with glee,+ for profit or free.+On this notice, these rights rely.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ WebOutput.hs view
@@ -0,0 +1,36 @@+module WebOutput where++import System.IO.Temp (openTempFile, createTempDirectory)+import Web.Browser (openBrowser)+import System.IO (hPutStr, hFlush)+import System.Directory (getTemporaryDirectory)+import System.FilePath.Posix (combine, FilePath)+import qualified Data.Text as T+import qualified Data.Text.IO as T++toTheBrowser content = do+ dir <- getTemporaryDirectory+ path <- writeContentToTempFile dir content "output.html"+ openBrowser path+ where+ writeContentToTempFile dir content fileName = do+ (path, handle) <- openTempFile dir "output.html"+ hPutStr handle content+ hFlush handle+ return path++data Resource = Resource {+ location :: FilePath,+ content :: T.Text+}++writeResource (Resource loc con) = T.writeFile loc con++manyToTheBrowser resources = do+ dir <- getTemporaryDirectory+ containing <- createTempDirectory dir "output"+ mapM writeResource (combined containing)+ (openBrowser . location . head) (combined containing)+ where+ combined dir = map (applyLocation (combine dir)) resources+ applyLocation f (Resource a b) = Resource (f a) b
+ test.hs view
@@ -0,0 +1,7 @@+{-# LANGUAGE OverloadedStrings #-}+import WebOutput++s = ("script.js", "window.onload = alert('it works')")+i = ("index.html", "<script src=\"script.js\"></script>")++main = multiToTheBrowser [i, s]
+ web-output.cabal view
@@ -0,0 +1,45 @@+-- Initial web-output.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++name: web-output+version: 0.3.0.0+synopsis: Library to present content to an user via their browser+description: Library to present content to an user via their browser+homepage: https://github.com/danse/web-output+license: PublicDomain+license-file: LICENSE+author: danse+maintainer: f.occhipinti@gmail.com+-- copyright: +category: Scripting+build-type: Simple+-- extra-source-files: +cabal-version: >=1.10++library+ exposed-modules: WebOutput+ -- other-modules: + -- other-extensions: + build-depends: base >=4.8 && <4.9,+ temporary,+ open-browser,+ directory,+ filepath,+ text+ -- hs-source-dirs: + default-language: Haskell2010+ +Test-Suite test+ type: exitcode-stdio-1.0+ main-is: test.hs+ build-depends: base,+ temporary,+ open-browser,+ directory,+ filepath,+ text+ default-language: Haskell2010++source-repository head+ type: git+ location: git@github.com:danse/web-output.git