happstack-jmacro-7.0.12.2/0000755000000000000000000000000013564535400013363 5ustar0000000000000000happstack-jmacro-7.0.12.2/Setup.hs0000644000000000000000000000011013564535400015007 0ustar0000000000000000#!/usr/bin/env runhaskell import Distribution.Simple main = defaultMain happstack-jmacro-7.0.12.2/LICENSE0000644000000000000000000000275313564535400014377 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.2/happstack-jmacro.cabal0000644000000000000000000000240313564535400017575 0ustar0000000000000000Name: happstack-jmacro Version: 7.0.12.2 Synopsis: Support for using JMacro with Happstack Description: JMacro provides QuasiQuote support for embedding javascript in Haskell source. This module provides some helper functions for serving the generated javascript via 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 == 8.0.1, GHC == 8.2.2, GHC == 8.4.1, GHC == 8.6.5, GHC == 8.8.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.7, jmacro == 0.6.*, wl-pprint-text >= 1.1 && < 1.3, 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.2/Happstack/0000755000000000000000000000000013564535400015301 5ustar0000000000000000happstack-jmacro-7.0.12.2/Happstack/Server/0000755000000000000000000000000013564535400016547 5ustar0000000000000000happstack-jmacro-7.0.12.2/Happstack/Server/JMacro.hs0000644000000000000000000000476113564535400020266 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