Merge remote-tracking branch 'origin/master' into static-pages

This commit is contained in:
Greg Weber 2012-02-09 20:49:51 -08:00
commit 4a2bff1c78
29 changed files with 93 additions and 56 deletions

View File

@ -1,5 +1,5 @@
name: yesod-auth name: yesod-auth
version: 0.8.0 version: 0.8.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman, Patrick Brisbin author: Michael Snoyman, Patrick Brisbin
@ -23,7 +23,7 @@ library
build-depends: base >= 4 && < 4.3 build-depends: base >= 4 && < 4.3
build-depends: authenticate >= 1.0 && < 1.1 build-depends: authenticate >= 1.0 && < 1.1
, bytestring >= 0.9.1.4 && < 0.10 , bytestring >= 0.9.1.4 && < 0.10
, yesod-core >= 0.10 && < 0.11 , yesod-core >= 0.10.1 && < 0.11
, wai >= 1.1 && < 1.2 , wai >= 1.1 && < 1.2
, template-haskell , template-haskell
, pureMD5 >= 2.0 && < 2.2 , pureMD5 >= 2.0 && < 2.2
@ -31,13 +31,13 @@ library
, text >= 0.7 && < 0.12 , text >= 0.7 && < 0.12
, mime-mail >= 0.3 && < 0.5 , mime-mail >= 0.3 && < 0.5
, blaze-html >= 0.4.1.3 && < 0.5 , blaze-html >= 0.4.1.3 && < 0.5
, yesod-persistent >= 0.3 && < 0.4 , yesod-persistent >= 0.3.1 && < 0.4
, hamlet >= 0.10 && < 0.11 , hamlet >= 0.10 && < 0.11
, shakespeare-css >= 0.10 && < 0.11 , shakespeare-css >= 0.10 && < 0.11
, yesod-json >= 0.3 && < 0.4 , yesod-json >= 0.3.1 && < 0.4
, containers , containers
, unordered-containers , unordered-containers
, yesod-form >= 0.4 && < 0.5 , yesod-form >= 0.4.1 && < 0.5
, transformers >= 0.2.2 && < 0.3 , transformers >= 0.2.2 && < 0.3
, persistent >= 0.8 && < 0.9 , persistent >= 0.8 && < 0.9
, persistent-template >= 0.8 && < 0.9 , persistent-template >= 0.8 && < 0.9

View File

@ -8,6 +8,8 @@ module Yesod.Core
-- ** Breadcrumbs -- ** Breadcrumbs
, YesodBreadcrumbs (..) , YesodBreadcrumbs (..)
, breadcrumbs , breadcrumbs
-- * Types
, Approot (..)
-- * Utitlities -- * Utitlities
, maybeAuthorized , maybeAuthorized
, widgetToPageContent , widgetToPageContent

View File

@ -182,7 +182,7 @@ sendRedirect y segments' env =
, ("Location", Blaze.ByteString.Builder.toByteString dest') , ("Location", Blaze.ByteString.Builder.toByteString dest')
] "Redirecting" ] "Redirecting"
where where
dest = joinPath y (approot y) segments' [] dest = joinPath y (resolveApproot y env) segments' []
dest' = dest' =
if S.null (W.rawQueryString env) if S.null (W.rawQueryString env)
then dest then dest

View File

