tomland-1.3.3.3: Bidirectional TOML serialization

Copyright | (c) 2018-2022 Kowainik
License | MPL-2.0
Maintainer | Kowainik <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | None
Language | Haskell2010

Toml.Type.Printer

Description

Contains functions for pretty printing `toml` types.

Since: 0.0.0

Synopsis

- data PrintOptions = PrintOptions {
  - printOptionsSorting :: !(Maybe (Key -> Key -> Ordering))
  - printOptionsIndent :: !Int
  - printOptionsLines :: !Lines
  }
- data Lines
  - = OneLine
  - | MultiLine
- defaultOptions :: PrintOptions
- pretty :: TOML -> Text
- prettyOptions :: PrintOptions -> TOML -> Text
- prettyKey :: Key -> Text

# Documentation

data PrintOptions #

Configures the pretty printer.

Since: 0.5.0

Constructors

PrintOptions |
- Fields printOptionsSorting :: !(Maybe (Key -> Key -> Ordering)) How table keys should be sorted, if at all. Since: 1.1.0.0 printOptionsIndent :: !Int Number of spaces by which to indent. Since: 1.1.0.0 printOptionsLines :: !Lines How to print Array. OneLine:
           foo = [a, b]
  MultiLine:
           foo =
               [ a
               , b
               ]
Default is `OneLine`.

data Lines #

Constructors

OneLine |
MultiLine |

defaultOptions :: PrintOptions #

Default printing options.

1. Sorts all keys and tables by name.
2. Indents with 2 spaces.

Since: 0.5.0

pretty :: TOML -> Text #

Converts `TOML` type into `Text` (using `defaultOptions`).

For example, this

    TOML
        { tomlPairs  = HashMap.fromList
              [("title", AnyValue $ Text "TOML example")]
        , tomlTables = PrefixTree.fromList
              [( "example" <| "owner"
               , mempty
                     { tomlPairs  = HashMap.fromList
                           [("name", AnyValue $ Text Kowainik)]
                     }
               )]
        , tomlTableArrays = mempty
        }

will be translated to this

    title = "TOML Example"

    [example.owner]
      name = "Kowainik"

Since: 0.0.0

prettyOptions :: PrintOptions -> TOML -> Text #

Converts `TOML` type into `Text` using provided `PrintOptions`

Since: 0.5.0

prettyKey :: Key -> Text #

Converts a key to text

Since: 0.0.0