separate yesod-shakespeare package

This commit is contained in:
Greg Weber 2015-06-07 19:44:20 -04:00
parent 11bf4d9c58
commit 10680f5108
42 changed files with 178 additions and 61 deletions

View File

@ -1,4 +1,5 @@
./yesod-core
./yesod-shakespeare
./yesod-static
./yesod-persistent
./yesod-newsfeed

View File

@ -13,5 +13,6 @@ packages:
- ./yesod
- ./yesod-eventsource
- ./yesod-websockets
- ./yesod-shakespeare
extra-deps:
- wai-app-static-3.1.0

View File

@ -24,6 +24,7 @@ import Web.Authenticate.OAuth
import Yesod.Auth
import Yesod.Form
import Yesod.Core
import Yesod.Shakespeare
data YesodOAuthException = CredentialError String Credential
| SessionError String

View File

@ -24,6 +24,7 @@ library
build-depends: authenticate-oauth >= 1.5 && < 1.6
, bytestring >= 0.9.1.4
, yesod-core >= 1.4 && < 1.5
, yesod-shakespeare >= 1.5 && < 1.6
, yesod-auth >= 1.4 && < 1.5
, text >= 0.7
, yesod-form >= 1.4 && < 1.5

View File

@ -63,6 +63,7 @@ import qualified Network.Wai as W
import Yesod.Core
import Yesod.Persist
import Yesod.Shakespeare
import Yesod.Auth.Message (AuthMessage, defaultMessage)
import qualified Yesod.Auth.Message as Msg
import Yesod.Form (FormMessage)
@ -146,7 +147,7 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage
authPlugins :: master -> [AuthPlugin master]
-- | What to show on the login page.
--
--
-- Default handler concatenates plugin widgets and wraps the result
-- in 'authLayout'. Override if you need fancy widget containers
-- or entirely custom page.

View File

@ -61,6 +61,7 @@ import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
import Data.Text.Encoding.Error (lenientDecode)
import Data.Text (Text)
import Yesod.Core
import Yesod.Shakespeare
import qualified Yesod.PasswordStore as PS
import qualified Text.Email.Validate
import qualified Yesod.Auth.Message as Msg

View File

@ -21,6 +21,7 @@ import Yesod.Auth
import qualified Web.Authenticate.OpenId as OpenId
import Yesod.Core
import Yesod.Shakespeare
import Data.Text (Text)
import qualified Yesod.Auth.Message as Msg
import qualified Data.Text as T

View File

@ -83,8 +83,9 @@ import Yesod.Core (HandlerSite, MonadHandler,
getYesod, invalidArgs, lift,
lookupGetParam,
lookupSession, notFound, redirect,
setSession, whamlet, (.:),
setSession, (.:),
TypedContent, HandlerT, liftIO)
import Yesod.Shakespeare (whamlet)
pid :: Text
pid = "googleemail2"

View File

@ -17,6 +17,7 @@ import qualified Web.Authenticate.OpenId as OpenId
import Yesod.Form
import Yesod.Core
import Yesod.Shakespeare
import Text.Cassius (cassius)
import Data.Text (Text, isPrefixOf)
import qualified Yesod.Auth.Message as Msg
@ -92,7 +93,7 @@ completeHelper idType gets' = do
eres <- try $ OpenId.authenticateClaimed gets' (authHttpManager master)
either onFailure onSuccess eres
where
onFailure err = do
onFailure err = do
tm <- getRouteToParent
lift $ loginErrorMessage (tm LoginR) $ T.pack $
show (err :: SomeException)

View File

@ -24,6 +24,7 @@ library
, authenticate >= 1.3
, bytestring >= 0.9.1.4
, yesod-core >= 1.4 && < 1.5
, yesod-shakespeare >= 1.5 && < 1.6
, wai >= 1.4
, template-haskell
, base16-bytestring

View File

