From 843d57b03549ed0481e6a4e39a1fdb0fa3311929 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 30 Dec 2017 02:40:44 -0500 Subject: Added more docmentation Added some more documentation, and removed some extranious prints --- README.md | 28 ++++++++++++++++++++++++++++ ctemplates.c | 12 ++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c0deebb..03bef80 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,34 @@ Adds a varlist that should be used one iteration through the loop 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 + + + +Substitutes a variable, with an optional default value. + +Prints the variable named "variable\_name" in it's place, if no variable named "variable\_name" is found, the default printed. If there is not variable name, and no default value, an error is logged, and it is expanded to an empty string. (If you need to have nothing printed when the variable does not exist, you should use `default=""` to keep the error log clean. + + + : + + : + + : + + +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`. + + + : + + +Loop statements, I bet you can't figure out what this does. + +Loops through a loop named "loop\_name", each iteration through the loop, only the varlist added to the loop is visible. That is, no other varlist, even the parent varlist, is visible while inside the loop. +
## Examples diff --git a/ctemplates.c b/ctemplates.c index faf4334..dd981ac 100644 --- a/ctemplates.c +++ b/ctemplates.c @@ -680,10 +680,10 @@ parse_variable(struct TMPL_token* head, struct TMPL_buf* errbuf){ int attribs_length = head->length - TAG_VAR_LENGTH; int in_name = kmp(start_of_attribs,attribs_length,ATTRIBUTE_VARNAME,ATTRIBUTE_VARNAME_LENGTH); int in_default = kmp(start_of_attribs,attribs_length,ATTRIBUTE_DEFAULT,ATTRIBUTE_DEFAULT_LENGTH); - if(in_name == -1 && DEBUGGING){ - char buf[ERR_MSG_LEN]; - snprintf(buf,ERR_MSG_LEN,"Parsing error: Could not find name=\"name\" near %s\n",head->start); - bputs(errbuf,buf); + if(in_name == -1){ + bputs(errbuf,"Parsing error: Could not find \"name\" field in variable near"); + bputsn(errbuf,head->start,ERR_MSG_LEN); + bputs(errbuf,"\n"); } if(in_name >= 0){ char* start_of_name = start_of_attribs + in_name + ATTRIBUTE_VARNAME_LENGTH; @@ -830,10 +830,10 @@ compile(char* tmplstr){ ret->out = alloc_tmpl_buf(); ret->errout = alloc_tmpl_buf(); struct TMPL_token* tokens = TMPL_tokenize(tmplstr,slen); - print_tokens(tokens); struct TMPL_tagnode* ast = parse(tokens,ret->errout); - print_ast(ast); if(ast == NULL){ + //size_t dummy; + //printf("error: %s\n",bstringify(ret->errout,&dummy)); }else{ ret->roottag = ast; } -- cgit v1.2.3-70-g09d2