Main functions
List of functions in the src folder.
- src.octache(varargin)
Renders mustache templates
USAGE:
output = octache(path_to_file_to_render, ... 'data', path_data_JSON, ... 'partials_path', pwd, ... 'partials_ext', 'mustache', ... 'l_del', '{{', ... 'r_del', '}}', ... 'warn', true, ... 'keep', true);
- Parameters:
template (
path or char) – The file or string to renderpartials_path (
path) – The directory where your partials reside. Default ispwd.data (
path) – The json data file or an equivalent structurepartials_ext (
(1 x n) char) – The extension for your mustache partials,mustacheby defaultleft_delim (
(1 x n) char) – The default left delimiter,{{by defaultright_delim (
(1 x n) char) – The default right delimiter,}}by defaultwarn (
boolean) – Print a warning for each undefined template key encounteredkeep (
boolean) – Keep unreplaced tags when a template substitution isn’t found in the data
EXAMPLE 1:
output = octache('"Hello {{value}}! {{who}}"', ... 'data', struct('value', 'world', ... 'who', 'I am Octache'))
Copyright 2022 Remi Gau
- src.renderer(varargin)
Render a mustache template with a data scope and partial capability.
USAGE:
output = renderer(template, ... 'data', data, ... 'partials_path', pwd, ... 'partials_ext', 'mustache', ... 'scopes', {}, ... 'l_del', '{{', ... 'r_del', '}}', ... 'padding', '', ... 'partials_dict', struct([]), ... 'warn', true, ... 'keep', true);
- Parameters:
template (
path or char or a (n X 2) cell) – the path to a mustache file, a string or a cell of tokens to renderdata (
structure or char) – The content of a json data file or a stringpath (
path) – The path where your partials reside. Default ispwd.ext (
(1 x n) char) – The extension for your mustache partials,mustacheby defaultscopes (
cell) – A stash organized as a cell of structure thatget_keywill look through. Default:{}.l_del (
(1 x n) char) – The default left delimiter,{{by defaultr_del (
(1 x n) char) – The default right delimiter,}}by defaultpadding (
(1 x n) char) – This is for padding partials, and shouldn’t be used (but can be if you really want to)partials_dict (
structure) – Will be search for partials before the filesystem is.struct('include', 'foo')is the same as a file calledinclude.mustache. Defaults:struct([]).warn (
boolean) – Print a warning for each undefined template key encounteredkeep (
boolean) – Keep unreplaced tags when a template substitution isn’t found in the data
- Returns:
- output:
(char) A string containing the rendered template.
EXAMPLE 1:
output = renderer('"Hello {{value}}! {{>who}}"', ... 'data', struct('value', 'world'), ... 'partials_dict', struct('who', 'I am Octache'))
EXAMPLE 2:
Given the file structure:
|- main.ms |- main.m |__ partials |- part.ms
then main.m would make the following call:
output = renderer(fullefile(pwd, 'main.ms'), ... 'data', struct('value', 'world'), ... 'partials_path', fullefile(pwd, 'partials'), ... 'partials_ext', 'ms', ... 'scopes', {}, ... 'warn', true, ... 'keep', true)
Copyright 2022 Remi Gau
- src.tokenize(varargin)
Tokenizes a mustache template in a generator fashion, using file-like objects. It also accepts a string containing the template.
USAGE:
tokens = tokenize(template, 'l_del', '{{', 'r_del', '}}')
Arguments:
- Parameters:
template (
path or char) – the path to a mustache file or a string to renderl_del (
(1 x n) char) – The default left delimiter,{{by defaultr_del (
(1 x n) char) – The default right delimiter,}}by default
- Returns:
- tokens:
A n x 2 cell of mustache tags in the form
{tag_type, tag_key}
Where
tag_typeis one of:literalsectioninverted sectionendpartialno escapeset delimiter
And
tag_keyis either the key or in the case of a literal tag, the literal itself.Copyright 2022 Remi Gau