yesod 1.4.5 → 1.6.2.3
raw patch · 9 files changed
Files
- ChangeLog.md +42/−0
- README.md +35/−0
- Yesod.hs +0/−2
- Yesod/Default/Config.hs +35/−18
- Yesod/Default/Config2.hs +7/−2
- Yesod/Default/Handlers.hs +1/−0
- Yesod/Default/Main.hs +7/−7
- Yesod/Default/Util.hs +21/−8
- yesod.cabal +18/−23
ChangeLog.md view
@@ -1,3 +1,45 @@+# ChangeLog for yesod++## 1.6.2.3++* Support `yesod-core` 1.7++## 1.6.2.2++* Set `base >= 4.11` for less CPP and imports [#1876](https://github.com/yesodweb/yesod/pull/1876)++## 1.6.2.1++* Support `template-haskell-2.19.0.0` [#1769](https://github.com/yesodweb/yesod/pull/1769)++## 1.6.2++* aeson 2++## 1.6.1.2++* Fix compatibility with template-haskell 2.17 [#1730](https://github.com/yesodweb/yesod/pull/1730)++## 1.6.1.1++* Allow yesod-form 1.7++## 1.6.1.0++* `widgetFileReload` and `widgetFileNoReload` now use absolute paths via the new `globFilePackage` Q Exp which can provide absolute templates paths within the project [#1691](https://github.com/yesodweb/yesod/pull/1691)++## 1.6.0.2++* Replace deprecated decodeFile with decodeFileEither. This should have no semantic impact, but silences a deprecation warning. [#1658](https://github.com/yesodweb/yesod/pull/1658)++## 1.6.0.1++* Remove unnecessary deriving of Typeable++## 1.6.0++* Upgrade to yesod-core 1.6+ ## 1.4.5 * Fix warnings
README.md view
@@ -8,3 +8,38 @@ For the yesod executable, see [yesod-bin](http://www.stackage.org/package/yesod-bin/). Yesod is [fully documented on its website](http://www.yesodweb.com/).++## Getting Started++Learn more about Yesod on [its main website](http://www.yesodweb.com/). If you+want to get started using Yesod, we strongly recommend the [quick start+guide](http://www.yesodweb.com/page/quickstart), based on [the Haskell build+tool stack](https://github.com/commercialhaskell/stack#readme).++Here's a minimal example!++```haskell+{-# LANGUAGE OverloadedStrings, QuasiQuotes, TemplateHaskell, TypeFamilies #-}++import Yesod++data App = App -- Put your config, database connection pool, etc. in here.++-- Derive routes and instances for App.+mkYesod "App" [parseRoutes|+/ HomeR GET+|]++instance Yesod App -- Methods in here can be overridden as needed.++-- The handler for the GET request at /, corresponds to HomeR.+getHomeR :: Handler Html+getHomeR = defaultLayout [whamlet|Hello World!|]++main :: IO ()+main = warp 3000 App+```++To read about each of the concepts in use above (routing, handlers,+linking, JSON), in detail, visit+[Basics in the Yesod book](https://www.yesodweb.com/book/basics#basics_routing).
Yesod.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE CPP #-} -- | This module simply re-exports from other modules for your convenience. module Yesod ( -- * Re-exports from yesod-core
Yesod/Default/Config.hs view
@@ -1,6 +1,8 @@-{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-}+{-# LANGUAGE ScopedTypeVariables #-}+ module Yesod.Default.Config ( DefaultEnv (..) , fromArgs@@ -18,14 +20,27 @@ import Data.Char (toUpper) import Data.Text (Text) import qualified Data.Text as T-import Data.Yaml+import Data.Yaml (+ Object,+ Parser,+ Value (..),+ decodeFileEither,+ parseEither,+ prettyPrintParseException,+ (.:)+ ) import Data.Maybe (fromMaybe)-import qualified Data.HashMap.Strict as M import System.Environment (getArgs, getProgName, getEnvironment) import System.Exit (exitFailure) import Data.Streaming.Network (HostPreference) import Data.String (fromString) +#if MIN_VERSION_aeson(2, 0, 0)+import qualified Data.Aeson.KeyMap as M+#else+import qualified Data.HashMap.Strict as M+#endif+ -- | A yesod-provided @'AppEnv'@, allows for Development, Testing, and -- Production environments data DefaultEnv = Development@@ -39,9 +54,9 @@ , port :: Int } deriving Show -parseArgConfig :: (Show env, Read env, Enum env, Bounded env) => IO (ArgConfig env)+parseArgConfig :: forall env. (Show env, Read env, Enum env, Bounded env) => IO (ArgConfig env) parseArgConfig = do- let envs = [minBound..maxBound]+ let envs = [minBound..maxBound] :: [env] args <- getArgs (portS, args') <- getPort id args portI <-@@ -52,10 +67,7 @@ [e] -> do case reads $ capitalize e of (e', _):_ -> return $ ArgConfig e' portI- [] -> do- () <- error $ "Invalid environment, valid entries are: " ++ show envs- -- next line just provided to force the type of envs- return $ ArgConfig (head envs) 0+ [] -> error $ "Invalid environment, valid entries are: " ++ show envs _ -> do pn <- getProgName putStrLn $ "Usage: " ++ pn ++ " <environment> [--port <port>]"@@ -144,7 +156,7 @@ Object obj -> return obj _ -> fail "Expected Object" let senv = show env- tenv = T.pack senv+ tenv = fromString senv maybe (error $ "Could not find environment: " ++ senv) return@@ -180,8 +192,8 @@ -> IO (AppConfig environment extra) loadConfig (ConfigSettings env parseExtra getFile getObject) = do fp <- getFile env- mtopObj <- decodeFile fp- topObj <- maybe (fail "Invalid YAML file") return mtopObj+ etopObj <- decodeFileEither fp+ topObj <- either (const $ fail "Invalid YAML file") return etopObj obj <- getObject env topObj m <- case obj of@@ -189,7 +201,7 @@ _ -> fail "Expected map" let host = fromString $ T.unpack $ fromMaybe "*" $ lookupScalar "host" m- mport <- parseMonad (\x -> x .: "port") m+ mport <- parseEitherM (\x -> x .: "port") m let approot' = fromMaybe "" $ lookupScalar "approot" m -- Handle the DISPLAY_PORT environment variable for yesod devel@@ -202,7 +214,7 @@ Nothing -> return approot' Just p -> return $ prefix `T.append` T.pack (':' : p) - extra <- parseMonad (parseExtra env) m+ extra <- parseEitherM (parseExtra env) m -- set some default arguments let port' = fromMaybe 80 mport@@ -233,9 +245,14 @@ -> (Value -> Parser a) -- ^ what to do with the mapping -> IO a withYamlEnvironment fp env f = do- mval <- decodeFile fp+ mval <- decodeFileEither fp case mval of- Nothing -> fail $ "Invalid YAML file: " ++ show fp- Just (Object obj)- | Just v <- M.lookup (T.pack $ show env) obj -> parseMonad f v+ Left err ->+ fail $ "Invalid YAML file: " ++ show fp ++ " " ++ prettyPrintParseException err+ Right (Object obj)+ | Just v <- M.lookup (fromString $ show env) obj -> parseEitherM f v _ -> fail $ "Could not find environment: " ++ show env++-- | Replacement for `parseMonad`+parseEitherM :: (a -> Parser b) -> a -> IO b+parseEitherM p = either fail pure . parseEither p
Yesod/Default/Config2.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-}+ -- | Some next-gen helper functions for the scaffolding's configuration system. module Yesod.Default.Config2 ( -- * Locally defined@@ -28,9 +29,7 @@ import Data.Yaml.Config -import Data.Semigroup import Data.Aeson-import qualified Data.HashMap.Strict as H import System.Environment (getEnvironment) import Network.Wai (Application) import Network.Wai.Handler.Warp@@ -42,6 +41,12 @@ import Network.Wai.Logger (clockDateCacher) import Yesod.Core.Types (Logger (Logger)) import System.Log.FastLogger (LoggerSet)++#if MIN_VERSION_aeson(2, 0, 0)+import qualified Data.Aeson.KeyMap as H+#else+import qualified Data.HashMap.Strict as H+#endif #ifndef mingw32_HOST_OS import System.Posix.Signals (installHandler, sigINT, Handler(Catch))
Yesod/Default/Handlers.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+ module Yesod.Default.Handlers ( getFaviconR , getRobotsR
Yesod/Default/Main.hs view
@@ -1,7 +1,7 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE CPP #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-}+ module Yesod.Default.Main ( defaultMain , defaultMainLog@@ -47,7 +47,7 @@ defaultMain load getApp = do config <- load app <- getApp config- runSettings + runSettings ( setPort (appPort config) $ setHost (appHost config) $ defaultSettings@@ -65,7 +65,7 @@ defaultMainLog load getApp = do config <- load (app, logFunc) <- getApp config- runSettings + runSettings ( setPort (appPort config) $ setHost (appHost config) $ setOnException (const $ \e -> when (shouldLog' e) $ logFunc@@ -78,7 +78,7 @@ where shouldLog' = Warp.defaultShouldDisplayException --- | Run your application continously, listening for SIGINT and exiting+-- | Run your application continuously, listening for SIGINT and exiting -- when received -- -- > withYourSite :: AppConfig DefaultEnv -> Logger -> (Application -> IO a) -> IO ()
Yesod/Default/Util.hs view
@@ -1,10 +1,12 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-}-{-# LANGUAGE CPP #-}+ -- | Various utilities used in the scaffolded site. module Yesod.Default.Util ( addStaticContentExternal , globFile+ , globFilePackage , widgetFileNoReload , widgetFileReload , TemplateLanguage (..)@@ -15,14 +17,16 @@ ) where import qualified Data.ByteString.Lazy as L+import Data.FileEmbed (makeRelativeToProject) import Data.Text (Text, pack, unpack) import Yesod.Core -- purposely using complete import so that Haddock will see addStaticContent import Control.Monad (when, unless)-import Control.Monad.Trans.Resource (runResourceT)-import Data.Conduit (($$))-import Data.Conduit.Binary (sourceLbs, sinkFileCautious)+import Conduit import System.Directory (doesFileExist, createDirectoryIfMissing) import Language.Haskell.TH.Syntax+#if MIN_VERSION_template_haskell(2,19,0)+ hiding (makeRelativeToProject)+#endif import Text.Lucius (luciusFile, luciusFileReload) import Text.Julius (juliusFile, juliusFileReload) import Text.Cassius (cassiusFile, cassiusFileReload)@@ -42,12 +46,12 @@ -> Text -- ^ filename extension -> Text -- ^ mime type -> L.ByteString -- ^ file contents- -> HandlerT master IO (Maybe (Either Text (Route master, [(Text, Text)])))+ -> HandlerFor master (Maybe (Either Text (Route master, [(Text, Text)]))) addStaticContentExternal minify hash staticDir toRoute ext' _ content = do liftIO $ createDirectoryIfMissing True statictmp exists <- liftIO $ doesFileExist fn'- unless exists $- liftIO $ runResourceT $ sourceLbs content' $$ sinkFileCautious fn'+ unless exists $ withSinkFileCautious fn' $ \sink ->+ runConduit $ sourceLazy content' .| sink return $ Just $ Right (toRoute ["tmp", pack fn], []) where fn, statictmp, fn' :: FilePath@@ -66,6 +70,11 @@ globFile :: String -> String -> FilePath globFile kind x = "templates/" ++ x ++ "." ++ kind +-- | `globFile` but returned path is absolute and within the package the Q Exp is evaluated+-- @since 1.6.1.0+globFilePackage :: String -> String -> Q FilePath+globFilePackage = (makeRelativeToProject <$>) . globFile+ data TemplateLanguage = TemplateLanguage { tlRequiresToWidget :: Bool , tlExtension :: String@@ -108,7 +117,11 @@ , show file , ", but no templates were found." ]+#if MIN_VERSION_template_haskell(2,17,0)+ exps -> return $ DoE Nothing $ map NoBindS exps+#else exps -> return $ DoE $ map NoBindS exps+#endif where qmexps :: Q [Maybe Exp] qmexps = mapM go tls@@ -126,7 +139,7 @@ -> Bool -- ^ requires toWidget wrap -> String -> (FilePath -> Q Exp) -> Q (Maybe Exp) warnUnlessExists shouldWarn x wrap glob f = do- let fn = globFile glob x+ fn <- globFilePackage glob x e <- qRunIO $ doesFileExist fn when (shouldWarn && not e) $ qRunIO $ putStrLn $ "widget file not found: " ++ fn if e
yesod.cabal view
@@ -1,5 +1,5 @@ name: yesod-version: 1.4.5+version: 1.6.2.3 license: MIT license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -8,43 +8,38 @@ description: API docs and the README are available at <http://www.stackage.org/package/yesod> category: Web, Yesod stability: Stable-cabal-version: >= 1.6+cabal-version: >= 1.10 build-type: Simple homepage: http://www.yesodweb.com/ extra-source-files: README.md ChangeLog.md library+ default-language: Haskell2010 if os(windows) cpp-options: -DWINDOWS - build-depends: base >= 4.6 && < 5- , yesod-core >= 1.4 && < 1.5- , yesod-persistent >= 1.4 && < 1.5- , yesod-form >= 1.4 && < 1.5- , monad-control >= 0.3 && < 1.1- , transformers >= 0.2.2- , wai >= 1.3- , wai-extra >= 1.3- , warp >= 1.3- , blaze-html >= 0.5- , blaze-markup >= 0.5.1+ build-depends: base >= 4.11 && < 5 , aeson+ , bytestring+ , conduit >= 1.3 , data-default-class- , unordered-containers- , yaml >= 0.8.17- , text , directory- , template-haskell- , bytestring- , monad-logger , fast-logger- , conduit- , conduit-extra >= 1.1.14- , resourcet+ , file-embed >= 0.0.10+ , monad-logger , shakespeare , streaming-commons+ , template-haskell+ , text+ , unordered-containers+ , wai >= 1.3+ , wai-extra >= 1.3 , wai-logger- , semigroups+ , warp >= 1.3+ , yaml >= 0.8.17+ , yesod-core >= 1.6 && < 1.8+ , yesod-form >= 1.6 && < 1.8+ , yesod-persistent >= 1.6 && < 1.7 exposed-modules: Yesod , Yesod.Default.Config