yesod-static-remote (empty) → 0.0.0.0
raw patch · 5 files changed
+133/−0 lines, 5 filesdep +basedep +bytestringdep +directory
Dependencies added: base, bytestring, directory, filepath, http-client, http-client-tls, template-haskell, yesod-static, yesod-static-remote
Files
- LICENSE +21/−0
- README.md +1/−0
- src/Yesod/EmbeddedStatic/Remote.hs +37/−0
- test/Spec.hs +17/−0
- yesod-static-remote.cabal +57/−0
+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2019 Tom Sydney Kerckhove++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ README.md view
@@ -0,0 +1,1 @@+# remote-static
+ src/Yesod/EmbeddedStatic/Remote.hs view
@@ -0,0 +1,37 @@+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}++module Yesod.EmbeddedStatic.Remote+ ( embedRemoteFileAt+ , ensureFile+ ) where++import Control.Monad+import qualified Data.ByteString.Lazy as LB+import Language.Haskell.TH+import Network.HTTP.Client+import Network.HTTP.Client.TLS+import System.Directory+import System.FilePath+import Yesod.EmbeddedStatic+import Yesod.EmbeddedStatic.Types++-- | Embed a file after downloading it (once, and caching it locally)+embedRemoteFileAt ::+ FilePath -- ^ The path to put it (relative)+ -> String -- ^ The url to download it from+ -> Generator+embedRemoteFileAt fp url = do+ runIO $ ensureFile fp url+ embedFile fp++ensureFile :: FilePath -> String -> IO ()+ensureFile rp url = do+ createDirectoryIfMissing True $ takeDirectory rp+ exists <- doesFileExist rp+ unless exists $ do+ man <- newManager tlsManagerSettings+ putStrLn $ unwords ["Downloading", url, "to put it at", rp]+ req <- parseUrlThrow url+ resp <- httpLbs req man+ LB.writeFile rp $ responseBody resp
+ test/Spec.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE TemplateHaskell #-}++module Main where++import Yesod.EmbeddedStatic+import Yesod.EmbeddedStatic.Remote++mkEmbeddedStatic+ False+ "myStatic"+ [ embedRemoteFileAt+ "tmp/test/deep/README.md"+ "https://raw.githubusercontent.com/NorfairKing/yesod-static-remote/master/README.md"+ ]++main :: IO ()+main = pure ()
+ yesod-static-remote.cabal view
@@ -0,0 +1,57 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.1.+--+-- see: https://github.com/sol/hpack+--+-- hash: 1fa979e2ae3a67d8c5387c3970bda5bfe431c85f03fe6dbbd5498ff32d46b908++name: yesod-static-remote+version: 0.0.0.0+description: Please see the README on GitHub at <https://github.com/NorfairKing/remote-static#readme>+homepage: https://github.com/NorfairKing/yesod-static-remote#readme+bug-reports: https://github.com/NorfairKing/yesod-static-remote/issues+author: Tom Sydney Kerckhove+maintainer: syd@cs-syd.eu+copyright: Copyright: (c) 2019 Tom Sydney Kerckhove+license: MIT+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md++source-repository head+ type: git+ location: https://github.com/NorfairKing/yesod-static-remote++library+ exposed-modules:+ Yesod.EmbeddedStatic.Remote+ other-modules:+ Paths_yesod_static_remote+ hs-source-dirs:+ src+ build-depends:+ base >=4.7 && <5+ , bytestring+ , directory+ , filepath+ , http-client+ , http-client-tls+ , template-haskell+ , yesod-static+ default-language: Haskell2010++test-suite remote-static-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Paths_yesod_static_remote+ hs-source-dirs:+ test+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ base >=4.7 && <5+ , yesod-static+ , yesod-static-remote+ default-language: Haskell2010