package jingoo
Build not checkedInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=120e5a14f6c8dfc43cac76e55af8af11dad2c6d8279c12377391586ad0626cd8
md5=90b16fd2bcf332c664f20dd9837723a1
Description
Added to opam-repository:
README
jingoo
About jingoo
Jingoo is OCaml template engine almost compatible with Jinja2(python template engine).
Install
manual
make
sudo make installopam
opam install jingooDifference between Jinja2 and Jingoo
- i18n features are not supported yet.
- Cause of language difference between ocaml and python, some of built-in filters are different from original one, especially orders of arguments and supported optional arguments etc.
- Single line comment is not supported. Because single '#' is used very much especially in html.
Usage
Simple usage
open Jingoo
(* output from direct string template *)
let result = Jg_template.from_string "{{ msg }}" ~models:[("msg", Jg_types.Tstr "hello, world!")]
(* or output from file template *)
let result2 = Jg_template.from_file "hello.jingoo" ~models:[("msg", Jg_types.Tstr "hello, world!")]Custom filter example
Set your custom filter to filters field of environment.
open Jingoo
let to_mail ?(kwargs=[]) ?(defaults=[]) value =
let id = Jg_runtime.string_of_tvalue value in
let domain = Jg_runtime.string_of_tvalue (Jg_runtime.jg_get_kvalue "domain" kwargs ~defaults) in
Jg_types.Tstr (id ^ "@" ^ domain)
let () =
let result = Jg_template.from_string "{{id | to_mail(domain='gmail.com')}}"
(* set your extension to 'filters' field of environment *)
~env:{Jg_types.std_env with
filters = [
(* CAUTION!: if jingoo <= 1.2.21, use 'Jg_runtime.func_arg1' instead of 'Jg_types.func_arg1_kw' *)
("to_mail", Jg_types.func_arg1_kw (to_mail ~defaults:[
("domain", Jg_types.Tstr "gmail.com");
]));
]
}
~models:[
("id", Jg_types.Tstr "foo")
] in
(* should output 'foo@gmail.com' *)
print_endline resultDynlink filter example
- Write your own filter(
my_ext.mlfor example) and add it byJg_stub.add(namespace asmy_extand func_name asto_md5for example).
open Jingoo
let to_md5 ?(kwargs=[]) ?(defaults=[]) value =
let seed = Jg_runtime.jg_get_kvalue "seed" kwargs ~defaults in
match value, seed with
| Jg_types.Tstr str, Jg_types.Tstr seed ->
Jg_types.Tstr (Digest.to_hex (Digest.string (str ^ seed)))
| _ -> Jg_types.Tnull
let () =
(* CAUTION!: if jingoo <= 1.2.21, use 'Jg_runtime.func_arg1' instead of 'Jg_types.func_arg1_kw' *)
Jg_stub.add_func ~namespace:"my_ext" ~func_name:"to_md5" (Jg_types.func_arg1_kw (to_md5 ~defaults:[
("seed", Jg_types.Tstr "");
]))- Compile it to
my_ext.cmxsby-sharedoption.
ocamlfind ocamlopt -shared -o my_ext.cmxs my_ext.ml- Set
my_ext.cmxstoextensionsfield of environment, and you can use your custom filtermy_ext.to_md5.
open Jingoo
let result = Jg_template.from_string "{{msg | my_ext.to_md5(seed='aaa')}}"
(* set your extension to 'extensions' field *)
~env:{Jg_types.std_env with
extensions = [
"my_ext.cmxs";
]
}
~models:[
("msg", Jg_types.Tstr "foo");
] in
(* should output '3cb988a734183289506ab7738261c827' *)
print_endline resultCheatsheet
See samples directory.
*.jingoo is template example and *.expected is expected string.
Documentation
http://tategakibunko.github.io/jingoo/
Playground
https://sagotch.github.io/try-jingoo/
License
MIT License
Dependencies (7)
Dev Dependencies (1)
-
ounit
with-test & >= "2.0.0"
Optional Dependencies
None
Used by (1)
-
spin
< "0.8.0"
Conflicts
None
Build status
Results of building jingoo with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
This version is not in the latest run; the versions below are.
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure