2{-# LANGUAGE RankNTypes #-}
3module Data.Yaml.Include (decodeFile, decodeFileEither) where
5#if !MIN_VERSION_directory(1, 2, 3)
6import Control.Exception (handleJust)
7import Control.Monad (guard)
8import System.IO.Error (ioeGetFileName, ioeGetLocation, isDoesNotExistError)
11import Control.Exception (throwIO)
12import Control.Monad (when)
13import Control.Monad.IO.Class (liftIO)
14import Control.Monad.Trans.Resource (MonadResource)
15import Data.Aeson (FromJSON)
17import qualified Data.Conduit.List as CL
18import Data.Text (unpack)
19import Data.Text.Encoding (decodeUtf8)
20import System.Directory
23import Data.Yaml.Internal (ParseException(..), decodeHelper_, decodeHelper)
24import Text.Libyaml hiding (decodeFile)
25import qualified Text.Libyaml as Y
30 -> ConduitM i Event m ()
33 go :: MonadResource m => [FilePath] -> FilePath -> ConduitM i Event m ()
35 cfp <- liftIO $ handleNotFound $ canonicalizePath fp
36 when (cfp `elem` seen) $ do
37 liftIO $ throwIO CyclicIncludes
38 Y.decodeFile cfp .| do
39 awaitForever $ \event -> case event of
40 EventScalar f (UriTag "!include") _ _ -> do
41 let includeFile = takeDirectory cfp </> unpack (decodeUtf8 f)
42 go (cfp : seen) includeFile .| CL.filter (`notElem` irrelevantEvents)
45 irrelevantEvents = [EventStreamStart, EventDocumentStart, EventDocumentEnd, EventStreamEnd]
47#if !MIN_VERSION_directory(1, 2, 3)
48 handleNotFound = handleJust
50 guard (isDoesNotExistError e)
51 guard (ioeGetLocation e == "canonicalizePath")
53 (throwIO . YamlException . ("Yaml file not found: " ++))
58-- | Like `Data.Yaml.decodeFile` but with support for relative and absolute
61-- The syntax for includes follows the form:
63-- > somekey: !include ./somefile.yaml
68decodeFile fp = decodeHelper (eventsFromFile fp) >>= either throwIO (return . either (const Nothing) id)
70-- | Like `Data.Yaml.decodeFileEither` but with support for relative and
73-- The syntax for includes follows the form:
75-- > somekey: !include ./somefile.yaml
79 -> IO (Either ParseException a)
80decodeFileEither = decodeHelper_ . eventsFromFile
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list