@ -28,6 +28,8 @@ module Yesod.Internal.Core
-- * Misc -- * Misc
, yesodVersion , yesodVersion
, yesodRender , yesodRender
, resolveApproot
, Approot (..)
) where ) where
import Yesod.Content import Yesod.Content
@ -121,20 +123,36 @@ class YesodDispatch sub master where
-> W.Application -> W.Application
yesodRunner = defaultYesodRunner yesodRunner = defaultYesodRunner
-- | Define settings for a Yesod applications. The only required setting is -- | How to determine the root of the application for constructing URLs.
-- 'approot'; other than that, there are intelligent defaults. --
-- Note that future versions of Yesod may add new constructors without bumping
-- the major version number. As a result, you should /not/ pattern match on
-- @Approot@ values.
data Approot master = ApprootRelative -- ^ No application root.
| ApprootStatic Text
| ApprootMaster (master -> Text)
| ApprootRequest (master -> W.Request -> Text)
type ResolvedApproot = Text
-- | Define settings for a Yesod applications. All methods have intelligent
-- defaults, and therefore no implementation is required.
class RenderRoute a => Yesod a where class RenderRoute a => Yesod a where
-- | An absolute URL to the root of the application. Do not include -- | An absolute URL to the root of the application. Do not include
-- trailing slash. -- trailing slash.
-- --
-- If you want to be lazy, you can supply an empty string under the -- Default value: 'ApprootRelative'. This is valid under the following
-- following conditions: -- conditions:
-- --
-- * Your application is served from the root of the domain. -- * Your application is served from the root of the domain.
-- --
-- * You do not use any features that require absolute URLs, such as Atom -- * You do not use any features that require absolute URLs, such as Atom
-- feeds and XML sitemaps. -- feeds and XML sitemaps.
approot :: a -> Text --
-- If this is not true, you should override with a different
-- implementation.
approot :: Approot a
approot = ApprootRelative
-- | The encryption key to be used for encrypting client sessions. -- | The encryption key to be used for encrypting client sessions.
-- Returning 'Nothing' disables sessions. -- Returning 'Nothing' disables sessions.
@ -395,7 +413,8 @@ defaultYesodRunner handler master sub murl toMasterRoute mkey req = do
handler handler
let sessionMap = Map.fromList let sessionMap = Map.fromList
$ filter (\(x, _) -> x /= nonceKey) session' $ filter (\(x, _) -> x /= nonceKey) session'
yar <- handlerToYAR master sub toMasterRoute (yesodRender master) errorHandler rr murl sessionMap h let ra = resolveApproot master req
yar <- handlerToYAR master sub toMasterRoute (yesodRender master ra) errorHandler rr murl sessionMap h
let mnonce = reqNonce rr let mnonce = reqNonce rr
-- FIXME should we be caching this IV value and reusing it for efficiency? -- FIXME should we be caching this IV value and reusing it for efficiency?
iv <- {-# SCC "iv" #-} maybe (return $ error "Should not be used") (const $ liftIO CS.randomIV) mkey iv <- {-# SCC "iv" #-} maybe (return $ error "Should not be used") (const $ liftIO CS.randomIV) mkey
@ -633,14 +652,23 @@ ynHelper render scripts jscript jsLoc =
yesodRender :: Yesod y yesodRender :: Yesod y
=> y => y
-> ResolvedApproot
-> Route y -> Route y
-> [(Text, Text)] -- ^ url query string -> [(Text, Text)] -- ^ url query string
-> Text -> Text
yesodRender y url params = yesodRender y ar url params =
TE.decodeUtf8 $ toByteString $ TE.decodeUtf8 $ toByteString $
fromMaybe fromMaybe
(joinPath y (approot y) ps (joinPath y ar ps
$ params ++ params') $ params ++ params')
(urlRenderOverride y url) (urlRenderOverride y url)
where where
(ps, params') = renderRoute url (ps, params') = renderRoute url
resolveApproot :: Yesod master => master -> W.Request -> ResolvedApproot
resolveApproot master req =
case approot of
ApprootRelative -> ""
ApprootStatic t -> t
ApprootMaster f -> f master
ApprootRequest f -> f master req

View File

@ -21,7 +21,7 @@ key2 = $(mkCacheKey)
mkYesod "C" [parseRoutes|/ RootR GET|] mkYesod "C" [parseRoutes|/ RootR GET|]
instance Yesod C where approot _ = "" instance Yesod C
getRootR :: Handler () getRootR :: Handler ()
getRootR = do getRootR = do

View File

@ -41,7 +41,7 @@ mkYesod "Y" [parseRoutes|
|] |]
instance Yesod Y where instance Yesod Y where
approot _ = "http://test" approot = ApprootStatic "http://test"
cleanPath _ s@("subsite":_) = Right s cleanPath _ s@("subsite":_) = Right s
cleanPath _ ["bar", ""] = Right ["bar"] cleanPath _ ["bar", ""] = Right ["bar"]
cleanPath _ ["bar"] = Left ["bar", ""] cleanPath _ ["bar"] = Left ["bar", ""]

View File

@ -21,7 +21,7 @@ mkYesod "App" [parseRoutes|
/after_runRequestBody AfterRunRequestBodyR POST /after_runRequestBody AfterRunRequestBodyR POST
|] |]
instance Yesod App where approot _ = "" instance Yesod App
getHomeR :: Handler RepHtml getHomeR :: Handler RepHtml
getHomeR = defaultLayout $ toWidget [hamlet| getHomeR = defaultLayout $ toWidget [hamlet|

View File

@ -18,7 +18,7 @@ mkYesod "Y" [parseRoutes|
|] |]
instance Yesod Y where instance Yesod Y where
approot _ = "http://test" approot = ApprootStatic "http://test"
errorHandler (InternalError e) = return $ chooseRep $ RepPlain $ toContent e errorHandler (InternalError e) = return $ chooseRep $ RepPlain $ toContent e
errorHandler x = defaultErrorHandler x errorHandler x = defaultErrorHandler x

View File

@ -15,8 +15,7 @@ mkYesod "Y" [parseRoutes|
/ RootR GET / RootR GET
|] |]
instance Yesod Y where instance Yesod Y
approot _ = ""
getRootR :: Handler RepHtml getRootR :: Handler RepHtml
getRootR = defaultLayout $ addHamlet [hamlet|<a href=@{RootR}>|] getRootR = defaultLayout $ addHamlet [hamlet|<a href=@{RootR}>|]

