packages feed

blaze-html-hexpat (empty) → 0.1.0.0

raw patch · 4 files changed

+147/−0 lines, 4 filesdep +basedep +blaze-htmldep +bytestringsetup-changed

Dependencies added: base, blaze-html, bytestring, hexpat, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Jasper Van der Jeugt 2010++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 Jasper Van der Jeugt 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,2 @@+import Distribution.Simple+main = defaultMain
+ Text/Blaze/Renderer/Hexpat.hs view
@@ -0,0 +1,82 @@+-- | Renderer that supports rendering to expat forests+--+-- Warning: because this renderer doesn't directly create the output, but rather+-- an XML tree representation, it is impossible to render pre-escaped text. This+-- means that @preEscapedString@ will produce the same output as @string@. This+-- also applies to the functions @preEscapedText@, @preEscapedTextValue@...+--+module Text.Blaze.Renderer.Hexpat+    ( Forest+    , renderHtml+    ) where++import Data.ByteString (ByteString)+import qualified Data.ByteString as SB+import qualified Data.Text as T+import qualified Data.Text.Encoding as T (encodeUtf8)+import qualified Text.XML.Expat.Tree as X++import Text.Blaze.Internal++-- | Type used as list of nodes+--+type Forest = [X.Node ByteString ByteString]++-- | Render a 'ChoiceString' to a bytestring. This is only meant to be used for+-- shorter strings, since it is inefficient for large strings.+--+fromChoiceStringSB :: ChoiceString -> ByteString+fromChoiceStringSB (Static s)               = getUtf8ByteString s+fromChoiceStringSB (String s)               = T.encodeUtf8 $ T.pack s+fromChoiceStringSB (Text s)                 = T.encodeUtf8 s+fromChoiceStringSB (ByteString s)           = s+fromChoiceStringSB (PreEscaped s)           = fromChoiceStringSB s+fromChoiceStringSB (External s)             = fromChoiceStringSB s+fromChoiceStringSB (AppendChoiceString x y) =+    fromChoiceStringSB x `SB.append` fromChoiceStringSB y+fromChoiceStringSB EmptyChoiceString        = SB.empty+{-# INLINE fromChoiceStringSB #-}++-- | Render a 'ChoiceString' to an appending list of nodes+--+fromChoiceString :: ChoiceString+                 -> Forest+                 -> Forest+fromChoiceString s@(Static _)     = (X.Text (fromChoiceStringSB s) :)+fromChoiceString s@(String _)     = (X.Text (fromChoiceStringSB s) :)+fromChoiceString s@(Text _)       = (X.Text (fromChoiceStringSB s) :)+fromChoiceString s@(ByteString _) = (X.Text (fromChoiceStringSB s) :)+fromChoiceString (PreEscaped s)   = fromChoiceString s+fromChoiceString (External s)     = fromChoiceString s+fromChoiceString (AppendChoiceString x y) =+    fromChoiceString x . fromChoiceString y+fromChoiceString EmptyChoiceString = id+{-# INLINE fromChoiceString #-}++-- | Render some 'Html' to an appending list of nodes+--+renderNodes :: Html+            -> Forest+            -> Forest+renderNodes = go []+  where+    go :: [(ByteString, ByteString)] -> HtmlM b -> Forest -> Forest+    go attrs (Parent tag _ _ content) =+        (X.Element (getUtf8ByteString tag) attrs (go [] content []) :)+    go attrs (Leaf tag _ _) =+        (X.Element (getUtf8ByteString tag) attrs [] :)+    go attrs (AddAttribute key _ value content) =+        go ((getUtf8ByteString key, fromChoiceStringSB value) : attrs) content+    go attrs (AddCustomAttribute key _ value content) =+        go ((fromChoiceStringSB key, fromChoiceStringSB value) : attrs) content+    go _ (Content content) = fromChoiceString content+    go attrs (Append h1 h2) = go attrs h1 . go attrs h2+    go _ Empty = id+    {-# NOINLINE go #-}+{-# INLINE renderNodes #-}++-- | Render HTML to an expat forest+--+renderHtml :: Html -> Forest+renderHtml html = renderNodes html []+{-# INLINE renderHtml #-}
+ blaze-html-hexpat.cabal view
@@ -0,0 +1,33 @@+Name:                blaze-html-hexpat+Version:             0.1.0.0+Synopsis:            A hexpat backend for blaze-html.+Description:         Allows you to generate hexpat node trees using blaze+                     syntax.+Homepage:            https://github.com/jaspervdj/blaze-html-hexpat+License:             BSD3+License-file:        LICENSE+Author:              Jasper Van der Jeugt, Doug Beardsley+Maintainer:          Jasper Van der Jeugt <jaspervdj@gmail.com>+Copyright:           Jasper Van der Jeugt+Stability:           Experimental+Category:            Text+Build-type:          Simple+Cabal-version:       >=1.6+++Source-repository head+  Type:              git+  Location:          http://github.com/jaspervdj/blaze-html-hexpat.git++Library+  Ghc-Options:       -Wall++  -- Modules exported by the library.+  Exposed-modules:   Text.Blaze.Renderer.Hexpat++  -- Packages needed in order to build this package.+  Build-depends:     base >= 4 && < 5,+                     text >= 0.10,+                     bytestring >= 0.9,+                     blaze-html >= 0.3.2 && < 0.4,+                     hexpat >= 0.19 && < 0.20