1

我正在使用 Heist 做一个项目,由于它最近升级到 0.13 版本,我尝试了一下,发现原来的 HeistConfig 改变了很多。

data HeistConfig m = HeistConfig
    { hcInterpretedSplices :: Splices (I.Splice m)
        -- ^ Interpreted splices are the splices that Heist has always had.  They
        -- return a list of nodes and are processed at runtime.
    , hcLoadTimeSplices    :: Splices (I.Splice IO)
        -- ^ Load time splices are like interpreted splices because they return a
        -- list of nodes.  But they are like compiled splices because they are
        -- processed once at load time.  All of Heist's built-in splices should be
        -- used as load time splices.
    , hcCompiledSplices    :: Splices (C.Splice m)
        -- ^ Compiled splices return a DList of Chunks and are processed at load
        -- time to generate a runtime monad action that will be used to render the
        -- template.
    , hcAttributeSplices   :: Splices (AttrSplice m)
        -- ^ Attribute splices are bound to attribute names and return a list of
        -- attributes.
    , hcTemplateLocations  :: [TemplateLocation]
        -- ^ A list of all the locations that Heist should get its templates
    }

所以现在我不能再使用 [] 作为默认 Splices,因为有 defaultInterpretedSplices 和 defaultLoadTimeSplices,我发现 defaultAttrSplices 只是错过了,那么我应该如何定义它呢?

4

1 回答 1

2

我认为没有内置的 AttrSplices。您应该能够使用或from之一mempty来绑定任何接头。return ()noSplicesHeist.SpliceAPI

Splices s是 的类型别名SplicesM s (),它只是一个State包装在 newtype 中。 Slices s也是 Monoid 类型类的实例,所以你可以在这里使用 mempty。

newtype SplicesM s a = SplicesM { unSplices :: State (Map Text s) a }
  deriving (Monad, MonadState (Map Text s))

type Splices s = SplicesM s ()

instance Monoid (Splices s) where
  mempty = noSplices
  mappend = unionWithS (\_ b -> b)
于 2013-09-15T20:22:10.480 回答