@ -1,10 +1,8 @@
{-# LANGUAGE CPP #-}
module YesodCoreTest (specs) where
module YesodCoreTest (specs) where
import YesodCoreTest.CleanPath
import YesodCoreTest.Exceptions
import YesodCoreTest.Widget
import YesodCoreTest.Media
import YesodCoreTest.Links
import YesodCoreTest.NoOverloadedStrings
import YesodCoreTest.InternalRequest
@ -28,8 +26,6 @@ specs :: Spec
specs = do
cleanPathTest
exceptionsTest
widgetTest
mediaTest
linksTest
noOverloadedTest
internalRequestTest

View File

@ -5,7 +5,7 @@ module YesodCoreTest.ErrorHandling
( errorHandlingTest
) where
import Yesod.Core
import Yesod.Shakespeare (whamlet)
import Text.Hamlet (hamlet)
import Yesod.Core.Widget
import Test.Hspec
import Network.Wai
@ -81,7 +81,7 @@ postAfterRunRequestBodyR = do
getErrorInBodyR :: Handler Html
getErrorInBodyR = do
let foo = error "error in body 19328" :: String
defaultLayout [whamlet|#{foo}|]
defaultLayout $ toWidget [hamlet|#{foo}|]
getErrorInBodyNoEvalR :: Handler (DontFullyEvaluate Html)
getErrorInBodyNoEvalR = fmap DontFullyEvaluate getErrorInBodyR

View File

@ -8,7 +8,7 @@ import YesodCoreTest.NoOverloadedStringsSub
import Yesod.Core
import Yesod.Core.Widget
import Yesod.Shakespeare
import Text.Hamlet (hamlet)
import Network.Wai.Test
import Network.Wai (pathInfo)
import Data.Monoid (mempty)
@ -22,11 +22,11 @@ getBarR :: Monad m => m T.Text
getBarR = return $ T.pack "BarR"
getBazR :: Yesod master => HandlerT Subsite (HandlerT master IO) Html
getBazR = lift $ defaultLayout [whamlet|Used Default Layout|]
getBazR = lift $ defaultLayout $ toWidget [hamlet|Used Default Layout|]
getBinR :: Yesod master => HandlerT Subsite (HandlerT master IO) Html
getBinR = do
widget <- widgetToParentWidget [whamlet|
widget <- widgetToParentWidget $ toWidget [hamlet|
<p>Used defaultLayoutT
<a href=@{BazR}>Baz
|]

View File

@ -2,7 +2,7 @@
module YesodCoreTest.StubSslOnly ( App ( App ) ) where
import Yesod.Core
import Yesod.Shakespeare
import Text.Hamlet (hamlet)
import qualified Web.ClientSession as CS
data App = App
@ -17,8 +17,8 @@ instance Yesod App where
fmap Just $ defaultClientSessionBackend 120 CS.defaultKeyFile
getHomeR :: Handler Html
getHomeR = defaultLayout
[whamlet|
getHomeR = defaultLayout $ toWidget
[hamlet|
<p>
Welcome to my test application.
|]

View File

@ -2,7 +2,7 @@
module YesodCoreTest.StubUnsecured ( App ( App ) ) where
import Yesod.Core
import Yesod.Shakespeare
import Text.Hamlet (hamlet)
data App = App
@ -13,8 +13,8 @@ mkYesod "App" [parseRoutes|
instance Yesod App
getHomeR :: Handler Html
getHomeR = defaultLayout
[whamlet|
getHomeR = defaultLayout $ toWidget
[hamlet|
<p>
Welcome to my test application.
|]

View File

@ -16,7 +16,6 @@ extra-source-files:
test/YesodCoreTest.hs
test/YesodCoreTest/*.hs
test/YesodCoreTest/JsLoaderSites/Bottom.hs
test/en.msg
test/test.hs
ChangeLog.md
README.md
@ -68,7 +67,6 @@ library
, word8
, auto-update
, semigroups
, shakespeare
exposed-modules: Yesod.Core
Yesod.Core.Content
@ -80,7 +78,6 @@ library
Yesod.Core.Types
Yesod.Core.Unsafe
Yesod.Routes.TH.Types
Yesod.Shakespeare
other-modules: Yesod.Core.Internal.Session
Yesod.Core.Internal.Request
Yesod.Core.Class.Handler
@ -104,7 +101,7 @@ library
Yesod.Routes.TH.ParseRoute
Yesod.Routes.TH.RouteAttrs
ghc-options: -Wall -ddump-splices -ddump-to-file
ghc-options: -Wall
-- Following line added due to: https://github.com/yesodweb/yesod/issues/545
-- This looks like a GHC bug
extensions: MultiParamTypeClasses
@ -167,19 +164,6 @@ test-suite tests
ghc-options: -Wall -fno-warn-unused-binds
extensions: TemplateHaskell
benchmark widgets
type: exitcode-stdio-1.0
hs-source-dirs: bench
build-depends: base
, criterion
, bytestring
, text
, transformers
, yesod-core
, blaze-html
main-is: widget.hs
ghc-options: -Wall -O2
source-repository head
type: git
location: https://github.com/yesodweb/yesod

View File

@ -33,6 +33,7 @@ import Control.Monad (liftM)
import Data.Text (Text)
import Data.String (IsString(..))
import Yesod.Core
import Yesod.Shakespeare
import qualified Data.Text as T
@ -314,4 +315,4 @@ bootstrapSubmitId = "b:ootstrap___unique__:::::::::::::::::submit-id"
-- > <$> areq textField nameSettings Nothing
-- > where nameSettings = withAutofocus $
-- > withPlaceholder "First name" $
-- > (bfs ("Name" :: Text))
-- > (bfs ("Name" :: Text))

View File

@ -62,6 +62,7 @@ import Yesod.Form.Types
import Yesod.Form.I18n.English
import Yesod.Form.Functions (parseHelper)
import Yesod.Core
import Yesod.Shakespeare
import Text.Hamlet
import Text.Blaze (ToMarkup (toMarkup), unsafeByteString)
#define ToHtml ToMarkup
@ -91,7 +92,7 @@ import qualified Data.ByteString.Lazy as L
import Data.Text as T ( Text, append, concat, cons, head
, intercalate, isPrefixOf, null, unpack, pack, splitOn
)
import qualified Data.Text as T (drop, dropWhile)
import qualified Data.Text as T (drop, dropWhile)
import qualified Data.Text.Read
import qualified Data.Map as Map
@ -161,15 +162,15 @@ timeField = timeFieldTypeText
{-# DEPRECATED timeField "'timeField' currently defaults to an input of type=\"text\". In the next major release, it will default to type=\"time\". To opt in to the new functionality, use 'timeFieldTypeTime'. To keep the existing behavior, use 'timeFieldTypeText'. See 'https://github.com/yesodweb/yesod/pull/874' for details." #-}
-- | Creates an input with @type="time"@. <http://caniuse.com/#search=time%20input%20type Browsers not supporting this type> will fallback to a text field, and Yesod will parse the time as described in 'timeFieldTypeText'.
--
--
-- Add the @time@ package and import the "Data.Time.LocalTime" module to use this function.
--
-- Since 1.4.2
timeFieldTypeTime :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay
timeFieldTypeTime :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m TimeOfDay
timeFieldTypeTime = timeFieldOfType "time"
-- | Creates an input with @type="text"@, parsing the time from an [H]H:MM[:SS] format, with an optional AM or PM (if not given, AM is assumed for compatibility with the 24 hour clock system).
--
--
-- Add the @time@ package and import the "Data.Time.LocalTime" module to use this function.
--
-- Since 1.4.2
@ -205,7 +206,7 @@ $newline never
where showVal = either id (pack . renderHtml)
-- | A newtype wrapper around a 'Text' whose 'ToMarkup' instance converts newlines to HTML @\<br>@ tags.
--
--
-- (When text is entered into a @\<textarea>@, newline characters are used to separate lines.
-- If this text is then placed verbatim into HTML, the lines won't be separated, thus the need for replacing with @\<br>@ tags).
-- If you don't need this functionality, simply use 'unTextarea' to access the raw text.
@ -333,7 +334,7 @@ timeParser = do
if i < 0 || i >= 60
then fail $ show $ msg $ pack xy
else return $ fromIntegral (i :: Int)
-- | Creates an input with @type="email"@. Yesod will validate the email's correctness according to RFC5322 and canonicalize it by removing comments and whitespace (see "Text.Email.Validate").
emailField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Text
emailField = Field
@ -525,7 +526,7 @@ $newline never
--
-- If this field is optional, the first radio button is labeled "\<None>", the second \"Yes" and the third \"No".
--
-- If this field is required, the first radio button is labeled \"Yes" and the second \"No".
-- If this field is required, the first radio button is labeled \"Yes" and the second \"No".
--
-- (Exact label titles will depend on localization).
boolField :: Monad m => RenderMessage (HandlerSite m) FormMessage => Field m Bool
@ -559,7 +560,7 @@ $newline never
t -> Left $ SomeMessage $ MsgInvalidBool t
showVal = either (\_ -> False)
-- | Creates an input with @type="checkbox"@.
-- | Creates an input with @type="checkbox"@.
-- While the default @'boolField'@ implements a radio button so you
-- can differentiate between an empty response (@Nothing@) and a no
-- response (@Just False@), this simpler checkbox field returns an empty
@ -814,7 +815,7 @@ prependZero t0 = if T.null t1
-- $optionsOverview
-- These functions create inputs where one or more options can be selected from a list.
--
--
-- The basic datastructure used is an 'Option', which combines a user-facing display value, the internal Haskell value being selected, and an external 'Text' stored as the @value@ in the form (used to map back to the internal value). A list of these, together with a function mapping from an external value back to a Haskell value, form an 'OptionList', which several of these functions take as an argument.
--
--
-- Typically, you won't need to create an 'OptionList' directly and can instead make one with functions like 'optionsPairs' or 'optionsEnum'. Alternatively, you can use functions like 'selectFieldList', which use their @[(msg, a)]@ parameter to create an 'OptionList' themselves.

View File

@ -59,6 +59,7 @@ import Text.Blaze (Markup, toMarkup)
#define Html Markup
#define toHtml toMarkup
import Yesod.Core
import Yesod.Shakespeare
import Network.Wai (requestMethod)
import Text.Hamlet (shamlet)
import Data.Monoid (mempty)

View File

@ -17,6 +17,7 @@ import Yesod.Form.Types
import Data.Text (Text)
import Control.Applicative (Applicative (..))
import Yesod.Core
import Yesod.Shakespeare
import Control.Monad (liftM, (<=<))
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)

View File

@ -15,6 +15,7 @@ module Yesod.Form.Jquery
) where
import Yesod.Core
import Yesod.Shakespeare
import Yesod.Form
import Data.Time (Day)
import Data.Default

View File

@ -13,6 +13,7 @@ import Yesod.Form.Types
import Yesod.Form.Functions
import Yesod.Form.Fields (checkBoxField)
import Yesod.Core
import Yesod.Shakespeare
import Control.Monad.Trans.RWS (get, put, ask)
import Data.Maybe (fromMaybe)
import Data.Text.Read (decimal)

View File

@ -33,6 +33,7 @@ import Control.Monad (liftM)
import Control.Monad.Trans.Class
import Data.String (IsString (..))
import Yesod.Core
import Yesod.Shakespeare
import qualified Data.Map as Map
import Data.Semigroup (Semigroup, (<>))

View File

@ -22,6 +22,7 @@ library
build-depends: base >= 4 && < 5
, yesod-core >= 1.4 && < 1.5
, yesod-persistent >= 1.4 && < 1.5
, yesod-shakespeare >= 1.5 && < 1.6
, time >= 1.1.4
, shakespeare >= 2.0
, persistent

View File

@ -0,0 +1,3 @@
## 1.5
* split off from yesod-core

20
yesod-shakespeare/LICENSE Normal file
View File

@ -0,0 +1,20 @@
Copyright (c) 2012 Michael Snoyman, http://www.yesodweb.com/
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.

View File

@ -0,0 +1,6 @@
## yesod-shakespeare
This package adds shakespeare integration on top of yesod-core.
The yesod package automatically adds in shakespeare functionality.
Yesod is well documented on [its website](http://www.yesodweb.com/).

View File

@ -69,12 +69,13 @@ import Text.Hamlet (hamlet, shamlet, xhamlet)
import Text.Lucius (Css, renderCss, CssUrl, renderCssUrl, lucius)
import Text.Cassius (cassius)
import Yesod.Core ( HandlerSite, MonadHandler
, getUrlRenderParams, toTextUrl, invalidArgs, permissionDenied, RedirectUrl, withUrlRenderer, getRequest, getYesod, sendResponse
, ToContent(..), ToTypedContent(..), HasContentType(..), typeJavascript, typeCss
, Route
, ToWidget(..), ToWidgetBody(..), ToWidgetMedia(..), ToWidgetHead(..), MonadWidget(..), asWidgetT, tellWidget, GWData(..), setMessage, setTitle
)
import Yesod.Core.Types
import Yesod.Core.Widget
import Yesod.Core.Class.Handler (HandlerSite, MonadHandler)
import Yesod.Core.Handler (getUrlRenderParams, toTextUrl, invalidArgs, permissionDenied, RedirectUrl, withUrlRenderer, getRequest, getYesod, sendResponse)
import Yesod.Core.Content (ToContent(..), ToTypedContent(..), HasContentType(..), typeJavascript, typeCss)
import Yesod.Routes.Class (Route)
-- for hamlet expansion
import qualified Data.Foldable

View File

@ -5,7 +5,7 @@
module Main where
import Criterion.Main
import Text.Hamlet
import Yesod.Shakespeare
import Numeric (showInt)
import qualified Data.ByteString.Lazy as L
import qualified Text.Blaze.Html.Renderer.Utf8 as Utf8

View File

@ -2,15 +2,15 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances, ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module YesodCoreTest.Media (mediaTest, Widget) where
module YesodShakespeareTest.Media (mediaTest, Widget) where
import Test.Hspec
import Yesod.Core
import Yesod.Core.Widget
import Yesod.Shakespeare
import Network.Wai
import Network.Wai.Test
import Text.Lucius
import YesodCoreTest.MediaData
import YesodShakespeareTest.MediaData
mkYesodDispatch "Y" resourcesY

View File

@ -1,7 +1,7 @@
{-# LANGUAGE QuasiQuotes, TypeFamilies, TemplateHaskell, MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
module YesodCoreTest.MediaData where
module YesodShakespeareTest.MediaData where
import Yesod.Core

View File

@ -1,16 +1,13 @@
{-# LANGUAGE QuasiQuotes, TypeFamilies, TemplateHaskell, MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances, ViewPatterns #-}
module YesodCoreTest.Widget (widgetTest) where
module YesodShakespeareTest.Widget (widgetTest) where
import Test.Hspec
import Yesod.Core
import Yesod.Core.Widget
import Yesod.Shakespeare
import Text.Julius
import Text.Lucius
import Text.Hamlet
import Network.Wai
import Network.Wai.Test

View File

@ -0,0 +1,11 @@
import Test.Hspec
import YesodShakespeareTest.Widget
import YesodShakespeareTest.Media
main :: IO ()
main = hspec specs
specs :: Spec
specs = do
widgetTest
mediaTest

View File

@ -0,0 +1,73 @@
name: yesod-shakespeare
version: 1.5
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
maintainer: Michael Snoyman <michael@snoyman.com>
synopsis: Creation of type-safe, RESTful web applications.
description: API docs and the README are available at <http://www.stackage.org/package/yesod-core>
category: Web, Yesod
stability: Stable
cabal-version: >= 1.8
build-type: Simple
homepage: http://www.yesodweb.com/
extra-source-files:
test/YesodShakespeareTest/*.hs
test/en.msg
test/test.hs
ChangeLog.md
README.md
library
build-depends: base >= 4.3 && < 5
, shakespeare
, yesod-core >= 1.4
, text >= 0.7
, template-haskell
, bytestring >= 0.9.1.4
, transformers >= 0.2.2
, blaze-html >= 0.5
, containers >= 0.2
exposed-modules: Yesod.Shakespeare
ghc-options: -Wall -ddump-splices -ddump-to-file
-- Following line added due to: https://github.com/yesodweb/yesod/issues/545
-- This looks like a GHC bug
extensions: MultiParamTypeClasses
-- Workaround for: http://ghc.haskell.org/trac/ghc/ticket/8443
extensions: TemplateHaskell
test-suite tests
type: exitcode-stdio-1.0
main-is: test.hs
hs-source-dirs: test
cpp-options: -DTEST
build-depends: base
,hspec >= 1.3
,hspec-expectations
,yesod-core
,yesod-shakespeare
,wai
,wai-extra
ghc-options: -Wall -fno-warn-unused-binds
extensions: TemplateHaskell
benchmark widgets
type: exitcode-stdio-1.0
hs-source-dirs: bench
build-depends: base
, yesod-shakespeare
, yesod-core
, transformers
, blaze-html
, bytestring
, criterion
main-is: widget.hs
ghc-options: -Wall -O2
source-repository head
type: git
location: https://github.com/yesodweb/yesod

View File

@ -11,6 +11,7 @@ import Network.Wai.Test (SResponse(simpleHeaders))
import Test.HUnit (assertFailure, assertBool)
import Test.Hspec (Spec)
import Yesod.Core
import Yesod.Shakespeare
import Yesod.EmbeddedStatic
import Yesod.Test
import qualified Data.ByteString as B

View File

@ -80,6 +80,7 @@ test-suite tests
build-depends: base
, hspec >= 1.3
, yesod-test >= 1.4
, yesod-shakespeare >= 1.5
, wai-extra
, HUnit

View File

@ -7,6 +7,7 @@ import Test.Hspec
import Yesod.Core
import Yesod.Form
import Yesod.Shakespeare
import Yesod.Test
import Yesod.Test.CssQuery
import Yesod.Test.TransversingCSS

View File

@ -57,6 +57,7 @@ test-suite test
, containers
, html-conduit
, yesod-core
, yesod-shakespeare
, yesod-form
, text
, wai

View File

@ -4,10 +4,12 @@
module Yesod
( -- * Re-exports from yesod-core
module Yesod.Core
, module Yesod.Shakespeare
, module Yesod.Form
, module Yesod.Persist
) where
import Yesod.Core
import Yesod.Shakespeare
import Yesod.Form
import Yesod.Persist

View File

@ -17,6 +17,7 @@ module Yesod.Default.Util
import qualified Data.ByteString.Lazy as L
import Data.Text (Text, pack, unpack)
import Yesod.Core -- purposely using complete import so that Haddock will see addStaticContent
import Yesod.Shakespeare
import Control.Monad (when, unless)
import System.Directory (doesFileExist, createDirectoryIfMissing)
import Language.Haskell.TH.Syntax

View File

@ -19,6 +19,7 @@ library
build-depends: base >= 4.3 && < 5
, yesod-core >= 1.4 && < 1.5
, yesod-shakespeare >= 1.5 && < 1.6
, yesod-auth >= 1.4 && < 1.5
, yesod-persistent >= 1.4 && < 1.5
, yesod-form >= 1.4 && < 1.5