View File

@ -15,7 +15,6 @@ import YesodCoreTest.MediaData
mkYesodDispatch "Y" resourcesY mkYesodDispatch "Y" resourcesY
instance Yesod Y where instance Yesod Y where
approot _ = ""
addStaticContent _ _ content = do addStaticContent _ _ content = do
tm <- getRouteToMaster tm <- getRouteToMaster
route <- getCurrentRoute route <- getCurrentRoute

View File

@ -8,7 +8,6 @@ import Test.Hspec.HUnit ()
import Yesod.Core hiding (Request) import Yesod.Core hiding (Request)
import Network.Wai.Test import Network.Wai.Test
import Data.Monoid (mempty) import Data.Monoid (mempty)
import Data.String (fromString)
data Subsite = Subsite data Subsite = Subsite
@ -29,8 +28,7 @@ mkYesod "Y" [parseRoutes|
/subsite SubsiteR Subsite getSubsite /subsite SubsiteR Subsite getSubsite
|] |]
instance Yesod Y where instance Yesod Y
approot _ = fromString ""
getRootR :: Handler () getRootR :: Handler ()
getRootR = return () getRootR = return ()

View File

@ -13,7 +13,7 @@ mkYesod "Y" [parseRoutes|
/r307 R307 GET /r307 R307 GET
/rregular RRegular GET /rregular RRegular GET
|] |]
instance Yesod Y where approot _ = "http://test" instance Yesod Y where approot = ApprootStatic "http://test"
app :: Session () -> IO () app :: Session () -> IO ()
app = yesod Y app = yesod Y

View File

@ -28,7 +28,7 @@ mkYesod "Y" [parseRoutes|
|] |]
instance Yesod Y where instance Yesod Y where
approot _ = "http://test" approot = ApprootStatic "http://test"
getRootR :: Handler RepHtml getRootR :: Handler RepHtml
getRootR = defaultLayout $ toWidgetBody [julius|<not escaped>|] getRootR = defaultLayout $ toWidgetBody [julius|<not escaped>|]

View File

@ -3,6 +3,7 @@ module YesodCoreTest.YesodTest
( yesod ( yesod
, parseRoutes, mkYesod, yesodDispatch, renderRoute, Yesod(..) , parseRoutes, mkYesod, yesodDispatch, renderRoute, Yesod(..)
, redirect , redirect
, Approot (..)
, module Network.Wai , module Network.Wai
, module Network.Wai.Test , module Network.Wai.Test
, module Test.Hspec , module Test.Hspec

View File

@ -1,5 +1,5 @@
name: yesod-core name: yesod-core
version: 0.10.0 version: 0.10.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>
@ -47,7 +47,7 @@ library
build-depends: wai-test build-depends: wai-test
build-depends: time >= 1.1.4 build-depends: time >= 1.1.4
, yesod-routes >= 0.0 && < 0.1 , yesod-routes >= 0.0.1 && < 0.1
, wai >= 1.1 && < 1.2 , wai >= 1.1 && < 1.2
, wai-extra >= 1.1 && < 1.2 , wai-extra >= 1.1 && < 1.2
, bytestring >= 0.9.1.4 && < 0.10 , bytestring >= 0.9.1.4 && < 0.10

View File

@ -1,5 +1,5 @@
name: yesod-default name: yesod-default
version: 0.6.0 version: 0.6.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Patrick Brisbin author: Patrick Brisbin
@ -18,7 +18,7 @@ library
cpp-options: -DWINDOWS cpp-options: -DWINDOWS
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, yesod-core >= 0.10 && < 0.11 , yesod-core >= 0.10.1&& < 0.11
, warp >= 1.1 && < 1.2 , warp >= 1.1 && < 1.2
, wai >= 1.1 && < 1.2 , wai >= 1.1 && < 1.2
, wai-extra >= 1.1 && < 1.2 , wai-extra >= 1.1 && < 1.2

View File

@ -11,7 +11,7 @@ module Yesod.Form.Nic
) where ) where
import Yesod.Handler import Yesod.Handler
import Yesod.Core (Route) import Yesod.Core (Route, yepnopeJs, Yesod)
import Yesod.Form import Yesod.Form
import Yesod.Widget import Yesod.Widget
import Text.HTML.SanitizeXSS (sanitizeBalance) import Text.HTML.SanitizeXSS (sanitizeBalance)
@ -23,7 +23,7 @@ import Data.Text (Text, pack)
import qualified Data.Text as T import qualified Data.Text as T
import Data.Maybe (listToMaybe) import Data.Maybe (listToMaybe)
class YesodNic a where class Yesod a => YesodNic a where
-- | NIC Editor Javascript file. -- | NIC Editor Javascript file.
urlNicEdit :: a -> Either (Route a) Text urlNicEdit :: a -> Either (Route a) Text
urlNicEdit _ = Right "http://js.nicedit.com/nicEdit-latest.js" urlNicEdit _ = Right "http://js.nicedit.com/nicEdit-latest.js"
@ -41,13 +41,24 @@ nicHtmlField = Field
<textarea id="#{theId}" :not (null theClass):class="#{T.intercalate " " theClass}" name="#{name}" .html>#{showVal val} <textarea id="#{theId}" :not (null theClass):class="#{T.intercalate " " theClass}" name="#{name}" .html>#{showVal val}
|] |]
addScript' urlNicEdit addScript' urlNicEdit
addJulius master <- lift getYesod
addJulius $
case yepnopeJs master of
Nothing ->
#if __GLASGOW_HASKELL__ >= 700 #if __GLASGOW_HASKELL__ >= 700
[julius| [julius|
#else #else
[$julius| [$julius|
#endif #endif
bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("#{theId}")}); bkLib.onDomLoaded(function(){new nicEditor({fullPanel:true}).panelInstance("#{theId}")});
|]
Just _ ->
#if __GLASGOW_HASKELL__ >= 700
[julius|
#else
[$julius|
#endif
(function(){new nicEditor({fullPanel:true}).panelInstance("#{theId}")})();
|] |]
} }
where where

