packages feed

servant-static-th 0.1.0.3 → 0.1.0.4

raw patch · 3 files changed

+21/−14 lines, 3 filesnew-uploaderPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Servant.Static.TH.Internal.Mime: utf8ByteStringToExp :: ByteString -> Q Exp

Files

example/Example.hs view
@@ -9,17 +9,17 @@ import Servant.Server (serve) import Servant.Static.TH (createApiAndServerDecs) --- 'createApiAndServerDecs' will use the files in the directory @test/test-dir@+-- 'createApiAndServerDecs' will use the files in the directory @example/example-dir@ -- to create two things. ----- Let's assume that the @test/test-dir@ directory looks like this:+-- Let's assume that the @example/example-dir@ directory looks like this: -- -- @---   $ tree test/test-dir/---   test/test-dir/+--   $ tree example/example-dir/+--   example/example-dir/ --   ├── dir --   │   ├── inner-file.html---   │   └── test.js+--   │   └── example.js --   └── hello.html -- @ --@@ -29,14 +29,14 @@ --   type FrontEndApi = --       "dir" :> --         ( "inner-file.html" :> Get '[HTML] Html :<|>---           "test.js" :> Get '[JS] ByteString+--           "example.js" :> Get '[JS] ByteString --         ) :<|> --       "hello.html" :> Get '[HTML] Html -- @ -- -- Next, the following function will be created.  This function represents a -- Servant server for the @FrontEndApi@.  It basically just returns the content--- from the files in the @test/test-dir@ directory.  The contents from the files+-- from the files in the @example/example-dir@ directory.  The contents from the files -- is statically embedded in the @frontEndServer@ function at compile fime: -- -- @@@ -55,11 +55,11 @@ --   Hello World --   $ curl localhost:8080/dir/inner-file.html --   Inner File---   $ curl localhost:8080/dir/test.js+--   $ curl localhost:8080/dir/example.js --   console.log(\"hello world\"); -- @ -$(createApiAndServerDecs "FrontEndApi" "frontEndServer" "test/test-dir")+$(createApiAndServerDecs "FrontEndApi" "frontEndServer" "example/example-dir")  app :: Application app = serve (Proxy :: Proxy FrontEndApi) frontEndServer
servant-static-th.cabal view
@@ -1,5 +1,5 @@ name:                servant-static-th-version:             0.1.0.3+version:             0.1.0.4 synopsis:            Embed a directory of static files in your Servant server description:         Please see <https://github.com/cdepillabout/servant-static-th#readme README.md>. homepage:            https://github.com/cdepillabout/servant-static-th
src/Servant/Static/TH/Internal/Mime.hs view
@@ -28,11 +28,11 @@ import qualified Data.Map as Map import Data.Monoid ((<>)) import Data.Proxy (Proxy)-import Data.Text (unpack)-import Data.Text.Encoding (decodeUtf8With)+import Data.Text (pack, unpack)+import Data.Text.Encoding (decodeUtf8With, encodeUtf8) import Data.Text.Encoding.Error (lenientDecode) import Data.Typeable (Typeable)-import Language.Haskell.TH (Exp, Q, Type)+import Language.Haskell.TH (Exp, Q, Type, appE, stringE, varE) import Network.HTTP.Media (MediaType, (//)) import Servant.HTML.Blaze (HTML) import Servant.API (Accept(contentType), MimeRender(mimeRender))@@ -68,6 +68,13 @@   let word8List = ByteString.unpack byteString   in [e|pure $ ByteString.pack word8List|] +utf8ByteStringToExp :: ByteString -> Q Exp+utf8ByteStringToExp byteString =+  let stringExp = stringE . unpack $ decodeUtf8With lenientDecode byteString+      packedExp = appE (varE 'pack) stringExp+      byteStringExp = appE (varE 'encodeUtf8) packedExp+  in appE (varE 'pure) byteStringExp+ htmlToExp :: ByteString -> Q Exp htmlToExp byteString =   let fileContentsString = unpack $ decodeUtf8With lenientDecode byteString@@ -83,7 +90,7 @@   , ("html", MimeTypeInfo [t|HTML|] [t|Html|] htmlToExp)   , ("jpeg", MimeTypeInfo [t|JPEG|] [t|ByteString|] byteStringToExp)   , ("jpg", MimeTypeInfo [t|JPEG|] [t|ByteString|] byteStringToExp)-  , ("js", MimeTypeInfo [t|JS|] [t|ByteString|] byteStringToExp)+  , ("js", MimeTypeInfo [t|JS|] [t|ByteString|] utf8ByteStringToExp)   , ("png", MimeTypeInfo [t|PNG|] [t|ByteString|] byteStringToExp)   , ("txt", MimeTypeInfo [t|TXT|] [t|ByteString|] byteStringToExp)   ]