Author:ptrace Comitter:ptrace Date:2026-03-15 10:20:40 UTC

template kind must be now explicitly declared if it's a string or file path

diff --git a/README.md b/README.md index 035b642..b74d9f5 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ A tiny html template 'engine'. It currently supports: ### Example 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,  If you want to know what you else can do with the template syntax,  look at the unit tests & comments in `test/test.jai`.   @@ -31,7 +31,7 @@ HTML template: Code: ```text #import "Basic"; #import "htmltemplate"()(READ_FROM_TEMPLATE_FILE = false); #import "htmltemplate"; main :: () { @@ -50,7 +50,7 @@ main :: () {     success,     html_string,     exit_code,     error_message := generate(queue_action, TEMPLATE);     error_message := generate(queue_action, TEMPLATE, .STRING);     defer {         free(html_string); diff --git a/examples/01_from_readme.jai b/examples/01_from_readme.jai index db5c16e..daf48ad 100644 --- a/examples/01_from_readme.jai +++ b/examples/01_from_readme.jai @@ -1,5 +1,5 @@ #import "Basic"; #import "htmltemplate"()(READ_FROM_TEMPLATE_FILE = false); #import "htmltemplate"(); /** @@ -38,7 +38,7 @@ main :: () {     success,     html_string,     exit_code,     error_message := generate(queue_action, TEMPLATE);     error_message := generate(queue_action, TEMPLATE, .STRING);     defer {         free(html_string); diff --git a/examples/02_with_comments.jai b/examples/02_with_comments.jai index 6cb431b..0c3fe9a 100644 --- a/examples/02_with_comments.jai +++ b/examples/02_with_comments.jai @@ -1,17 +1,14 @@ #import "Basic"; html_template :: #import "htmltemplate"()(READ_FROM_TEMPLATE_FILE = false); html_template :: #import "htmltemplate"; /**     jai 01_with_comments.jai -quiet && ./01_with_comments     jai 02_with_comments.jai -quiet && ./02_with_comments */ /** 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.     Below is a template. This would you 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 @@ -113,15 +110,18 @@ main :: () {     /** 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.         We have to declare if the template if from a raw string or file(path).         In this case we're reading the template from a string, so we pass `.STRING`.         If you omit the very last parameter, like in this case, 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).     exit_code,     // More needed for debugging, consult the `lib.jai` for more information.     error_message  // This returns the exact error message if !success. (You have to free it)     := generate(queue_action, YOUR_TEMPLATE_FILE);     := generate(queue_action, YOUR_TEMPLATE_FILE, .STRING);     defer {         free(html_string); diff --git a/htmltemplate/lib.jai b/htmltemplate/lib.jai index 61b2817..b163274 100644 --- a/htmltemplate/lib.jai +++ b/htmltemplate/lib.jai @@ -32,12 +32,6 @@ #import "Math"; /** READ_FROM_TEMPLATE_FILE: If false, you can pass the template string,     instead of the filepath to the template file.*/ #module_parameters () (READ_FROM_TEMPLATE_FILE := true); Exit_Codes :: enum s32 #specified {     OK :: 0; @@ -56,6 +50,7 @@ Action :: struct { generate :: (     queue_action: [..]Action,     template_fp_or_string: string,     input_kind: enum { STRING; FILE; },     html_fp: string = "" ) -> (success: bool, html: string, exit_code: Exit_Codes, error_message: string) { @@ -68,6 +63,7 @@ generate :: (     line_no = 1;     tokens: [..]Token;     source: string;     queue_replace: [..]Replace_Token;     defer { @@ -75,11 +71,12 @@ generate :: (         array_free(queue_replace);     }     #if READ_FROM_TEMPLATE_FILE {         source := file_acquire(template_fp_or_string);     if #complete input_kind == {     case .STRING;         source = template_fp_or_string;     case .FILE;         source = file_acquire(template_fp_or_string);         return_if_err(.ERR_FILE);     } else {         source := template_fp_or_string;     }     token_success := tokenize(source, *tokens); diff --git a/test/test.jai b/test/test.jai index 8754b14..d07abc5 100644 --- a/test/test.jai +++ b/test/test.jai @@ -1,10 +1,7 @@ #import "Basic"()(     MEMORY_DEBUGGER = MEMORY_DEBUGGER_ENABLED  // Enable it via `jai build.jai - memory` ); #import "htmltemplate"()(     READ_FROM_TEMPLATE_FILE = false  // Consult the lib.jai file ); #import "htmltemplate"; #import "stringpad";  // Not needed for the lib. Only for unit tests @@ -295,7 +292,7 @@ test_case_loop_wrong_overload_1 :: () -> success: bool {     template := "{{ loop:foo_loop: %1 %2 %3 }}";     success, _, exit_code, error_message := generate(         queue_action, template         queue_action, template, .STRING     ,, temp);     if !success { @@ -315,7 +312,7 @@ test_case_loop_wrong_overload_2 :: () -> success: bool {     template := "{{ loop:foo_loop: %1 %2 %3 }}";     success, _, exit_code, error_message := generate(         queue_action, template         queue_action, template, .STRING     ,, temp);     if !success { @@ -335,7 +332,7 @@ test_case_replace_wrong_overload :: () -> success: bool {     template := "{{ :foo: %1 %2 %3 }}";     success, _, exit_code, error_message := generate(         queue_action, template         queue_action, template, .STRING     ,, temp);     if !success { @@ -387,7 +384,7 @@ test_html :: (tc: Test_Case) -> success: bool {     commit(tc.id, tc.values);     success, html_new, exit_code, error_message := generate(         queue_action, tc.template         queue_action, tc.template, .STRING     ,, temp);     dbg("Values:    %", tc.values); @@ -412,7 +409,7 @@ test_success :: (tc: Test_Case) -> success: bool {     commit(tc.id, tc.values);     success, html_new, exit_code, error_message := generate(         queue_action, tc.template         queue_action, tc.template, .STRING     ,, temp);     dbg("Values:   %", tc.values);