View File

@ -1,5 +1,5 @@
name: yesod-form name: yesod-form
version: 0.4.0 version: 0.4.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>
@ -14,8 +14,8 @@ description: Form handling support for Yesod Web Framework
library library
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, yesod-core >= 0.10 && < 0.11 , yesod-core >= 0.10.1 && < 0.11
, yesod-persistent >= 0.3 && < 0.4 , yesod-persistent >= 0.3.1 && < 0.4
, time >= 1.1.4 , time >= 1.1.4
, hamlet >= 0.10 && < 0.11 , hamlet >= 0.10 && < 0.11
, shakespeare-css >= 0.10 && < 0.11 , shakespeare-css >= 0.10 && < 0.11

View File

@ -1,5 +1,5 @@
name: yesod-json name: yesod-json
version: 0.3.0 version: 0.3.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>
@ -14,7 +14,7 @@ description: Generate content for Yesod using the aeson package.
library library
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, yesod-core >= 0.10 && < 0.11 , yesod-core >= 0.10.1 && < 0.11
, yesod-routes < 0.1 , yesod-routes < 0.1
, aeson >= 0.5 , aeson >= 0.5
, text >= 0.8 && < 1.0 , text >= 0.8 && < 1.0

View File

@ -1,5 +1,5 @@
name: yesod-newsfeed name: yesod-newsfeed
version: 0.4.0 version: 0.4.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman, Patrick Brisbin author: Michael Snoyman, Patrick Brisbin
@ -14,7 +14,7 @@ description: Helper functions and data types for producing News feeds.
library library
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, yesod-core >= 0.10 && < 0.11 , yesod-core >= 0.10.1 && < 0.11
, time >= 1.1.4 , time >= 1.1.4
, hamlet >= 0.10 && < 0.11 , hamlet >= 0.10 && < 0.11
, bytestring >= 0.9.1.4 && < 0.10 , bytestring >= 0.9.1.4 && < 0.10

View File

@ -1,5 +1,5 @@
name: yesod-persistent name: yesod-persistent
version: 0.3.0 version: 0.3.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>
@ -14,7 +14,7 @@ description: Some helpers for using Persistent from Yesod.
library library
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, yesod-core >= 0.10 && < 0.11 , yesod-core >= 0.10.1 && < 0.11
, persistent >= 0.8 && < 0.9 , persistent >= 0.8 && < 0.9
, persistent-template >= 0.8 && < 0.9 , persistent-template >= 0.8 && < 0.9
, transformers >= 0.2.2 && < 0.3 , transformers >= 0.2.2 && < 0.3

View File

