wheb-strapped (empty) → 0.0.1.0
raw patch · 4 files changed
+177/−0 lines, 4 filesdep +StrappedTemplatesdep +Whebdep +basesetup-changed
Dependencies added: StrappedTemplates, Wheb, base, mtl
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- Web/Wheb/Plugins/Strapped.hs +44/−0
- wheb-strapped.cabal +101/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Kyle++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Kyle nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Web/Wheb/Plugins/Strapped.hs view
@@ -0,0 +1,44 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE MultiParamTypeClasses #-}++module Web.Wheb.Plugins.Strapped+ ( StrappedContainer(..)+ , StrappedApp (..)+ , renderTemplate+ , initStrapped + , module Text.Strapped+ ) where++++import Control.Monad.Except++import Web.Wheb++import Text.Strapped++data StrappedContainer m = StrappedContainer + { renderconfig :: RenderConfig + , defaultBucket :: InputBucket m+ }++class StrappedApp g m where+ getStrappedContainer :: g -> StrappedContainer m++-- | Load Strapped from a directory matching the extention+initStrapped :: MonadIO m => FilePath -> String -> InitM g s m (StrappedContainer (WhebT g s m))+initStrapped fp s = do+ mtmpls <- liftIO $ templateStoreFromDirectory fp s+ case mtmpls of+ Left err -> error (show err)+ Right tmpls -> return $ StrappedContainer (defaultConfig { templateStore = tmpls }) []++-- | Render a template or throw an error+renderTemplate :: (MonadIO m, StrappedApp g (WhebT g s m)) => String -> InputBucket (WhebT g s m) -> WhebHandlerT g s m+renderTemplate tName bucket = do+ sc <- getWithApp getStrappedContainer + result <- render (renderconfig sc) (combineBuckets bucket (defaultBucket sc)) tName+ case result of+ Left err -> throwError $ Error500 (show err)+ Right b -> builder "text/html" b
+ wheb-strapped.cabal view
@@ -0,0 +1,101 @@+-- Initial wheb-strapped.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++-- The name of the package.+name: wheb-strapped++-- The package version. See the Haskell package versioning policy (PVP) +-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary: +-+------- breaking API changes+-- | | +----- non-breaking API additions+-- | | | +--- code changes with no API change+version: 0.0.1.0++-- A short (one-line) description of the package.+synopsis: Strapped templates for Wheb++-- A longer description of the package.+-- description: ++-- URL for the project homepage or repository.+homepage: https://github.com/hansonkd/Wheb-Framework++-- The license under which the package is released.+license: BSD3++-- The file containing the license text.+license-file: LICENSE++-- The package author(s).+author: Kyle++-- An email address to which users can send suggestions, bug reports, and +-- patches.+maintainer: me@khanson.io++-- A copyright notice.+-- copyright: ++category: Web++build-type: Simple++-- Extra files to be distributed with the package, such as examples or a +-- README.+-- extra-source-files: ++-- Constraint on the version of Cabal needed to build this package.+cabal-version: >=1.10++description:+ Implements basic functionality for:+ .+ * <http://hackage.haskell.org/package/StrappedTemplates StrappedTemplates>+ .+ * <http://hackage.haskell.org/package/Wheb Wheb>+ .+ /In action:/+ .+ Use with language extensions /OverloadedStrings/, /FlexibleInstances/, /MultiParamTypeClasses/+ .+ > import Control.Monad.Except+ >+ > import Web.Wheb+ > import Web.Wheb.Plugins.Strapped+ > import Text.Strapped+ >+ > type MyApp = WhebT MyGlobalCtx () IO+ > + > data MyGlobalCtx = MyGlobalCtx (StrappedContainer MyApp)+ > + > instance StrappedApp MyGlobalCtx MyApp where+ > getStrappedContainer (MyGlobalCtx g) = g+ > + > main :: IO ()+ > main = do+ > opts <- generateOptions $ do+ > sc <- initStrapped "examples/resources" ".html"+ > addGET "." rootPat $ renderTemplate "index.html" (emptyBucket)+ > return (MyGlobalCtx sc, ())+ > runWhebServer opts++library+ -- Modules exported by the library.+ exposed-modules: Web.Wheb.Plugins.Strapped+ + -- Modules included in this library but not exported.+ -- other-modules: + + -- LANGUAGE extensions used by modules in this package.+ other-extensions: OverloadedStrings, FlexibleContexts, MultiParamTypeClasses+ + -- Other library packages from which modules are imported.+ build-depends: base >=4.7 && <4.8, mtl >=2.2 && <2.3, Wheb >=0.2 && <0.3, StrappedTemplates >=0.1 && <0.2+ + -- Directories containing source files.+ -- hs-source-dirs: + + -- Base language which the package is written in.+ default-language: Haskell2010+