package jingoo

  1. Overview
  2. Docs
exception SyntaxError of string
type environment = {
  1. autoescape : bool;
    (*

    If true, template variables are auto escaped when output.

    *)
  2. strict_mode : bool;
    (*

    If true, strict type cheking is enabled. If false, some kind of invalid type usages are just ignored. for example, following expression throws exception if strict_mode = true, but is skipped if strict_mode = false.

    {# 3(Tint) is not iterable #}
    {% for item in 3 %}
      {{ item }}
    {% endfor %}
    *)
  3. template_dirs : string list;
    (*

    Template search path list used by {% include %} statements. Jingoo will always search in current directory in last resort.

    *)
  4. filters : (string * tvalue) list;
    (*

    User-defined filters.

    *)
  5. extensions : string list;
    (*

    Path list of shared library modules (.cms or .cmxs files) which are dynamically loaded.

    *)
}

See std_env

and context = {
  1. frame_stack : frame list;
  2. macro_table : (string, macro) Stdlib.Hashtbl.t;
  3. namespace_table : (string, frame) Stdlib.Hashtbl.t;
  4. active_filters : string list;
  5. serialize : bool;
  6. output : tvalue -> unit;
}
and frame = (string, tvalue) Stdlib.Hashtbl.t
and macro =
  1. | Macro of macro_arg_names * macro_defaults * macro_code
and macro_arg_names = string list
and macro_defaults = kwargs
and macro_code = statement list
and tvalue =
  1. | Tnull
  2. | Tint of int
  3. | Tbool of bool
  4. | Tfloat of float
  5. | Tstr of string
  6. | Tobj of (string * tvalue) list
  7. | Thash of (string, tvalue) Stdlib.Hashtbl.t
  8. | Tpat of string -> tvalue
  9. | Tlist of tvalue list
  10. | Tset of tvalue list
  11. | Tfun of ?kwargs:kwargs -> tvalue -> tvalue
  12. | Tarray of tvalue array
  13. | Tlazy of tvalue Stdlib.Lazy.t
  14. | Tvolatile of unit -> tvalue
and kwargs = (string * tvalue) list

Boxing OCaml values

Unboxing OCaml values

Unboxing operations raise Invalid_argument in case of type error.

Helpers for function writing

Notes about some data types

tvalue.Tobj Key/value object using an associative list.

tvalue.Thash Key/value objects using a hash table.

tvalue.Tpat Key/value object using a function to map "key" to value. Faster than tvalue.Tobj and tvalue.Thash, but not iterable nor testable.

tvalue.Tset Tuples

tvalue.Tlazy Lazy values are actually computed only when needed. Useful for recursive some data structure. In the following example, your app would throw a stack overflow without lazyness.

let rec lazy_model n =
  let prev = lazy_model (n - 1) in
  let next = lazy_model (n + 1) in
  let cur = Tint n in
  Tlazy (lazy (Tobj [ ("cur", cur) ; ("prev", prev) ; ("next", next) ]) )

tvalue.Tvolatile You can use volatile values for variables that can not be defined at model's definition time or if it is subject to changes over time on ocaml's side

Function calls

Built-in functions (aka filters) expect the TARGET value to be the LAST argument, in order to be usable with the pipe notation. You are encouraged to do the same while defining your own functions.

{{ x | foo (10,20) }} is equivalent too {{ foo (10,20,x) }}.

Functions support partial application. e.g. {{ list | map (foo (10,20)) }}

There is two kind of arguments: unnamed arguments and keyword arguments.

When defining a keyword argument, label can't be omitted.

You can't use slice(4, [1,2,3,4,5], 0), because you need to explicitly bind 0 with the fill_with label.

A correct usage of the slice function would be slice(4, [1,2,3,4,5], fill_with=0).

Note that kwargs may be defined at any place: slice(4, fill_with=0, [1,2,3,4,5]).

OCaml

Innovation. Community. Security.