@ -61,7 +61,7 @@ So each route is specified by:
> , rhDispatch :: Dispatch res > , rhDispatch :: Dispatch res
> } > }
Your application needs to provide this moudle with a list of routes, and then Your application needs to provide this module with a list of routes, and then
this module will give you back a new dispatch function. In other words: this module will give you back a new dispatch function. In other words:
> toDispatch :: [Route res] -> Dispatch res > toDispatch :: [Route res] -> Dispatch res

View File

@ -1,5 +1,5 @@
name: yesod-routes name: yesod-routes
version: 0.0.0 version: 0.0.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>

View File

@ -1,5 +1,5 @@
name: yesod-static name: yesod-static
version: 0.10.0 version: 0.10.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>
@ -19,7 +19,7 @@ library
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, containers >= 0.2 && < 0.5 , containers >= 0.2 && < 0.5
, old-time >= 1.0 , old-time >= 1.0
, yesod-core >= 0.10 && < 0.11 , yesod-core >= 0.10.1 && < 0.11
, base64-bytestring >= 0.1.0.1 && < 0.2 , base64-bytestring >= 0.1.0.1 && < 0.2
, cereal >= 0.3 && < 0.4 , cereal >= 0.3 && < 0.4
, bytestring >= 0.9.1.4 && < 0.10 , bytestring >= 0.9.1.4 && < 0.10

View File

@ -83,7 +83,7 @@ type Form x = Html -> MForm ~sitearg~ ~sitearg~ (FormResult x, Widget)
-- Please see the documentation for the Yesod typeclass. There are a number -- Please see the documentation for the Yesod typeclass. There are a number
-- of settings which can be configured by overriding methods here. -- of settings which can be configured by overriding methods here.
instance Yesod ~sitearg~ where instance Yesod ~sitearg~ where
approot = appRoot . settings approot = ApprootMaster $ appRoot . settings
-- Place the session key file in the config folder -- Place the session key file in the config folder
encryptKey _ = fmap Just $ getKey "config/client_session_key.aes" encryptKey _ = fmap Just $ getKey "config/client_session_key.aes"

View File

@ -27,6 +27,7 @@
<div id="main" role="main"> <div id="main" role="main">
^{pageBody pc} ^{pageBody pc}
<footer> <footer>
#{extraCopyright $ appExtra $ settings master}
$maybe analytics <- extraAnalytics $ appExtra $ settings master $maybe analytics <- extraAnalytics $ appExtra $ settings master
<script> <script>

View File

@ -1,5 +1,3 @@
$maybe msg <- mmsg $maybe msg <- mmsg
<div #message>#{msg} <div #message>#{msg}
^{widget} ^{widget}
<footer>
#{extraCopyright $ appExtra $ settings master}

View File

@ -60,7 +60,7 @@ mkYesodData "~sitearg~" $(parseRoutesFile "config/routes")
-- Please see the documentation for the Yesod typeclass. There are a number -- Please see the documentation for the Yesod typeclass. There are a number
-- of settings which can be configured by overriding methods here. -- of settings which can be configured by overriding methods here.
instance Yesod ~sitearg~ where instance Yesod ~sitearg~ where
approot = appRoot . settings approot = ApprootMaster $ appRoot . settings
-- Place the session key file in the config folder -- Place the session key file in the config folder
encryptKey _ = fmap Just $ getKey "config/client_session_key.aes" encryptKey _ = fmap Just $ getKey "config/client_session_key.aes"

View File

@ -1,5 +1,5 @@
name: yesod name: yesod
version: 0.10.0 version: 0.10.1
license: BSD3 license: BSD3
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>
@ -73,11 +73,11 @@ library
cpp-options: -DGHC7 cpp-options: -DGHC7
else else
build-depends: base >= 4 && < 4.3 build-depends: base >= 4 && < 4.3
build-depends: yesod-core >= 0.10 && < 0.11 build-depends: yesod-core >= 0.10.1 && < 0.11
, yesod-auth >= 0.8 && < 0.9 , yesod-auth >= 0.8.1 && < 0.9
, yesod-json >= 0.3 && < 0.4 , yesod-json >= 0.3.1 && < 0.4
, yesod-persistent >= 0.3 && < 0.4 , yesod-persistent >= 0.3.1 && < 0.4
, yesod-form >= 0.4 && < 0.5 , yesod-form >= 0.4.1 && < 0.5
, monad-control >= 0.3 && < 0.4 , monad-control >= 0.3 && < 0.4
, transformers >= 0.2.2 && < 0.3 , transformers >= 0.2.2 && < 0.3
, wai >= 1.1 && < 1.2 , wai >= 1.1 && < 1.2