Permalink
Browse files

upgrade to heist-0.10

  • Loading branch information...
freizl committed Jan 2, 2013
1 parent 8008b7a commit f575b9a583b9be7c7ae2bfb2de51be83ea6574e2
Showing with 39 additions and 34 deletions.
  1. +1 −1 .gitignore
  2. +8 −7 example/snap.hs
  3. +17 −15 snaplet-i18n.cabal
  4. +13 −11 src/Snap/Snaplet/I18N.hs
View
@@ -2,4 +2,4 @@ dist
*.o
*.hi
log
-cabal-dev
+cabal-dev*
View
@@ -27,7 +27,9 @@ import qualified Data.ByteString.Lazy as LBS
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Text.XmlHtml as X
-import Text.Templating.Heist
+import Heist
+import qualified Heist.Interpreted as I
+import Control.Lens
import Text.XmlHtml hiding (render)
#ifdef DEVELOPMENT
@@ -45,7 +47,7 @@ data App = App
, _i18n :: Snaplet I18NSnaplet
}
-makeLens ''App
+makeLenses ''App
instance HasHeist App where
heistLens = subSnaplet heist
@@ -63,18 +65,18 @@ decodedParam p = fromMaybe "" <$> getParam p
------------------------------------------------------------------------------
-testSplice :: Splice AppHandler
+testSplice :: I.Splice AppHandler
testSplice = do
locale <- liftIO $ getDefaultLocale
--liftIO $ print locale
- textSplice $ T.pack "test"
+ I.textSplice $ T.pack "test"
index :: AppHandler ()
index = do
- heistLocal (bindSplice "testSplice" testSplice) $ render "index"
+ heistLocal (I.bindSplice "testSplice" testSplice) $ render "index"
-- | wrap to element span
---
+--
------------------------------------------------------------------------------
@@ -117,4 +119,3 @@ getActions conf = do
(appEnvironment =<< getOther conf) app
hPutStrLn stderr $ T.unpack msgs
return (site, cleanup)
-
View
@@ -3,7 +3,7 @@
-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.
-- The name of the package.
Name: snaplet-i18n
-Version: 0.0.3.1
+Version: 0.0.4
Description: A light weight i18n snaplet.
Synopsis: snaplet-i18n
Homepage: https://github.com/HaskellCNOrg/snaplet-i18n
@@ -36,20 +36,22 @@ Library
Other-modules: Paths_snaplet_i18n
Build-Depends:
- base >= 4 && < 5,
- snap == 0.9.*,
- snap-core == 0.9.*,
- snap-loader-dynamic == 0.9.*,
- snap-loader-static == 0.9.*,
- xmlhtml >= 0.2,
- heist >= 0.8.1 && < 0.9,
- bytestring >= 0.9 && < 1.0,
- data-lens-template >= 2.1 && < 2.2,
- data-lens >= 2.0 && < 2.1,
- filepath >= 1.2 && < 1.4,
- directory >= 1.1 && < 1.2,
- configurator >= 0.2 && < 0.3,
- text >= 0.11 && < 0.12
+ base >= 4 && < 5,
+ snap >= 0.10 && < 0.11,
+ xmlhtml >= 0.2,
+ heist >= 0.10 && < 0.11,
+ filepath >= 1.2 && < 1.4,
+ configurator >= 0.2 && < 0.3,
+ lens >= 3.7.0.1 && < 3.8,
+ text >= 0.11 && < 0.12
+
+-- snap-core >= 0.9 && < 0.11,
+
+-- bytestring >= 0.9 && < 0.11,
+-- directory >= 1.1 && < 1.2,
+ --lens >= 3.7.0.1 && < 3.8,
+ -- snap-loader-dynamic == 0.9.*,
+ -- snap-loader-static == 0.9.*,
if impl(ghc >= 6.12.0)
ghc-options: -Wall -fwarn-tabs -funbox-strict-fields
View
@@ -13,11 +13,13 @@ module Snap.Snaplet.I18N
import Control.Monad
import qualified Data.Configurator as Config
import qualified Data.Configurator.Types as Config
-import Data.Lens.Common
+--import Control.Lens
import Data.Maybe
import qualified Data.Text as T
import System.FilePath.Posix
-import Text.Templating.Heist
+import Heist
+import qualified Heist.Interpreted as I
+--import qualified Heist.Compiled as C
import Text.XmlHtml hiding (render)
import qualified Text.XmlHtml as X
@@ -62,7 +64,7 @@ data I18NSnaplet = I18NSnaplet
-- | Compose App with a I18N Snaplet.
--
class HasI18N b where
- i18nLens :: Lens b (Snaplet I18NSnaplet)
+ i18nLens :: SnapletLens b I18NSnaplet
-- | Util functions
--
@@ -96,9 +98,9 @@ initI18NSnaplet l = makeSnaplet "i18n" description datadir $ do
msg <- liftIO $ readMessageFile fp i18nConfig
addDefaultSplices
return $ I18NSnaplet i18nConfig msg
- where addDefaultSplices = addSplices [ ("i18n", liftHeist i18nSplice)
- , ("i18nSpan", liftHeist i18nSpanSplice)]
- -- config dir for snaplet
+ where addDefaultSplices = addSplices [ ("i18n", i18nSplice)
+ , ("i18nSpan", i18nSpanSplice)]
+ -- config dir for current snaplet
datadir = Just $ liftM (++ "/resources") getDataDir
description = "light weight i18n snaplet"
@@ -138,21 +140,21 @@ i18nSpliceAttr = "name"
-- <i18n name="hello"><p><i18nValue/></p></i18n>
--
-- FIXME: Turns out that it is not possible to fail at compilation if value is Nothing but runtime.
-i18nSplice :: HasI18N b => Splice (Handler b b)
+i18nSplice :: HasI18N b => I.Splice (Handler b b)
i18nSplice = do
input <- getParamNode
value <- lift . lookupI18NValue $ getNameAttr input
case childElements input of
[] -> return [X.TextNode value]
- _ -> runChildrenWithText [("i18nValue", value)]
+ _ -> I.runChildrenWithText [("i18nValue", value)]
-- | Splices. use 'span' html element wrap result.
--
-i18nSpanSplice :: HasI18N b => Splice (Handler b b)
+i18nSpanSplice :: HasI18N b => SnapletISplice b -- (Handler b b)
i18nSpanSplice = do
input <- getParamNode
- value <- lift . lookupI18NValue $ getNameAttr input
- return [X.Element "span" (elementAttrs input) [X.TextNode value]]
+ v <- lift . lookupI18NValue $ getNameAttr input
+ return [X.Element "span" (elementAttrs input) [X.TextNode v]]
-- | Look up 'name' attribute value.
--

0 comments on commit f575b9a

Please sign in to comment.