packages feed

shakespeare-babel-0.1.0.0: src/Text/Babel.hs

-- | A Shakespearean module for Babel

module Text.Babel
    ( babel
    , babelFile
    , babelFileReload
    , babelSettings
    ) where

import           Language.Haskell.TH.Quote
import           Language.Haskell.TH.Syntax
import           Text.Julius
import           Text.Shakespeare

-- | es2015 compiles down to Javascript
babelSettings :: Q ShakespeareSettings
babelSettings = do
  jsettings <- javascriptSettings
  return $ jsettings { varChar = '#'
                     , preConversion = Just PreConvert
                                       { preConvert = ReadProcess "babel" ["--presets", "es2015"]
                                       , preEscapeIgnoreBalanced = "'\""
                                       , preEscapeIgnoreLine = "//"
                                       , wrapInsertion = Just WrapInsertion
                                                         { wrapInsertionIndent = Nothing
                                                         , wrapInsertionStartBegin = ";(function("
                                                         , wrapInsertionSeparator = ", "
                                                         , wrapInsertionStartClose = "){"
                                                         , wrapInsertionEnd = "})"
                                                         , wrapInsertionAddParens = False
                                                         }}}

-- | Read inline
babel :: QuasiQuoter
babel = QuasiQuoter { quoteExp = \s -> babelSettings >>= \rs -> quoteExp (shakespeare rs) s }

-- | Read in a es2015 file
babelFile :: FilePath -> Q Exp
babelFile fp = do
    rs <- babelSettings
    shakespeareFile rs fp

-- | Read in a es2015 file at develop
babelFileReload :: FilePath -> Q Exp
babelFileReload fp = do
    rs <- babelSettings
    shakespeareFileReload rs fp