Skip to content

Commit

Permalink
Determine whether file is SASS or SCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
meoblast001 committed Aug 21, 2015
1 parent 287a921 commit 627875a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hakyll-sass.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: hakyll-sass
version: 0.1.0.0
version: 0.1.0
synopsis: Hakyll SASS compiler over hsass
license: MIT
license-file: LICENSE
Expand Down
20 changes: 16 additions & 4 deletions src/Hakyll/Web/Sass.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ import Hakyll.Core.Compiler
import Hakyll.Core.Item
import System.IO.Unsafe
import Text.Sass.Compilation
import Text.Sass.Options

-- | Compiles a SASS file into CSS.
sassCompiler :: Compiler (Item String)
sassCompiler = do
bodyStr <- itemBody <$> getResourceBody
resultOrErr <- unsafeCompiler (compileString bodyStr def)
case resultOrErr of
Left sassError -> fail (unsafePerformIO $ errorMessage sassError)
Right result -> makeItem result
extension <- getUnderlyingExtension
let mayOptions = selectFileType def extension
case mayOptions of
Just options -> do
resultOrErr <- unsafeCompiler (compileString bodyStr options)
case resultOrErr of
Left sassError -> fail (unsafePerformIO $ errorMessage sassError)
Right result -> makeItem result
Nothing -> fail "File type must be .scss or .sass."

-- | Use the file extension to determine whether to use indented syntax.
selectFileType :: SassOptions -> String -> Maybe SassOptions
selectFileType options ".scss" = Just $ options { sassIsIndentedSyntax = False }
selectFileType options ".sass" = Just $ options { sassIsIndentedSyntax = True }
selectFileType _ _ = Nothing

0 comments on commit 627875a

Please sign in to comment.