mustache-c  1.0
mustache.h
Go to the documentation of this file.
00001 #ifndef MUSTACHE_H
00002 #define MUSTACHE_H
00003 
00006 typedef struct mustache_api_t             mustache_api_t;                
00007 typedef struct mustache_token_t           mustache_token_t;              
00008 typedef struct mustache_token_t           mustache_template_t;           
00009 typedef enum   mustache_token_type_t      mustache_token_type_t;         
00010 typedef struct mustache_token_variable_t  mustache_token_variable_t;     
00011 typedef struct mustache_token_section_t   mustache_token_section_t;      
00012 
00021 typedef uintmax_t (*mustache_api_read)   (mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size);
00022 
00031 typedef uintmax_t (*mustache_api_write)  (mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size);
00032 
00040 typedef uintmax_t (*mustache_api_varget) (mustache_api_t *api, void *userdata, mustache_token_variable_t *token); 
00041 
00049 typedef uintmax_t (*mustache_api_sectget)(mustache_api_t *api, void *userdata, mustache_token_section_t  *token); 
00050 
00057 typedef void      (*mustache_api_error)  (mustache_api_t *api, void *userdata, uintmax_t lineno, char *error); 
00058 
00063 typedef void      (*mustache_api_freedata)(mustache_api_t *api, void *userdata); 
00064 
00066 enum mustache_token_type_t {
00067         TOKEN_TEXT,                             
00068         TOKEN_VARIABLE,                         
00069         TOKEN_SECTION                           
00070 };
00071 
00072 struct mustache_token_variable_t {
00073         char                  *text;            
00074         uintmax_t              text_length;     
00075         void                  *userdata;        
00076 };
00077 
00078 struct mustache_token_section_t {
00079         char                  *name;            
00080         mustache_token_t      *section;         
00081         uintmax_t              inverted;        
00082         void                  *userdata;        
00083 };
00084 
00085 struct mustache_token_t {
00086         mustache_token_type_t  type;            
00087         
00088         union {
00089                 mustache_token_variable_t     token_simple;
00090                 mustache_token_section_t      token_section;
00091         };
00092         
00093         mustache_token_t      *next;            
00094 };
00095 
00096 struct mustache_api_t {
00097         mustache_api_read     read;             
00098         mustache_api_write    write;            
00099         mustache_api_varget   varget;           
00100         mustache_api_sectget  sectget;          
00101         mustache_api_error    error;            
00102         mustache_api_freedata freedata;         
00103 };
00104 
00105 // api
00106 
00113 mustache_template_t * mustache_compile(mustache_api_t *api, void *userdata);
00114 
00122 uintmax_t             mustache_prerender(mustache_api_t *api, void *userdata, mustache_template_t *template);
00123 
00131 uintmax_t             mustache_render (mustache_api_t *api, void *userdata, mustache_template_t *template);
00132 
00136 void                  mustache_free   (mustache_api_t *api, mustache_template_t *template);
00137 
00138 // helpers (build with --enable-helpers, default)
00139 
00141 typedef struct mustache_str_ctx {
00142         char                  *string;       
00143         
00144         uintmax_t              offset;       
00145 } mustache_str_ctx;
00146 
00147 uintmax_t             mustache_std_strread  (mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size); 
00148 uintmax_t             mustache_std_strwrite (mustache_api_t *api, void *userdata, char *buffer, uintmax_t buffer_size); 
00149 
00150 // debug api (build with --enable-debug, not default)
00151 void                  mustache_dump   (mustache_template_t *template); 
00152 
00153 #endif