package yocaml

  1. Overview
  2. Docs
Core engine of the YOCaml Static Site Generator

Install

dune-project
 Dependency

Authors

Maintainers

Sources

yocaml-2.7.0.tbz
sha256=89a74bd5cb37e580e45e4ed3d43b07b2cca5af9ab7f98966c48fe9730dc4af2e
sha512=ae77555570320c28c47d748e75056ccc44bb43cddf6fef70e8b556254fd809d67b915b313bd1833c28581db1fdeefbe34e81d5548744d6ecabe466ee1ef6284c

doc/yocaml/Yocaml/Data/index.html

Module Yocaml.DataSource

Describes an mostly compatible Ezjsonm AST that acts as a generic AST for describing metadata that can be exchanged between source documents and templates. To summarise, source metadata is ultimately projected into a value of type Yocaml.Data.t and data injected into templates is projected from values of type Yocaml.Data.t.

To be generic, you need to provide a module capable of transforming the AST of arbitrary metadata (for example, Yaml) into a value of type Yocaml.Data.t to be used generically.

Types

Sourcetype t = private
  1. | Null
  2. | Bool of bool
  3. | Int of int
  4. | Float of float
  5. | String of string
  6. | List of t list
  7. | Record of (string * t) list
    (*

    Describes the set of possible values for the Data AST.

    *)
Sourcetype ezjsonm = [
  1. | `Null
  2. | `Bool of bool
  3. | `Float of float
  4. | `String of string
  5. | `A of ezjsonm list
  6. | `O of (string * ezjsonm) list
]

Describes type ezjsonm (to be compatible with historical libraries, such as ocaml_yaml).

Creating Data values

Sourceval null : t

null returns the t for null.

Sourceval bool : bool -> t

bool b converts a Boolean into a t.

Sourceval int : int -> t

int i converts an integer into a t.

Sourceval float : float -> t

float f converts a float into a t.

Sourceval string : string -> t

string s converts a string into a t.

Sourceval list : t list -> t

list v converts a list of t into a t.

Generic Data values

Building generic Data values.

Sourceval list_of : ('a -> t) -> 'a list -> t

list f v converts a list of arbitrary values into a t.

Sourceval record : (string * t) list -> t

record fields converts a list of t into a t.

Sourceval option : ('a -> t) -> 'a option -> t

option opt converts an option into a t or null.

Sourceval sum : ('a -> string * t) -> 'a -> t

sum f x convert sum into a t.

Sourceval pair : ('a -> t) -> ('b -> t) -> ('a * 'b) -> t

pair f g (x, y) construct a pair as a t. A pair has the structure {"fst": a, "snd": b}.

Sourceval triple : ('a -> t) -> ('b -> t) -> ('c -> t) -> ('a * 'b * 'c) -> t

triple f g h (x, y, z) is pair f (pair g h) (x, (y, z)). It use pair to define triple.

Sourceval quad : ('a -> t) -> ('b -> t) -> ('c -> t) -> ('d -> t) -> ('a * 'b * 'c * 'd) -> t

quad f g h i (w, x, y, z) is pair f (triple g h) (w, (x, y, z))

Sourceval either : ('a -> t) -> ('b -> t) -> ('a, 'b) Either.t -> t

either f g x construct either as a t. Either has the structure {"constr": "left | right", "value": e}.

Specific Data values

Sourceval path : Path.t -> t

Normalize a Path.

Validating Data values

Sourcemodule Validation : sig ... end

Used to validate data described by type Yocaml.Data.t to build validation pipelines. The aim of this module is to produce combinators for building validation pipelines that support nesting and that can transform any value described by the AST in Data into arbitrary OCaml values.

Conversion signature

Sourcemodule type S = sig ... end

Modules that convert OCaml values into Yocaml.Data.t values.

Using conversion modules

Sourceval into : (module S with type t = 'a) -> 'a -> t

into (module M) v applies M.to_data from the given conversion module M to the OCaml value v, producing a Yocaml.Data.t.

Validation helper types

Sourcetype 'a converter = 'a -> t

'a converter converts a value of type 'a into a t.

Sourcetype ('a, 'b) validator = 'a -> 'b Validation.validated_value

('a, 'b) validator validates a value of type 'a and returns a Yocaml.Data.Validation.validated_value of type 'b.

Sourcetype 'a validable = (t, 'a) validator

'a validable is a validator that takes a value of type t and returns a validated value of type 'a.

Utils

Sourceval equal : t -> t -> bool

Equality between t.

Sourceval pp : Format.formatter -> t -> unit

Pretty-printer for t (mostly used for debugging issue).

Sourceval to_sexp : t -> Sexp.t

to_sexp convert to a Yocaml.Sexp.t.

Sourceval to_ezjsonm : t -> ezjsonm

to_ezjsonm v converts a t into a ezjsonm.

Sourceval from_ezjsonm : ezjsonm -> t

from_ezjsonm v converts a ezjsonm into a t.