packages feed

hsx-jmacro (empty) → 6.0.0

raw patch · 4 files changed

+118/−0 lines, 4 filesdep +basedep +hsxdep +jmacrosetup-changed

Dependencies added: base, hsx, jmacro, mtl, pretty

Files

+ HSX/JMacro.hs view
@@ -0,0 +1,62 @@+{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- | This module provides support for embedding javascript generated by jmacro into HSX.+--+-- It provides the following instances:+--+-- > instance (XMLGenerator m, IntegerSupply m) => EmbedAsChild m JStat+-- > instance (IntegerSupply m, IsName n, EmbedAsAttr m (Attr Name String)) => EmbedAsAttr m (Attr n JStat)+-- +-- In order to ensure that each embedded 'JStat' block has unique+-- variable names, the monad must supply a source of unique+-- names. This is done by adding an instance of 'IntegerSupply' for+-- the monad being used with 'XMLGenerator'.+--+-- For example, an 'IntegerSupply' for 'ServerPartT':+--+-- > instance IntegerSupply (ServerPartT (StateT Integer IO)) where+-- >     nextInteger = nextInteger'+--+-- This variation avoids the use of an extra monad transformer:+--+-- > instance IntegerSupply (ServerPartT IO) where+-- >     nextInteger = fmap (fromIntegral . (`mod` 1024) . hashUnique) (liftIO newUnique)+--+module HSX.JMacro where++import Control.Monad.Trans             (lift)+import Control.Monad.State             (MonadState(get,put))+import HSX.XMLGenerator                (XMLGenerator(..), XMLGen(..), EmbedAsChild(..), EmbedAsAttr(..), IsName(..), Attr(..), Name)+import Language.Javascript.JMacro      (JStat(..), jsToDoc, jsSaturate, renderJs)+import Text.PrettyPrint.HughesPJ       (Style(..), Mode(..), render, renderStyle, style)++class IntegerSupply m where +    nextInteger :: m Integer++-- | This help function allows you to easily create an 'IntegerSupply'+-- instance for monads that have a 'MonadState' 'Integer' instance.+--+-- For example:+--+-- > instance IntegerSupply (ServerPartT (StateT Integer IO)) where+-- >     nextInteger = nextInteger'+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 $ genElement (Nothing, "script")+                    [asAttr ("type" := "text/javascript")]+                    [asChild (render $ jsToDoc $ jsSaturate (Just ('i' : show i)) jstat)]+++instance (IntegerSupply m, IsName n, EmbedAsAttr m (Attr Name String)) => EmbedAsAttr m (Attr n JStat) where+  asAttr (n := jstat) = +      do i <- lift nextInteger+         asAttr $ (toName n := (renderStyle lineStyle $ jsToDoc $ jsSaturate (Just ('i' : show i)) jstat))+      where+        lineStyle = style { mode= OneLineMode }
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Jeremy Shaw 2011++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 Jeremy Shaw 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,3 @@+#!/usr/bin/env runhaskell+import Distribution.Simple+main = defaultMain
+ hsx-jmacro.cabal view
@@ -0,0 +1,23 @@+Name:                hsx-jmacro+Version:             6.0.0+Synopsis:            hsx+jmacro support+Description:         HSX allows for the use of literal XML in Haskell program text. JMacro allows for the use of javascript-syntax for generating javascript in Haskell. This library makes it easy to embed JMacro generated javascript in HSX templates.+Homepage:            http://www.happstack.com/+License:             BSD3+License-file:        LICENSE+Author:              Jeremy Shaw+Maintainer:          jeremy@n-heptane.com+Stability:           Provisional+Category:            Web+Build-type:          Simple+Cabal-version:       >=1.2++Library+  Exposed-modules:   HSX.JMacro++  Build-depends:       +                     base >4 && <5,+                     hsx,+                     jmacro,+                     mtl,+                     pretty