diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2018-12-05 18:42:19 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2018-12-05 18:42:19 -0500 |
| commit | 7d3b0b917cdb93d249dc356db8471fe9e6863424 (patch) | |
| tree | f5544048afa123a8f483e4ef7173235ba2a3e565 | |
| parent | ea5f2d56933d04975ef34b85372a577ad433950f (diff) | |
| download | libctemplates-7d3b0b917cdb93d249dc356db8471fe9e6863424.tar.gz libctemplates-7d3b0b917cdb93d249dc356db8471fe9e6863424.tar.bz2 libctemplates-7d3b0b917cdb93d249dc356db8471fe9e6863424.zip | |
Added more documentation
Added documentation for each function in the include/ctemplates.h file
Also did some spellchecking on the readme.
| -rw-r--r-- | README.md | 22 | ||||
| -rw-r--r-- | include/ctemplates.h | 21 |
2 files changed, 29 insertions, 14 deletions
@@ -4,7 +4,7 @@ If you found this page using a search engine, you may be looking for the original [libctemplate](http://libctemplate.sourceforge.net) by Stephen C. Losen libctemplates is a template expander written for use with HTML. It's goals are -to be simple, versitile, and fast. This library started off as a +to be simple, versatile, and fast. This library started off as a fork of libctemplate, but eventually became a total rewrite. libctemplate, the original, was built primarily for cgi applications. libctemplate was tightly coupled with file streams, while libctemplate**S** renders templates to @@ -12,22 +12,20 @@ strings for use in any application, FastCGI or [Kore](kore.io), for example. If you think libctemplates is missing a feature, feel free to suggest it to [alex@cogarr.net](mailto://alex@cogarr.net), or, even better, write it yourself and send the patch! You can find -instructions on createing and sending git patches [here](http://cogarr.net/source/cgit.cgi/?p=about). +instructions on creating and sending git patches [here](http://cogarr.net/source/cgit.cgi/?p=about). ## Contents 1. [Installation](#Installation) 2. [Usage](#Usage) -3. [Quick refrence](#Quick refernce) +3. [Quick reference](#Quick refernce) 4. [Examples](#Examples) - - <section id="Installation"></section> ## Installation Run the make file. libctemplates should compile on any system with a c99 -complient c compiler. If you are on linux, run +complaint c compiler. If you are on linux, run make; make install @@ -40,7 +38,7 @@ libctemplates.a, for example: gcc main.c -lctemplates <section id="Quick refrence"></section> -## Quick refrence +## Quick reference ### Structs @@ -50,7 +48,7 @@ libctemplates.a, for example: Holds a list of variables to be used when rendering a template loops can be held in a varlist, and varlists can be held in loops. * struct TMPL\_loop - Used to defien things to loop through in a varlist. + Used to define things to loop through in a varlist. ### Functions @@ -94,7 +92,7 @@ Adds a varlist that should be used one iteration through the loop char* TMPL_render(struct TMPL_templates* t, struct TMPL_varlist* vl, size_t* length) -Turns a template and varlist into a string. the returned char\* should NOT be freed. The returned char\* is only valid until TMPL\_render() is called again. If you need it even after TMPL\_render() is called, copy it. The length of the returned string is put into `length` to help in copying. +Turns a template and varlist into a string. The returned char\* should NOT be freed. The returned char\* is only valid until TMPL\_render() is called again. If you need it even after TMPL\_render() is called, copy it. The length of the returned string is put into `length` to help in copying. ### Templating tags @@ -114,7 +112,7 @@ Prints the variable named "variable\_name" in it's place, if no variable named " Branching statements, checks if a variable is equal to a constant value. -Checks if the variable "variable\_name" contains the string "check\_value". There is currently no way to check if two variables are equal. Elseif and Else clauses are optional. All `TMPL_IF` statements must be closed with `TMPL_END`. You can use `TMPL_IF` and `TMPL_ELSEIF` to check for a variable's existance by not specifying a `value` parameter. +Checks if the variable "variable\_name" contains the string "check\_value". There is currently no way to check if two variables are equal. Elseif and Else clauses are optional. All `TMPL_IF` statements must be closed with `TMPL_END`. You can use `TMPL_IF` and `TMPL_ELSEIF` to check for a variable's existence by not specifying a `value` parameter. <TMPL_LOOP name="loop_name"> : @@ -327,7 +325,7 @@ a minifier! Just a template expander! ### Loops Loops are special in libctemplates, loops each have their own namespace, and -only variables that have been added to the namespace are acessable in the loop. +only variables that have been added to the namespace are accessible in the loop. *template.html* @@ -411,7 +409,7 @@ only variables that have been added to the namespace are acessable in the loop. This time through the loop, my variable is theird Done! -<!-- Some styleing, make it pretty! --> +<!-- Some styling, make it pretty! --> <style> body,html{ line-height:1.2; diff --git a/include/ctemplates.h b/include/ctemplates.h index df41085..ca77391 100644 --- a/include/ctemplates.h +++ b/include/ctemplates.h @@ -16,31 +16,48 @@ //Length of error messages #define ERR_MSG_LEN 500 +/* A variable list, holds key-value pairs as (string -> (string | loop)) */ struct TMPL_varlist; +/* A list structure, holds an array of varlists to be looped over*/ struct TMPL_loop; /* Holdes all the data needed for a template*/ struct TMPL_templates; +/* Adds a variable to a variable list under a certain name */ void TMPL_add_var_to_varlist(struct TMPL_varlist* vl, const char* name, const char* value); + +/* Adds a loop to a variable list under a certain name */ void TMPL_add_loop_to_varlist(struct TMPL_varlist* vl, const char* name, struct TMPL_loop* loop); -void TMPL_add_varlist_to_loop(struct TMPL_loop* l, struct TMPL_varlist* vl); +/* Adds a variable list as one of the varlists in a loop */ +void TMPL_add_varlist_to_loop(struct TMPL_loop* l, struct TMPL_varlist* vl); +/* Create a new varlist. If allocation fails, the struct retuned will be NULL */ struct TMPL_varlist* TMPL_alloc_varlist(void); +/* Frees a varlist (and recursively, any loops under it, any varlists under those loops, ect.) */ void TMPL_free_varlist(struct TMPL_varlist* t); +/* Allocate a new template. If allocation fails, the struct retunred will be NULL */ struct TMPL_templates* TMPL_alloc_template(const char* t); +/* Free a template. Do not use the string returned by TMPL_render() the template is freed */ void TMPL_free_template(struct TMPL_templates* t); +/* Create a new loop. If allocation fails, the struct returned will be NULL */ struct TMPL_loop* TMPL_alloc_loop(void); +/* Free a loop. If the loop is added to a varlist, just call free on the varlist +and any loops that have been added to it will automatically be freed.*/ void TMPL_free_loop(struct TMPL_loop* tl); +/* Takes a template and varlist, and collapses it into a string. +If size_p is non-null, the size of the resulting string will be placed in it. +If any errors happened the t->error will be non-zero and the error can be +retreived with TMPL_err(t,&size)*/ char* TMPL_render(struct TMPL_templates* t, struct TMPL_varlist* varlist, size_t* size_p); const char* TMPL_err(struct TMPL_templates* t,size_t* size); -/*A debug function*/ +/* A debug functions */ void print_varlist(struct TMPL_varlist* vl); void print_ast(struct TMPL_templates* root); |
