Переглянути джерело

Drop Heist support, switch to SassC

master
Peter J. Jones 4 роки тому
джерело
коміт
4807b2a5ba
4 змінених файлів з 12 додано та 145 видалено
  1. 1
    1
      LICENSE
  2. 8
    15
      devalot-hakyll.cabal
  3. 0
    126
      src/Hakyll/Web/Heist.hs
  4. 3
    3
      src/Hakyll/Web/Sass.hs

+ 1
- 1
LICENSE Переглянути файл

@@ -1,4 +1,4 @@
Copyright (c) 2013 Peter Jones <pjones@pmade.com>
Copyright (c) 2013-2015 Peter Jones <pjones@pmade.com>

All rights reserved.


+ 8
- 15
devalot-hakyll.cabal Переглянути файл

@@ -1,32 +1,25 @@
name: devalot-hakyll
version: 0.2.0.0
version: 0.3.0.0
synopsis: Hakyll extensions for Devalot.com
license: BSD3
license-file: LICENSE
author: Peter Jones <pjones@pmade.com>
maintainer: Peter Jones <pjones@pmade.com>
copyright: Copyright (C) 2013 Peter Jones
copyright: Copyright (C) 2013-2015 Peter Jones
category: Web
build-type: Simple
cabal-version: >=1.8

library
exposed-modules:
Hakyll.Web.Heist
exposed-modules:
Hakyll.Web.JavaScript
Hakyll.Web.Sass
hs-source-dirs: src
ghc-options: -Wall
build-depends:
build-depends:
base >= 4.4 && < 5.0,
hakyll >= 4.1 && < 4.2,
heist >= 0.11 && < 0.12,
blaze-builder >= 0.3 && < 0.4,
hakyll >= 4.1 && < 4.8,
hjsmin >= 0.1.4 && < 0.2,
bytestring >= 0.9 && < 0.11,
errors >= 1.4 && < 1.5,
mtl >= 2.1 && < 2.2,
text >= 0.11 && < 0.12,
utf8-string >= 0.3 && < 0.4,
xmlhtml >= 0.2 && < 0.3,
hjsmin >= 0.1.4 && < 0.1.5
utf8-string >= 0.3 && < 0.4

+ 0
- 126
src/Hakyll/Web/Heist.hs Переглянути файл

@@ -1,143 +0,0 @@
{-# LANGUAGE OverloadedStrings #-}

{-

This file is part of the package devalot-hakyll. It is subject to the
license terms in the LICENSE file found in the top-level directory of
this distribution and at git://pmade.com/devalot-hakyll/LICENSE. No
part of devalot-hakyll package, including this file, may be copied,
modified, propagated, or distributed except according to the terms
contained in the LICENSE file.

-}

--------------------------------------------------------------------------------
module Hakyll.Web.Heist
( loadDefaultHeist
, loadHeist
, applyTemplate
, applyTemplateList
, applyJoinTemplateList
, Content
, SpliceT
, State
) where

--------------------------------------------------------------------------------
import Blaze.ByteString.Builder (toByteString)
import Control.Error (runEitherT)
import Control.Monad (liftM)
import Control.Monad.Reader (ReaderT(..), ask)
import Control.Monad.Trans (lift)
import Data.ByteString (ByteString)
import Data.Monoid ((<>))
import Text.XmlHtml (elementAttrs)
import Data.ByteString.UTF8 (toString)
import Data.List (intersperse)
import qualified Data.Text as T

--------------------------------------------------------------------------------
import Hakyll.Core.Compiler
import Hakyll.Core.Item
import Hakyll.Web.Template.Context

--------------------------------------------------------------------------------
import Heist
import qualified Heist.Compiled as C

--------------------------------------------------------------------------------
type Content a = (Context a, Item a)
type SpliceT a = ReaderT (Content a) Compiler
type State a = HeistState (SpliceT a)

--------------------------------------------------------------------------------
loadHeist :: FilePath
-- ^ Directory containing the templates.
-> [(T.Text, C.Splice (SpliceT a))]
-- ^ List of compiled Heist slices.
-> [(T.Text, AttrSplice (SpliceT a))]
-- ^ List of Heist attribute slices.
-> IO (HeistState (SpliceT a))
loadHeist baseDir a b = do
tState <- runEitherT $ do
templates <- loadTemplates baseDir
let splices' = [("hakyll", hakyllSplice)] ++ a
attrs = [("url", urlAttrSplice)] ++ b
hc = HeistConfig [] defaultLoadTimeSplices splices' attrs templates
initHeist hc
either (error . concat) return tState

--------------------------------------------------------------------------------
loadDefaultHeist :: FilePath -> IO (HeistState (SpliceT a))
loadDefaultHeist baseDir = loadHeist baseDir [] []

--------------------------------------------------------------------------------
applyTemplate :: HeistState (SpliceT a) -- ^ HeistState
-> ByteString -- ^ Template name
-> Context a -- ^ Context
-> Item a -- ^ Page
-> Compiler (Item String) -- ^ Resulting item
applyTemplate state name context item = do
case C.renderTemplate state name of
Nothing -> fail badTplError
Just (r,_) -> do builder <- runReaderT r (context, item)
let body = toString $ toByteString builder
return $ itemSetBody body item
where badTplError = "failed to render template: " ++ toString name

--------------------------------------------------------------------------------
applyTemplateList :: HeistState (SpliceT a) -- ^ HeistState
-> ByteString
-> Context a
-> [Item a]
-> Compiler String
applyTemplateList = applyJoinTemplateList ""

--------------------------------------------------------------------------------
applyJoinTemplateList :: String
-> HeistState (SpliceT a) -- ^ HeistState
-> ByteString
-> Context a
-> [Item a]
-> Compiler String
applyJoinTemplateList delimiter state name context items = do
items' <- mapM (applyTemplate state name context) items
return $ concat $ intersperse delimiter $ map itemBody items'

--------------------------------------------------------------------------------
hakyllSplice :: C.Splice (SpliceT a)
hakyllSplice = do
node <- getParamNode
return $ C.yieldRuntimeText $ do
(context, item) <- lift ask
let context' f = unContext (context <> missingField) f item
case lookup "field" $ elementAttrs node of
Nothing -> fail fieldError
Just f -> liftStr $ context' $ T.unpack f
where fieldError = "The `hakyll' splice is missing the `field' attribute"
liftStr s = lift $ lift $ liftM T.pack s

--------------------------------------------------------------------------------
urlAttrSplice :: AttrSplice (SpliceT a)
urlAttrSplice _ = do
(context, item) <- lift ask
let url = unContext (context <> missingField) "url" item
val <- lift $ lift $ liftM T.pack url
return $ ("href", val) : []

+ 3
- 3
src/Hakyll/Web/Sass.hs Переглянути файл

@@ -21,16 +21,16 @@ import Hakyll.Web.CompressCss (compressCss)
--------------------------------------------------------------------------------
-- | Convert a @*.sass@ file into compressed CSS.
sassCompiler :: Compiler (Item String)
sassCompiler = toCSS "sass"
sassCompiler = toCSS "sassc"

--------------------------------------------------------------------------------
-- | Convert a @*.scss@ file into compress CSS.
scssCompiler :: Compiler (Item String)
scssCompiler = toCSS "scss"
scssCompiler = toCSS "sassc"

--------------------------------------------------------------------------------
toCSS :: String -> Compiler (Item String)
toCSS tool = do item <- getResourceString
css <- unixFilter tool options $ itemBody item
makeItem $ compressCss css
where options = ["-s", "--trace"]
where options = [ ]

Завантаження…
Відмінити
Зберегти