-- |-- Module: Hakyll.Web.Sass-- Copyright: (C) 2015 Braden Walters-- License: MIT (see LICENSE file)-- Maintainer: Braden Walters <vc@braden-walters.info>-- Stability: experimental-- Portability: ghcmodule Hakyll.Web.Sass( sassCompiler, sassCompilerWith, renderSass, renderSassWith, selectFileType, sassDefConfig, module Text.Sass.Options) whereimport Control.Monad (join)import Data.Default.Classimport Hakyll.Core.Compilerimport Hakyll.Core.Identifierimport Hakyll.Core.Itemimport System.FilePath (takeExtension)import Text.Sass.Compilationimport Text.Sass.Optionsimport Prelude-- | Compiles a SASS file into CSS. Use the file extension to determine SCSS-- from SASS formatting.sassCompiler :: Compiler (Item String)sassCompiler = getResourceBody >>= renderSass-- | Compiles a SASS file into CSS with options. The file extension will not-- be used to determine SCSS from SASS formatting.sassCompilerWith :: SassOptions -> Compiler (Item String)sassCompilerWith options = getResourceBody >>= renderSassWith options-- | Compiles a SASS file item into CSS. Use the file extension to determine-- SCSS from SASS formatting.renderSass :: Item String -> Compiler (Item String)renderSass item = let extension = (takeExtension . toFilePath . itemIdentifier) item in case selectFileType sassDefConfig extension of Just options -> renderSassWith options item Nothing -> fail "File type must be .scss or .sass."-- | Compiles a SASS file item into CSS with options. The file extension will-- not be used to determine SCSS from SASS formatting.renderSassWith :: SassOptions -> Item String -> Compiler (Item String)renderSassWith options item = let filePath = toFilePath $ itemIdentifier item in join $ unsafeCompiler $ do resultOrErr <- compileFile filePath options case resultOrErr of Left sassError -> errorMessage sassError >>= fail Right result -> return (makeItem result)-- | Use the file extension to determine whether to use indented syntax.selectFileType :: SassOptions -> String -> Maybe SassOptionsselectFileType options ".scss" = Just $ options { sassIsIndentedSyntax = False }selectFileType options ".sass" = Just $ options { sassIsIndentedSyntax = True }selectFileType _ _ = Nothing-- | Default sass configuration.sassDefConfig :: SassOptionssassDefConfig = def