happstack-jmacro-7.0.12/0000755000000000000000000000000013134440604013215 5ustar0000000000000000happstack-jmacro-7.0.12/happstack-jmacro.cabal0000644000000000000000000000215013134440604017426 0ustar0000000000000000Name: happstack-jmacro Version: 7.0.12 Synopsis: Support for using JMacro with Happstack Description: Support for using JMacro with Happstack Homepage: http://www.happstack.com/ License: BSD3 License-file: LICENSE Author: Jeremy Shaw Maintainer: jeremy@n-heptane.com -- Copyright: Stability: Provisional Category: Web, Happstack Build-type: Simple Cabal-version: >=1.6 tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1 Library Exposed-modules: Happstack.Server.JMacro Build-depends: base > 4 && < 5, base64-bytestring >= 0.1 && < 1.1, bytestring >= 0.9 && < 0.11, cereal >= 0.3 && < 0.6, digest == 0.0.*, happstack-server >= 6.4 && < 7.6, jmacro == 0.6.*, wl-pprint-text == 1.1.*, text >= 0.9 && < 1.3, utf8-string >= 0.3 && < 1.1 source-repository head type: git location: https://github.com/Happstack/happstack-jmacro.git happstack-jmacro-7.0.12/LICENSE0000644000000000000000000000275313134440604014231 0ustar0000000000000000Copyright 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. happstack-jmacro-7.0.12/Setup.hs0000644000000000000000000000011013134440604014641 0ustar0000000000000000#!/usr/bin/env runhaskell import Distribution.Simple main = defaultMain happstack-jmacro-7.0.12/Happstack/0000755000000000000000000000000013134440604015133 5ustar0000000000000000happstack-jmacro-7.0.12/Happstack/Server/0000755000000000000000000000000013134440604016401 5ustar0000000000000000happstack-jmacro-7.0.12/Happstack/Server/JMacro.hs0000644000000000000000000000476113134440604020120 0ustar0000000000000000{-# LANGUAGE QuasiQuotes #-} -- |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@. -- The rendered JavaScript will be wrapped in an anonymous function that is -- then called, so as to ensure the statements execute in a local scope. -- An implication of this is that top-level unhygienic variables in JMacro -- will /not/ be globally available; instead, you should set properties on -- the global @window@ object. module Happstack.Server.JMacro (jmResponse) where import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as S import Data.ByteString.Base64.URL (encode) import Data.Digest.Adler32 (adler32) import Data.Serialize (runPut, putWord32le) import qualified Data.Text.Lazy.Encoding as T import Happstack.Server (ToMessage(..), ServerMonad, Request(Request, rqUri), Response, askRq) import Language.Javascript.JMacro (JStat(..), renderJs, renderPrefixJs, jmacro, jLam, toStat) import Text.PrettyPrint.Leijen.Text (Doc, displayT, renderOneLine) -- import Text.PrettyPrint (Style(mode), Mode(OneLineMode), style, renderStyle) mkId :: String -> String mkId = S.unpack . S.map dollar . S.takeWhile (/= '=') . encode . B.dropWhile (== 0) . runPut . putWord32le . adler32 . S.pack where dollar '-' = '$' dollar c = c data PrefixedJStat = PrefixedJStat String JStat instance ToMessage JStat where toContentType _ = S.pack "text/javascript; charset=UTF-8" toMessage js = T.encodeUtf8 . displayT . renderOneLine . renderJs $ scoped where scoped = [jmacro| (function { `(js)`; })(); |] instance ToMessage PrefixedJStat where toContentType _ = S.pack "text/javascript; charset=UTF-8" toMessage (PrefixedJStat prefix js) = T.encodeUtf8 . displayT . renderOneLine . renderPrefixJs (mkId prefix) $ js -- | Render a 'JStat' into a 'Response', saturating the variable names with -- a hash computed from the 'rqUri'. Unlike the 'ToMessage' instance for -- @JStat@, this doesn't wrap the statements in a function and so the -- workaround for global unhygienic names isn't necessary. On the other -- hand, generated variable names are a bit longer. jmResponse :: ServerMonad m => JStat -> m Response jmResponse jstat = do Request{rqUri = uri} <- askRq return . toResponse $ PrefixedJStat uri jstat