mustache-c  1.0
Data Structures | Typedefs | Enumerations | Functions
mustache.h File Reference

Go to the source code of this file.

Data Structures

struct  mustache_token_variable_t
struct  mustache_token_section_t
struct  mustache_token_t
struct  mustache_api_t
struct  mustache_str_ctx

Typedefs

typedef struct mustache_api_t mustache_api_t
 Api typedef.
typedef struct mustache_token_t mustache_token_t
 Token typedef.
typedef struct mustache_token_t mustache_template_t
 Template typedef.
typedef enum mustache_token_type_t mustache_token_type_t
 Token type typedef.
typedef struct
mustache_token_variable_t 
mustache_token_variable_t
 Token variable typedef.
typedef struct
mustache_token_section_t 
mustache_token_section_t
 Token section typedef.
typedef uintmax_t(* mustache_api_read )(mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size)
typedef uintmax_t(* mustache_api_write )(mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size)
typedef uintmax_t(* mustache_api_varget )(mustache_api_t *api, void *userdata, mustache_token_variable_t *token)
typedef uintmax_t(* mustache_api_sectget )(mustache_api_t *api, void *userdata, mustache_token_section_t *token)
typedef void(* mustache_api_error )(mustache_api_t *api, void *userdata, uintmax_t lineno, char *error)
typedef void(* mustache_api_freedata )(mustache_api_t *api, void *userdata)
typedef struct mustache_str_ctx mustache_str_ctx

Enumerations

enum  mustache_token_type_t { TOKEN_TEXT, TOKEN_VARIABLE, TOKEN_SECTION }

Functions

mustache_template_tmustache_compile (mustache_api_t *api, void *userdata)
uintmax_t mustache_prerender (mustache_api_t *api, void *userdata, mustache_template_t *template)
uintmax_t mustache_render (mustache_api_t *api, void *userdata, mustache_template_t *template)
void mustache_free (mustache_api_t *api, mustache_template_t *template)
uintmax_t mustache_std_strread (mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size)
 Helper api function to read from plain C string.
uintmax_t mustache_std_strwrite (mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size)
 Helper api function to write to plain C string.
void mustache_dump (mustache_template_t *template)
 Debug dump template.

Detailed Description


Typedef Documentation

typedef void(* mustache_api_error)(mustache_api_t *api, void *userdata, uintmax_t lineno, char *error)

Errors callback. Used only on compilation stage.

Parameters:
apiCurrent api set
userdataUserdata passed to mustache_compile function
linenoLine number on which error occured
errorError description
typedef void(* mustache_api_freedata)(mustache_api_t *api, void *userdata)

Free userdata callback.

Parameters:
apiCurrent api set
userdataUserdata saved in tokens
typedef uintmax_t(* mustache_api_read)(mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size)

Read callback, used only on compilation stage. Write your data in buffer and return number of bytes read.

Parameters:
apiCurrent api set, probably not used in this callback
userdataUserdata passed to mustache_compile function
bufferOutput buffer
buffer_sizeOutput buffer size
Return values:
0No more data (EOF)
>0Successful call, number indicate number of bytes read
typedef uintmax_t(* mustache_api_sectget)(mustache_api_t *api, void *userdata, mustache_token_section_t *token)

Get section callback. User call iterativly render routines on section, or do nothing.

Parameters:
apiCurrent api set
userdataUserdata passed to mustache_render function
tokenMustache section token
Return values:
0Error occured
>0Successful call
typedef uintmax_t(* mustache_api_varget)(mustache_api_t *api, void *userdata, mustache_token_variable_t *token)

Get variable callback. User call ->write api to dump variable value to output, or do nothing.

Parameters:
apiCurrent api set
userdataUserdata passed to mustache_render function
tokenMustache variable token
Return values:
0Error occured
>0Successful call
typedef uintmax_t(* mustache_api_write)(mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size)

Write callback. Save input data in desired place.

Parameters:
apiCurrent api set
userdataUserdata passed to mustache_render function
bufferInput buffer
buffer_sizeInput buffer size
Return values:
0Error occured
>0Successful call

Helper context


Enumeration Type Documentation

Token type enum

Enumerator:
TOKEN_TEXT 

Type text.

TOKEN_VARIABLE 

Type variable.

TOKEN_SECTION 

Type section.


Function Documentation

mustache_template_t* mustache_compile ( mustache_api_t api,
void *  userdata 
)

Compile template

Parameters:
apiCurrent api set
userdataUserdata passed to ->read function
Return values:
NULLError occured
!NULLSuccessful call
void mustache_free ( mustache_api_t api,
mustache_template_t template 
)

Free template

Parameters:
templateTemplate to free
uintmax_t mustache_prerender ( mustache_api_t api,
void *  userdata,
mustache_template_t template 
)

Prerender template. You will receive ->varget and ->sectget callbacks only, precompute some info if needed and save to userdata field.

Parameters:
apiCurrent api set
userdataUserdata passed to ->read function
templateTemplate to use for rendering
Return values:
0Error occured
>0Successful call
uintmax_t mustache_render ( mustache_api_t api,
void *  userdata,
mustache_template_t template 
)

Render template

Parameters:
apiCurrent api set
userdataUserdata passed to ->write and other functions
templateTemplate to use for rendering
Return values:
0Error occured
>0Successful call