yesod-static 1.6.1.0 → 1.6.1.1
raw patch · 16 files changed
+99/−74 lines, 16 filesdep +cryptondep +crypton-conduitdep −cryptonitedep −cryptonite-conduitdep ~basenew-uploader
Dependencies added: crypton, crypton-conduit
Dependencies removed: cryptonite, cryptonite-conduit
Dependency ranges changed: base
Files
- ChangeLog.md +8/−0
- Yesod/EmbeddedStatic.hs +6/−7
- Yesod/EmbeddedStatic/Css/AbsoluteUrl.hs +1/−0
- Yesod/EmbeddedStatic/Css/Util.hs +8/−5
- Yesod/EmbeddedStatic/Generators.hs +16/−15
- Yesod/EmbeddedStatic/Internal.hs +2/−13
- Yesod/EmbeddedStatic/Types.hs +5/−2
- Yesod/Static.hs +9/−10
- sample-embed.hs +5/−2
- sample.hs +4/−1
- test/EmbedDevelTest.hs +5/−1
- test/EmbedProductionTest.hs +5/−1
- test/EmbedTestGenerator.hs +4/−1
- test/FileGeneratorTests.hs +9/−6
- test/GeneratorTestUtil.hs +5/−3
- yesod-static.cabal +7/−7
ChangeLog.md view
@@ -1,5 +1,13 @@ # ChangeLog for yesod-static +## 1.6.1.2++* Set `base >= 4.11` for less CPP and imports [#1876](https://github.com/yesodweb/yesod/pull/1876)++## 1.6.1.1++* Use crypton instead of cryptonite [#1838](https://github.com/yesodweb/yesod/pull/1838)+ ## 1.6.1.0 * Support reproducible embedded file order [#1684](https://github.com/yesodweb/yesod/issues/1684#issuecomment-652562514)
Yesod/EmbeddedStatic.hs view
@@ -1,13 +1,13 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-} {-# OPTIONS_GHC -fno-warn-orphans #-}+ -- | A subsite which serves static content which is embedded at compile time. -- -- At compile time, you supply a list of files, directories, processing functions (like javascript@@ -49,7 +49,6 @@ , module Yesod.EmbeddedStatic.Generators ) where -import Control.Applicative as A ((<$>)) import Data.IORef import Data.Maybe (catMaybes) import Language.Haskell.TH@@ -98,7 +97,7 @@ , ValD (VarP name) (NormalB link) [] ] --- | Creates an 'EmbeddedStatic' by running, at compile time, a list of generators. +-- | Creates an 'EmbeddedStatic' by running, at compile time, a list of generators. -- Each generator produces a list of entries to embed into the executable. -- -- This template haskell splice creates a variable binding holding the resulting@@ -132,7 +131,7 @@ -> [Generator] -- ^ the generators (see "Yesod.EmbeddedStatic.Generators") -> Q [Dec] mkEmbeddedStatic dev esName gen = do- entries <- concat A.<$> sequence gen+ entries <- concat <$> sequence gen computed <- runIO $ mapM (if dev then devEmbed else prodEmbed) entries let settings = Static.mkSettings $ return $ map cStEntry computed
Yesod/EmbeddedStatic/Css/AbsoluteUrl.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+ -- | Manipulate CSS urls. -- -- * Make relative urls absolute (useful when combining assets)
Yesod/EmbeddedStatic/Css/Util.hs view
@@ -1,10 +1,14 @@-{-# LANGUAGE OverloadedStrings, QuasiQuotes, TemplateHaskell, TupleSections, GeneralizedNewtypeDeriving #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TupleSections #-}+ module Yesod.EmbeddedStatic.Css.Util where -import Control.Applicative+import Control.Applicative ((<|>)) import Control.Monad (void, foldM) import Data.Hashable (Hashable)-import Data.Monoid import Network.Mime (MimeType, defaultMimeLookup) import Text.CSS.Parse (parseBlocks) import Language.Haskell.TH (litE, stringL)@@ -68,8 +72,7 @@ parseCssWith :: (T.Text -> T.Text -> EithUrl) -> T.Text -> Either String Css parseCssWith urlParser contents =- let mparsed = parseBlocks contents in- case mparsed of+ case parseBlocks contents of Left err -> Left err Right blocks -> Right [ (t, map (uncurry urlParser) b) | (t,b) <- blocks ]
Yesod/EmbeddedStatic/Generators.hs view
@@ -1,4 +1,7 @@-{-# LANGUAGE TemplateHaskell, QuasiQuotes, ScopedTypeVariables #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-}+ -- | A generator is executed at compile time to load a list of entries -- to embed into the subsite. This module contains several basic generators, -- but the design of generators and entries is such that it is straightforward@@ -30,10 +33,9 @@ -- $example ) where -import Control.Applicative as A ((<$>), (<*>)) import Control.Exception (try, SomeException) import Control.Monad (forM, when)-import Data.Char (isDigit, isLower)+import Data.Char (isLower) import Data.Default (def) import Data.Maybe (isNothing) import Language.Haskell.TH@@ -93,7 +95,7 @@ return (concat paths) -- | Embed all files in a directory into the static subsite.--- +-- -- Equivalent to passing the empty string as the location to 'embedDirAt', -- so the directory path itself is not part of the resource locations (and so -- also not part of the generated route variable names).@@ -112,7 +114,7 @@ -- * js/jquery.js -- -- * js/bootstrap.js--- +-- -- then @embedDirAt \"somefolder\" \"static\"@ will -- -- * Make the file @static\/css\/bootstrap.css@ available at the location@@ -207,9 +209,9 @@ } (Just hin, Just hout, _, ph) <- Proc.createProcess p (compressed, (), code) <- runConcurrently $ (,,)- A.<$> Concurrently (runConduit $ sourceHandle hout .| sinkLazy)- A.<*> Concurrently (BL.hPut hin ct >> hClose hin)- A.<*> Concurrently (Proc.waitForProcess ph)+ <$> Concurrently (runConduit $ sourceHandle hout .| sinkLazy)+ <*> Concurrently (BL.hPut hin ct >> hClose hin)+ <*> Concurrently (Proc.waitForProcess ph) if code == ExitSuccess then do putStrLn $ "Compressed successfully with " ++ f@@ -246,11 +248,10 @@ | otherwise = '_' name = map replace f routeName = mkName $- case () of- ()- | null name -> error "null-named file"- | isDigit (head name) -> '_' : name- | isLower (head name) -> name+ case name of+ [] -> error "null-named file"+ n : _+ | isLower n -> name | otherwise -> '_' : name @@ -295,7 +296,7 @@ -- -- Here is a small example yesod program using this generator. Try toggling -- the development argument to @mkEmbeddedStatic@.--- +-- -- >{-# LANGUAGE TemplateHaskell, QuasiQuotes, TypeFamilies #-} -- >module Main where -- >@@ -321,7 +322,7 @@ -- >getHomeR :: Handler Html -- >getHomeR = defaultLayout $ [whamlet| -- ><h1>Hello--- ><p>Check the +-- ><p>Check the -- > <a href=@{StaticR compile_time_json}>compile time -- >|] -- >
Yesod/EmbeddedStatic/Internal.hs view
@@ -3,7 +3,7 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE CPP #-}+ module Yesod.EmbeddedStatic.Internal ( EmbeddedStatic(..) , Route(..)@@ -16,7 +16,6 @@ , widgetSettings ) where -import Control.Applicative as A ((<$>)) import Data.IORef import Language.Haskell.TH import Network.HTTP.Types (Status(..), status404, status200, status304)@@ -40,16 +39,6 @@ import Yesod.Static (base64md5) import Yesod.EmbeddedStatic.Types -#if !MIN_VERSION_base(4,6,0)--- copied from base-atomicModifyIORef' :: IORef a -> (a -> (a,b)) -> IO b-atomicModifyIORef' ref f = do- b <- atomicModifyIORef ref- (\x -> let (a, b) = f x- in (a, a `seq` b))- b `seq` return b-#endif- -- | The subsite for the embedded static file server. data EmbeddedStatic = EmbeddedStatic { stApp :: !Application@@ -144,7 +133,7 @@ -> (BL.ByteString -> Either a BL.ByteString) -> AddStaticContent site staticContentHelper getStatic staticR minify ext _ ct = do- wIORef <- widgetFiles . getStatic A.<$> getYesod+ wIORef <- widgetFiles . getStatic <$> getYesod let hash = T.pack $ base64md5 ct hash' = Just $ T.encodeUtf8 hash filename = T.concat [hash, ".", ext]
Yesod/EmbeddedStatic/Types.hs view
@@ -1,4 +1,7 @@-{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+ module Yesod.EmbeddedStatic.Types( Location , Generator@@ -32,7 +35,7 @@ -- given name will be created which points to this resource. , ebLocation :: Location -- ^ The location to serve the resource from. , ebMimeType :: MimeType -- ^ The mime type of the resource.- , ebProductionContent :: IO BL.ByteString + , ebProductionContent :: IO BL.ByteString -- ^ If the development argument to 'Yesod.EmbeddedStatic.mkEmbeddedStatic' is False, -- then at compile time this action will be executed to load the content. -- During development, this action will not be executed.
Yesod/Static.hs view
@@ -1,12 +1,12 @@-{-# LANGUAGE QuasiQuotes #-}-{-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE CPP #-}+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeFamilies #-} --------------------------------------------------------- -- -- | Serve static files from a Yesod app.@@ -87,7 +87,7 @@ import qualified Data.Text as T import qualified Data.Map as M import Data.IORef (readIORef, newIORef, writeIORef)-import Data.Char (isLower, isDigit)+import Data.Char (isLower) import Data.List (foldl') import qualified Data.ByteString as S import System.PosixCompat.Files (getFileStatus, modificationTime)@@ -392,11 +392,10 @@ mkRoute (alias, f) = do let name' = intercalate "_" $ map (map replace') alias routeName = mkName $- case () of- ()- | null name' -> error "null-named file"- | isDigit (head name') -> '_' : name'- | isLower (head name') -> name'+ case name' of+ [] -> error "null-named file"+ n : _+ | isLower n -> name' | otherwise -> '_' : name' f' <- [|map pack $(TH.lift f)|] qs <- if makeHash
sample-embed.hs view
@@ -1,5 +1,8 @@-{-# LANGUAGE TemplateHaskell, QuasiQuotes, TypeFamilies #-}--- | This embeds just a single file; it embeds the source code file +{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeFamilies #-}++-- | This embeds just a single file; it embeds the source code file -- \"sample-embed.hs\" from the current directory so when you compile, -- the sample-embed.hs file must be in the current directory. --
sample.hs view
@@ -1,5 +1,8 @@-{-# LANGUAGE QuasiQuotes, TypeFamilies, MultiParamTypeClasses #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeFamilies #-}+ import Yesod.Static import Yesod.Core import Network.Wai.Handler.Warp (run)
test/EmbedDevelTest.hs view
@@ -1,4 +1,8 @@-{-# LANGUAGE TemplateHaskell, QuasiQuotes, TypeFamilies, OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeFamilies #-}+ module EmbedDevelTest where -- Tests the development mode of the embedded static subsite by
test/EmbedProductionTest.hs view
@@ -1,5 +1,9 @@-{-# LANGUAGE TemplateHaskell, QuasiQuotes, TypeFamilies, OverloadedStrings #-} {-# LANGUAGE LambdaCase #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeFamilies #-}+ module EmbedProductionTest where -- Tests the production mode of the embedded static subsite by
test/EmbedTestGenerator.hs view
@@ -1,4 +1,7 @@-{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+ module EmbedTestGenerator (testGen) where import Data.Default
test/FileGeneratorTests.hs view
@@ -1,4 +1,7 @@-{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+ module FileGeneratorTests (fileGenSpecs) where import Control.Exception@@ -11,7 +14,7 @@ -- | Embeds the LICENSE file license :: GenTestResult-license = $(embedFile "LICENSE" >>= +license = $(embedFile "LICENSE" >>= testOneEntry (Just "_LICENSE") "LICENSE" (BL.readFile "LICENSE") ) @@ -22,7 +25,7 @@ embDir :: [GenTestResult] embDir = $(embedDir "test/embed-dir" >>=- testEntries + testEntries [ (Just "abc_def_txt", "abc/def.txt", BL.readFile "test/embed-dir/abc/def.txt") , (Just "lorem_txt", "lorem.txt", BL.readFile "test/embed-dir/lorem.txt") , (Just "foo", "foo", BL.readFile "test/embed-dir/foo")@@ -31,7 +34,7 @@ embDirAt :: [GenTestResult] embDirAt = $(embedDirAt "xxx" "test/embed-dir" >>=- testEntries + testEntries [ (Just "xxx_abc_def_txt", "xxx/abc/def.txt", BL.readFile "test/embed-dir/abc/def.txt") , (Just "xxx_lorem_txt", "xxx/lorem.txt", BL.readFile "test/embed-dir/lorem.txt") , (Just "xxx_foo", "xxx/foo", BL.readFile "test/embed-dir/foo")@@ -50,7 +53,7 @@ [ "test/embed-dir/abc/def.txt", "test/embed-dir/foo"] >>= testOneEntry (Just "out2_txt") "out2.txt" (return "Yesod Rocks\nBar\nExtra") )- + fileGenSpecs :: Spec fileGenSpecs = do describe "Embed File" $ do@@ -82,7 +85,7 @@ BL.filter (/= 13) out `shouldBe` "Hello World\n" it "tryCompressTools" $ do- out <- flip tryCompressTools "abcdef" + out <- flip tryCompressTools "abcdef" [ const $ throwIO $ ErrorCall "An expected error" , const $ return "foo" , const $ return "bar"
test/GeneratorTestUtil.hs view
@@ -1,7 +1,9 @@-{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}+ module GeneratorTestUtil where -import Control.Applicative import Control.Monad (when) import Data.List (sortBy) import Language.Haskell.TH@@ -22,7 +24,7 @@ -- | Creates a GenTestResult at compile time by testing the entry. testEntry :: Maybe String -> Y.Location -> IO BL.ByteString -> Entry -> ExpQ-testEntry name _ _ e | ebHaskellName e /= (mkName Control.Applicative.<$> name) =+testEntry name _ _ e | ebHaskellName e /= (mkName <$> name) = [| GenError ("haskell name " ++ $(litE $ stringL $ show $ ebHaskellName e) ++ " /= " ++ $(litE $ stringL $ show name)) |]
yesod-static.cabal view
@@ -1,5 +1,5 @@ name: yesod-static-version: 1.6.1.0+version: 1.6.1.1 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -27,7 +27,7 @@ library default-language: Haskell2010- build-depends: base >= 4.10 && < 5+ build-depends: base >= 4.11 && < 5 , async , attoparsec >= 0.10 , base64-bytestring >= 0.1.0.1@@ -35,8 +35,8 @@ , bytestring >= 0.9.1.4 , conduit >= 1.3 , containers >= 0.2- , cryptonite >= 0.11- , cryptonite-conduit >= 0.1+ , crypton >= 1.0+ , crypton-conduit >= 0.2.3 , css-text >= 0.1.2 , data-default , directory >= 1.0@@ -86,7 +86,7 @@ Yesod.EmbeddedStatic.Types Yesod.Static YesodStaticTest- build-depends: base+ build-depends: base < 5 , hspec >= 1.3 , yesod-test >= 1.6 , wai-extra@@ -98,8 +98,8 @@ , bytestring , conduit , containers- , cryptonite- , cryptonite-conduit+ , crypton+ , crypton-conduit , data-default , directory , file-embed