aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-12-30 02:40:44 -0500
committerAlexander Pickering <alexandermpickering@gmail.com>2017-12-30 02:40:44 -0500
commit843d57b03549ed0481e6a4e39a1fdb0fa3311929 (patch)
treeadbbd62789a1cce4e70b358301377522afd8dadc
parent9c8bf52be1fe1af8830327c375d644ecfdb5f5c1 (diff)
downloadlibctemplates-843d57b03549ed0481e6a4e39a1fdb0fa3311929.tar.gz
libctemplates-843d57b03549ed0481e6a4e39a1fdb0fa3311929.tar.bz2
libctemplates-843d57b03549ed0481e6a4e39a1fdb0fa3311929.zip
Added more docmentation
Added some more documentation, and removed some extranious prints
-rw-r--r--README.md28
-rw-r--r--ctemplates.c12
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
+
+ <TMPL_VAR name="variable_name" default="default_value">
+
+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.
+
+ <TMPL_IF name="variable_name" value="check_value">
+ :
+ <TMPL_ELSEIF name="variable_name" value="check_value">
+ :
+ <TMPL_ELSE>
+ :
+ <TMPL_END>
+
+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`.
+
+ <TMPL_LOOP name="loop_name">
+ :
+ <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.
+
<section id="Examples"></section>
## 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;
}