Author:ptrace Comitter:ptrace Date:2026-03-15 09:46:38 UTC Merge: bceb4c48a0b522617270db67c4d6a279dc884dbc e0b458ea8416c309ed7b156dcb32ed55c375b615

Merge pull request 'Removed module param that writes generated content into a file, this is now controlled by an optional param in generate(); adapted stuff to the current Jai version; adapted examples' (#2) from feat/html-write-as-optional-param-in-generate-proc into main

Reviewed-on: https://codeberg.org/ptrace/htmltemplate-jai/pulls/2

diff --git a/README.md b/README.md index f66102d..035b642 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A tiny html template 'engine'. It currently supports: If you want an example with more explainations, consult `examples/02_with_comments.jai`.   For more explaination about the module parameters, consult: `htmltemplate/lib.jai`.   And if you want to know what you else can do with the template syntax,  look at the unit tests  & comments in `test/test.jai`.   look at the unit tests & comments in `test/test.jai`.   HTML template: @@ -88,12 +88,9 @@ Output: ``` $ jai -version Version: beta 0.2.024, built on 31 December 2025. Version: beta 0.2.026, built on 21 February 2026. ``` **Note:** You need at least version `0.2.023`,  since it introduced tagged unions there.   ## Usage Put the library into your project-local `modules` dir,  diff --git a/build.jai b/build.jai index 8036650..d2c89ef 100644 --- a/build.jai +++ b/build.jai @@ -71,7 +71,7 @@ build :: () {         return;     }     if args_program_run  run_build_result(w, program_args);     if args_program_run  run_build_result_of_workspace(w, program_args); } build_debug :: (w: Workspace, target_options: *Build_Options) { diff --git a/examples/02_with_comments.jai b/examples/02_with_comments.jai index 715cfd3..6cb431b 100644 --- a/examples/02_with_comments.jai +++ b/examples/02_with_comments.jai @@ -1,9 +1,6 @@ #import "Basic"; html_template :: #import "htmltemplate"()(     READ_FROM_TEMPLATE_FILE = false,     CREATE_HTML_FILE = false ); html_template :: #import "htmltemplate"()(READ_FROM_TEMPLATE_FILE = false); /** @@ -11,17 +8,10 @@ html_template :: #import "htmltemplate"()( */ /** The module paramaters define, if you want to read and write into a file,     or not. The defaults assume, you always want to read from a file, but     writing is optional. Instead it just returns the rendered html code as     string - it always does that, independend of the settings. /** The module paramater defines, if you want to read from a file,     or not. The default assumes, you always want to read from a file.     For this example, I disabled any reading and writing from and to files,     instead I provide a function where you can manually decide, when to     store the result in a file. */ /** This below is the template. This would be read from a file normally, but     Below is a template. This would you read from a file normally, but     this is up to you. */ YOUR_TEMPLATE_FILE :: #string STR_END @@ -122,9 +112,10 @@ main :: () {     ]);     /** Now we can generate the html file. Since we disabled the file write,         we don't have to specify an output path and we can just omit the         last paramater. */     /** Now we can generate the html file.         Note: If you omit the last parameter, like in this case we only provide two               instead of three, it does not write the generated content into a file.     */     success,       // If something went wrong, it's indicated here.     html_string,   // Your output as string. (You have to free it). diff --git a/htmltemplate/lib.jai b/htmltemplate/lib.jai index 714452e..61b2817 100644 --- a/htmltemplate/lib.jai +++ b/htmltemplate/lib.jai @@ -33,12 +33,8 @@ /** READ_FROM_TEMPLATE_FILE: If false, you can pass the template string,     instead of the filepath to the template file.     CREATE_HTML_FILE: If true, it will create the final rendered html file by     the path you provided.     In any case, it still returns a string. */ #module_parameters () (READ_FROM_TEMPLATE_FILE := true, CREATE_HTML_FILE := false);     instead of the filepath to the template file.*/ #module_parameters () (READ_FROM_TEMPLATE_FILE := true); @@ -104,8 +100,10 @@ generate :: (     html_new := template_replace(queue_replace, source);     return_if_err(.ERR_REPLACE);     fw_success := file_write(html_new, html_fp);     return_if_err(.ERR_FILE);     if html_fp {         fw_success := file_write(html_new, html_fp);         return_if_err(.ERR_FILE);     }     return true, html_new, .OK, ""; } @@ -409,8 +407,6 @@ file_acquire :: (fp: string) -> data: string { } file_write :: (data: string, fp: string) {     #if !CREATE_HTML_FILE return;     success := write_entire_file(fp, data);     if !success { diff --git a/test/test.jai b/test/test.jai index 4bcc6ce..8754b14 100644 --- a/test/test.jai +++ b/test/test.jai @@ -2,8 +2,7 @@     MEMORY_DEBUGGER = MEMORY_DEBUGGER_ENABLED  // Enable it via `jai build.jai - memory` ); #import "htmltemplate"()(     READ_FROM_TEMPLATE_FILE = false,    // Consult the lib.jai file     CREATE_HTML_FILE = false            // for more information.     READ_FROM_TEMPLATE_FILE = false  // Consult the lib.jai file ); #import "stringpad";  // Not needed for the lib. Only for unit tests