packages feed

hakyll-blaze-templates (empty) → 0.1.0.0

raw patch · 4 files changed

+149/−0 lines, 4 filesdep +basedep +blaze-htmldep +hakyllsetup-changed

Dependencies added: base, blaze-html, hakyll

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Simonas Kazlauskas++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 Simonas Kazlauskas 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
+ hakyll-blaze-templates.cabal view
@@ -0,0 +1,57 @@+-- The name of the package.+name:                hakyll-blaze-templates++-- The package version.  See the Haskell package versioning policy (PVP)+-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:             0.1.0.0++-- A short (one-line) description of the package.+synopsis:            Blaze templates for Hakyll++-- A longer description of the package.+-- description:++-- The license under which the package is released.+license:             BSD3+-- The file containing the license text.+license-file:        LICENSE+-- The package author(s).+author:              Simonas Kazlauskas+-- An email address to which users can send suggestions, bug reports, and+-- patches.+maintainer:          git@kazlauskas.me+bug-reports:         https://github.com/simukis/hakyll-blaze-templates/issues++-- A copyright notice.+-- copyright:++category:            Web+build-type:          Simple++-- Constraint on the version of Cabal needed to build this package.+cabal-version:       >=1.8++Source-Repository head+  Type:     git+  Location: git://github.com/simukis/hakyll-blaze-templates.git+++library+  -- Modules exported by the library.+  exposed-modules:     Hakyll.Web.Template.Blaze++  -- Modules included in this library but not exported.+  -- other-modules:++  -- Other library packages from which modules are imported.+  build-depends:       base       == 4.6.*,+                       hakyll     == 4.2.*,+                       blaze-html == 0.6.*++  -- Directories containing source files.+  hs-source-dirs:      src+
+ src/Hakyll/Web/Template/Blaze.hs view
@@ -0,0 +1,60 @@+module Hakyll.Web.Template.Blaze+    ( Template+    , applyTemplate+    , applyTemplateList+    , applyTemplateListWith+    , toHtml+    , safeToHtml+    ) where++import Hakyll                          (Context(..), Item, Compiler,+                                        itemSetBody, missingField, itemBody)+import Data.Monoid                     (mappend)+import Data.List                       (intercalate)+import Text.Blaze.Html                 (Html)+import qualified Text.Blaze.Html as H+import Text.Blaze.Html.Renderer.String (renderHtml)+++type Template m a = (String -> m String) -> Item a -> m Html+++applyTemplate :: Template Compiler String -- ^ Blaze template+              -> Context String           -- ^ Hakyll context+              -> Item String              -- ^ The item+              -> Compiler (Item String)   -- ^ Resulting HTML+applyTemplate tpl ctx item =+    tpl ctx' item+    >>= return . renderHtml+    >>= \body -> return $ itemSetBody body item+  where+    ctx' :: String -> Compiler String+    ctx' key = unContext (ctx `mappend` missingField) key item+++applyTemplateListWith :: String              -- ^ String to join template with+                      -> Template Compiler String -- ^ Blaze template+                      -> Context String           -- ^ Hakyll context+                      -> [Item String]            -- ^ List of items+                      -> Compiler String          -- ^ Resulting HTML+applyTemplateListWith delimiter tpl ctx items =+    mapM (applyTemplate tpl ctx) items+    >>= return . intercalate delimiter . map itemBody+++applyTemplateList = applyTemplateListWith ""+++toHtml, safeToHtml :: String -> Html+-- | Synonym for blaze's toHtml. The only difference being that input string is+-- enforced to String type. This is necessary for easy use of this function+-- with -XOverloadedStrings. Otherwise compiler can't infer the appropriate+-- type to use and fails.+toHtml = H.toHtml++-- | Synonym for blaze's preEscapedToHtml. The only difference being that input+-- string is enforced to String type. This is necessary for easy use of this+-- function with -XOverloadedStrings. Otherwise compiler can't infer the+-- appropriate type to use and fails.+-- Also safeToHtml sounds better than preEscapedToHtml+safeToHtml = H.preEscapedToHtml