minilight-0.4.2: A SDL2-based graphics library, batteries-included.

Safe HaskellNone
LanguageHaskell2010

MiniLight.Loader

Description

The package provides the configuration loader.

An configuration example:

_vars:
  window:
    width: 800
    height: 600
app:
  - name: message-layer
    properties:
      window:
        image: resources/window-base.png
        position:
          x: 0
          y: ${${var:window.height} - ${ref:..size.height}}
        size:
          width: ${var:window.width}
          height: 150

Syntax

_vars

You can define a new variable. Use object syntax under the _vars field.

The variables can be referenced in all siblings and under their siblings to the _vars, in the variable syntax ${var:_path_}.

Expr

In each field, you can specify an expression defined in the loader.

  • ${}: enclose the expr by ${}, to tell the parsers that the field is an expr not a plain string.
  • ${ref:_path_}: specify any path to refer any other value. The path resolution is performed once, not recursively resolved. _path_ consists of field names splitted by a period. Use double dots .. for a parent.
  • ${var:_path_}: specify any path to value defined at the field. _path_ consists of field names splitted by a period.
  • arithmetic operator: addition, subtraction, multiplication and division (+,-,*,/) can also be used in ${}.
Synopsis

Documentation

createComponentBy :: (HasLoaderEnv env, HasLightEnv env, MonadIO m) => Resolver -> Maybe Text -> ComponentConfig -> LightT env m (Either String Component) Source #

Create a component with given resolver.

resolveConfig :: MonadIO m => FilePath -> m (Either Text AppConfig) Source #

Load an config file and return the resolved AppConfig.

loadAppConfig Source #

Arguments

:: (HasLightEnv env, HasLoaderEnv env, MonadIO m, MonadCatch m) 
=> FilePath

Filepath to the yaml file.

-> Resolver

Specify any resolver.

-> LightT env m () 

Load an config file and set in the environment. Calling this function at once, this overrides all values in the environment. This will generate an error log and skip the component if the configuration is invalid. This function also assign unique IDs for each component, using assignUID.

patchAppConfig Source #

Arguments

:: (HasLightEnv env, HasLoaderEnv env, MonadIO m, MonadCatch m) 
=> FilePath

Filepath to the yaml file.

-> Resolver

Specify any resolver.

-> LightT env m () 

Load the config file again and place the newly loaded components. This is used for HCR (hot component replacement). Call loadAppConfig first.

resolve :: Value -> Value Source #

Interpret a JSON value, and unsafely apply fromRight

parseAppConfig :: Value -> Either Text AppConfig Source #

Create AppConfig value from JSON value