scotty-hastache 0.1.0 → 0.2.0
raw patch · 4 files changed
+56/−22 lines, 4 filesdep +textdep ~scotty
Dependencies added: text
Dependency ranges changed: scotty
Files
- changelog +20/−0
- examples/hastachetest.hs +1/−1
- scotty-hastache.cabal +9/−7
- src/Web/Scotty/Hastache.hs +26/−14
+ changelog view
@@ -0,0 +1,20 @@+0.2+---++Keeping up with the Scotty 0.6 updating. The introduction of the+custom exception types is reflected in the `scotty-hastache` package+as well. The main types are now polymorphic over an exception type++ type ScottyH e = ScottyT e HState+ type ActionH e = ActionT e HState++In addition, the specialized (to `Text`) types and runners are+introduced++ type ScottyH' = ScottyH Text+ type ActionH' = ActionH Text+ scottyH' :: Port -> ScottyH' () -> IO ()+ scottyHOpts' :: Options -> ScottyH' () -> IO ()+++Thanks to Kirill Zaborsky for pointing out the incompatibility with 0.6.
examples/hastachetest.hs view
@@ -7,7 +7,7 @@ import Web.Scotty.Hastache main :: IO ()-main = scottyH 3000 $ do+main = scottyH' 3000 $ do setTemplatesDir "templates" get "/:word" $ do
scotty-hastache.cabal view
@@ -1,7 +1,7 @@ name: scotty-hastache-version: 0.1.0-homepage: https://github.com/co-dan/scotty-hastache-bug-reports: https://github.com/co-dan/scotty-hastache/issues+version: 0.2.0+homepage: https://github.com/scotty-web/scotty-hastache+bug-reports: https://github.com/scotty-web/scotty-hastache/issues synopsis: Easy Mustache templating support for Scotty description: This library provides a small templating DSL extension@@ -16,13 +16,14 @@ license-file: LICENSE author: Dan Frumin maintainer: difrumin@gmail.com-copyright: (c) 2013 Dan Frumin <difrumin@gmail.com>+copyright: (c) 2013-2014 Dan Frumin <difrumin@gmail.com> category: Web stability: experimental build-type: Simple cabal-version: >=1.10 -extra-source-files: examples/hastachetest.hs+extra-source-files: changelog+ examples/hastachetest.hs examples/templates/greet.html library@@ -35,7 +36,8 @@ hastache >= 0.5.0, http-types >= 0.7.3.0.1, mtl >= 2.1.2,- scotty >= 0.5.0,+ scotty >= 0.6,+ text >= 0.11.3.1, wai >= 1.3.0.1, warp >= 1.3.4.1 @@ -46,4 +48,4 @@ source-repository head type: git- location: git://github.com/co-dan/scotty-hastache.git+ location: git://github.com/scotty-web/scotty-hastache.git
src/Web/Scotty/Hastache.hs view
@@ -17,7 +17,7 @@ import Web.Scotty.Hastache main :: IO ()-main = scottyH 3000 $ do+main = scottyH' 3000 $ do setTemplatesDir \"templates\" -- ^ Setting up the director with templates get \"/:word\" $ do@@ -49,6 +49,7 @@ import qualified Data.Map as M import Data.Maybe (fromMaybe) import Data.Monoid (mempty)+import Data.Text.Lazy (Text) import Network.Wai (Application, Response) import Network.Wai.Handler.Warp (Port) import System.FilePath.Posix ((</>))@@ -57,46 +58,57 @@ import Text.Blaze.Internal (Markup) import Text.Hastache import Text.Hastache.Context+ import Web.Scotty.Trans as S -- * Runners and types -- | The runner to use instead of 'scotty'-scottyH :: Port -> ScottyH () -> IO ()+scottyH :: (ScottyError e) => Port -> ScottyH e () -> IO () scottyH p s = do (runH, runActionToIO) <- mkHStateRunners defaultConfig scottyT p runH runActionToIO s -- | The runner to use instead of 'scottyOpts'-scottyHOpts :: Options -> ScottyH () -> IO ()+scottyHOpts :: (ScottyError e) => Options -> ScottyH e () -> IO () scottyHOpts opts s = do (runH, runActionToIO) <- mkHStateRunners defaultConfig scottyOptsT opts runH runActionToIO s --- | A type synonym for @ScottyT HState@-type ScottyH = ScottyT HState+-- | A type synonym for @ScottyT e HState@; with custom exception types+type ScottyH e = ScottyT e HState --- | A type synonym for @ScottyT HState@-type ActionH = ActionT HState+-- | A type synonym for @ScottyT e HState@; with custom exception types+type ActionH e = ActionT e HState +-- ** Specialized types and runners++type ScottyH' = ScottyH Text+type ActionH' = ActionH Text++scottyH' :: Port -> ScottyH' () -> IO ()+scottyH' = scottyH+scottyHOpts' :: Options -> ScottyH' () -> IO ()+scottyHOpts' = scottyHOpts+ -- * The DSL itself -- ** Configuration -- | Update the Hastache configuration as whole-setHastacheConfig :: MuConfig IO -> ScottyH ()+setHastacheConfig :: MuConfig IO -> ScottyH e () setHastacheConfig conf = do (_, tmap) <- lift State.get lift . State.put $ (conf, tmap) -- | Modify the Hastache configuration as whole-modifyHastacheConfig :: (MuConfig IO -> MuConfig IO) -> ScottyH ()+modifyHastacheConfig :: (MuConfig IO -> MuConfig IO) -> ScottyH e () modifyHastacheConfig f = lift $ State.modify (f *** id) -- | Set the path to the directory with templates. This affects -- how /both/ 'hastache' and the @{{> template}}@ bit searches for the -- template files.-setTemplatesDir :: FilePath -> ScottyH ()+setTemplatesDir :: FilePath -> ScottyH e () setTemplatesDir dir = do lift $ State.modify $ \(conf :: MuConfig IO, tmap) -> (conf { muTemplateFileDir = Just dir }, tmap)@@ -104,7 +116,7 @@ -- | Set the default extension for template files. This affects -- how /both/ 'hastache' and the @{{> template}}@ bit searches for the -- template files.-setTemplateFileExt :: String -> ScottyH ()+setTemplateFileExt :: String -> ScottyH e () setTemplateFileExt ext = do lift $ State.modify $ \(conf :: MuConfig IO, tmap) -> (conf { muTemplateFileExt = Just ext }, tmap)@@ -119,7 +131,7 @@ -- The variables that have been initialized using 'setH' are -- substituted for their values, uninitialized variables are -- considered to be empty/null.-hastache :: FilePath -> ActionT HState ()+hastache :: ScottyError e => FilePath -> ActionH e () hastache tpl = do ((conf :: MuConfig IO), tmap) <- lift State.get setHeader "Content-Type" "text/html"@@ -131,7 +143,7 @@ raw res -- | Set the value of a mustache variable.-setH :: String -> MuType IO -> ActionT HState ()+setH :: ScottyError e => String -> MuType IO -> ActionH e () setH x y = do (conf, tmap) <- lift State.get lift . State.put $ (conf, M.insert x y tmap)@@ -153,7 +165,7 @@ evalStateT m (muconf, mempty) return (runH, runActionToIO) -scottyHApp :: MuConfig IO -> ScottyH () -> IO Application+scottyHApp :: MuConfig IO -> ScottyH e () -> IO Application scottyHApp conf defs = do (runH, runActionToIO) <- mkHStateRunners conf scottyAppT runH runActionToIO defs