[happstack-jmacro: split out hsx-specific code into hsx-jmacro. jeremy@n-heptane.com**20110517232725 Ignore-this: f1a4bfd05a7d48e789af7938b2a86223 ] move ./happstack-jmacro/Happstack/Server/HSP/JMacro.hs ./happstack-jmacro/Happstack/Server/JMacro.hs rmdir ./happstack-jmacro/Happstack/Server/HSP hunk ./happstack-jmacro/Happstack/Server/JMacro.hs 1 -{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses #-} -{-# OPTIONS_GHC -F -pgmFtrhsx -fno-warn-orphans #-} -module Happstack.Server.HSP.JMacro where +-- |This modules provides support for using JMacro with Happstack. +-- +-- It provides the instance, +-- +-- > instance ToMessage JStat +-- +-- Which will serve a 'JStat' value as @text/javascript; charset=UTF-8@. +module Happstack.Server.JMacro where hunk ./happstack-jmacro/Happstack/Server/JMacro.hs 11 -import Data.ByteString.Lazy.UTF8 as LB (fromString) -import Control.Monad.Trans (lift) -import Control.Monad.State (MonadState(get,put)) -import Happstack.Server (ToMessage(..)) -import HSP -import Language.Javascript.JMacro (JStat(..), jsToDoc, jsSaturate, renderJs) -import Text.PrettyPrint.HughesPJ - -class IntegerSupply m where - nextInteger :: m Integer - -nextInteger' :: (MonadState Integer m) => m Integer -nextInteger' = - do i <- get - put (succ i) - return i - -instance (XMLGenerator m, IntegerSupply m) => EmbedAsChild m JStat where - asChild jstat = - do i <- lift nextInteger - asChild $ - - -instance (EmbedAsAttr m Attribute, IntegerSupply m, IsName n) => EmbedAsAttr m (Attr n JStat) where - asAttr (n := jstat) = - do i <- lift nextInteger - asAttr $ MkAttr (toName n, pAttrVal $ renderStyle lineStyle $ jsToDoc $ jsSaturate (Just ('i' : show i)) jstat) - where - lineStyle = style { mode= OneLineMode } - +import Data.ByteString.Lazy.UTF8 as LB +import Happstack.Server (ToMessage(..)) +import Language.Javascript.JMacro (JStat(..), renderJs) hunk ./happstack-jmacro/examples/Examples.lhs 1 -JMacro is a library that makes it easy to generate javascript in -Haskell. This is useful even if are just trying to add a little bit of -javascript code to your HTML templates. +#ifdef WOOT +To generate .html from this file run: + +cpphs -DHsColour --noline Examples.lhs | HsColour -lit -css | markdown --html4tags > examples.html + +And remove the extra
around the tags. +#endif + +JMacro is a +library that makes it easy to generate javascript in Haskell. This is +useful even if are just trying to add a little bit of javascript code +to your HTML templates. hunk ./happstack-jmacro/examples/Examples.lhs 31 -The happstack-jmacro library makes it easy to use JMacro with Happstack and HSP. +The happstack-jmacro library makes it easy to use JMacro with Happstack and HSP. hunk ./happstack-jmacro/examples/Examples.lhs 36 -pre-processors. Instead it uses the magic of QuasiQuotation. -http://haskell.org/haskellwiki/Quasiquotation +pre-processors. Instead it uses the magic of QuasiQuotation. hunk ./happstack-jmacro/examples/Examples.lhs 41 -> {-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, TypeSynonymInstances, QuasiQuotes #-} +> {-# LANGUAGE CPP, FlexibleInstances, GeneralizedNewtypeDeriving, TypeSynonymInstances, QuasiQuotes #-} hunk ./happstack-jmacro/examples/Examples.lhs 58 +> import Data.Unique hunk ./happstack-jmacro/examples/Examples.lhs 61 -> import Happstack.Server.HSP.JMacro (IntegerSupply(..), nextInteger') +> import Happstack.Server.JMacro () -- ToMessage instance for JStat hunk ./happstack-jmacro/examples/Examples.lhs 64 +> import HSX.JMacro (IntegerSupply(..), nextInteger') -- ^ EmbedAsChild and EmbedAsAttr instances for JStat hunk ./happstack-jmacro/examples/Examples.lhs 68 -In order to ensure that each