Skip to content

Commit

Permalink
Cleanup, documentation, add generated cabal file.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Apr 19, 2010
1 parent ed66e4d commit fa5519d
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 89 deletions.
70 changes: 70 additions & 0 deletions BlazeHtml.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-- BlazeHtml.cabal auto-generated by cabal init. For additional
-- options, see
-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.
-- The name of the package.
Name: BlazeHtml

-- The package version. See the Haskell package versioning policy
-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
-- standards guiding when and how versions should be incremented.
Version: 0.1

-- A short (one-line) description of the package.
Synopsis: A blazingly fast HTML generation library.

-- A longer description of the package.
-- Description:

-- URL for the project homepage or repository.
Homepage: https://github.com/jaspervdj/BlazeHtml

-- The license under which the package is released.
License: BSD3

-- The file containing the license text.
License-file: LICENSE

-- The package author(s).
Author: Jasper Van der Jeugt

-- An email address to which users can send suggestions, bug reports,
-- and patches.
Maintainer: [email protected]

-- A copyright notice.
-- Copyright:

-- Stability of the pakcage (experimental, provisional, stable...)
Stability: Experimental

Category: Text

Build-type: Simple

-- Extra files to be distributed with the package, such as examples or
-- a README.
-- Extra-source-files:

-- Constraint on the version of Cabal needed to build this package.
Cabal-version: >=1.2


Library
-- Source directories
Hs-Source-Dirs: src,
lib/binary-0.5.0.2/src

-- Modules exported by the library.
Exposed-modules: Text.Blaze.Internal.Utf8Builder

-- Packages needed in order to build this package.
Build-depends: base >= 4 && < 5,
text >= 0.7,
bytestring >= 0.9

-- Modules not exported by this package.
Other-modules: Data.Binary.Builder

-- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.
-- Build-tools:

30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env runhaskell
import Distribution.Simple
main = defaultMain
2 changes: 1 addition & 1 deletion benchmarks/Utf8Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ benchByteStrings = BL.length . toLazyByteString

benchByteStrings' :: [S.ByteString] -> Int64
benchByteStrings' = BL.length . toLazyByteString
. mconcat . map fromSmallByteString
. mconcat . map fromRawByteString

benchText :: [Text] -> Int64
benchText = BL.length . toLazyByteString . mconcat
Expand Down
58 changes: 29 additions & 29 deletions benchmarks/Utf8Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ text = Html . const . fromHtmlText
{-# INLINE text #-}

rawByteString :: ByteString -> Html
rawByteString = Html . const . fromSmallByteString
rawByteString = Html . const . fromRawByteString
{-# INLINE rawByteString #-}

showHtml :: Show a => a -> Html
Expand All @@ -54,31 +54,31 @@ showHtml = Html . const . fromHtmlString . show

tag :: ByteString -> Html -> Html
tag name inner = Html $ \attrs ->
fromAscii7Char '<' `mappend` (fromSmallByteString name
`mappend` (attrs
`mappend` (fromAscii7Char '>'
`mappend` (runHtml inner mempty
`mappend` (fromSmallByteString "</"
`mappend` (fromSmallByteString name
`mappend` (fromAscii7Char '>')))))))
fromRawAscii7Char '<' `mappend` (fromRawByteString name
`mappend` (attrs
`mappend` (fromRawAscii7Char '>'
`mappend` (runHtml inner mempty
`mappend` (fromRawByteString "</"
`mappend` (fromRawByteString name
`mappend` (fromRawAscii7Char '>')))))))
{-# INLINE tag #-}

addAttr :: ByteString -> Text -> Html -> Html
addAttr key value h = Html $ \attrs ->
runHtml h $ attrs `mappend` (fromAscii7Char ' '
`mappend` (fromSmallByteString key
`mappend` (fromSmallByteString "=\""
runHtml h $ attrs `mappend` (fromRawAscii7Char ' '
`mappend` (fromRawByteString key
`mappend` (fromRawByteString "=\""
`mappend` (fromHtmlText value
`mappend` (fromAscii7Char '"')))))
`mappend` (fromRawAscii7Char '"')))))
{-# INLINE addAttr #-}

tag' :: ByteString -> ByteString -> Html -> Html
tag' begin end = \inner -> Html $ \attrs ->
fromSmallByteString begin
fromRawByteString begin
`mappend` attrs
`mappend` fromAscii7Char '>'
`mappend` fromRawAscii7Char '>'
`mappend` runHtml inner mempty
`mappend` fromSmallByteString end
`mappend` fromRawByteString end
{-# INLINE tag' #-}

tableB, tableE :: ByteString
Expand Down Expand Up @@ -164,7 +164,7 @@ hello2 = "Hello, me!"
hello3 = "Hello, world!"
loop = "Loop"

static = Html . const . fromSmallByteString
static = Html . const . fromRawByteString
{-# INLINE static #-}

basic :: (Text, Text, [Text]) -- ^ (Title, User, Items)
Expand Down Expand Up @@ -194,33 +194,33 @@ textM = HtmlM . const . fromHtmlText
{-# INLINE textM #-}

rawByteStringM :: ByteString -> HtmlM a
rawByteStringM = HtmlM . const . fromSmallByteString
rawByteStringM = HtmlM . const . fromRawByteString
{-# INLINE rawByteStringM #-}

showAscii7HtmlM :: Show a => a -> HtmlM a
showAscii7HtmlM = HtmlM . const . fromAscii7Show
showAscii7HtmlM = HtmlM . const . fromHtmlShow
{-# INLINE showAscii7HtmlM #-}

tagM :: ByteString -> HtmlM a -> HtmlM a
tagM name inner = HtmlM $ \attrs ->
fromAscii7Char '<' `mappend` (fromSmallByteString name
`mappend` (attrs
`mappend` (fromAscii7Char '>'
`mappend` (runHtmlM inner mempty
`mappend` (fromSmallByteString "</"
`mappend` (fromSmallByteString name
`mappend` (fromAscii7Char '>')))))))
fromRawAscii7Char '<' `mappend` (fromRawByteString name
`mappend` (attrs
`mappend` (fromRawAscii7Char '>'
`mappend` (runHtmlM inner mempty
`mappend` (fromRawByteString "</"
`mappend` (fromRawByteString name
`mappend` (fromRawAscii7Char '>')))))))
-- By inlining this function, functions calling this (e.g. `tableHtml`) will close
-- around the `tag` variable, which ensures `tag'` is only calculated once.
{-# INLINE tagM #-}

addAttrM :: ByteString -> Text -> HtmlM a -> HtmlM a
addAttrM key value h = HtmlM $ \attrs ->
runHtmlM h $ attrs `mappend` (fromAscii7Char ' '
`mappend` (fromSmallByteString key
`mappend` (fromSmallByteString "=\""
runHtmlM h $ attrs `mappend` (fromRawAscii7Char ' '
`mappend` (fromRawByteString key
`mappend` (fromRawByteString "=\""
`mappend` (fromHtmlText value
`mappend` (fromAscii7Char '"')))))
`mappend` (fromRawAscii7Char '"')))))
{-# INLINE addAttrM #-}

tableM = tagM "table"
Expand Down
Loading

0 comments on commit fa5519d

Please sign in to comment.