MommaWatasu / OteraEngine.jl

This package is a template engine for Julia Lang.
https://mommawatasu.github.io/OteraEngine.jl/stable
MIT License
20 stars 4 forks source link

Can't print loop to template #16

Closed Sinfaen closed 1 year ago

Sinfaen commented 1 year ago

Hello, I'm testing out integrating this package into what I'm working on. I looked at the introduction and managed to insert a variable into a template (base_name). However, I tried inserting a loop after it and ran into an error

Template:

extern crate ndarray;
extern crate num_complex;
use ndarray::Array;

// {{base_name}}
{% for i in 1:10 %}
// {{i}}
{% end %}

Code

        templ = OteraEngine.Template(infilepath)
        init = Dict("base_name" => ctxt.name)
        template_output = templ(tmp_init = init)

where infilepath is a filepath to my template and base_name == "all_data_types"

My error:

ERROR: LoadError: BoundsError: attempt to access 126-codeunit String at index [127]
Stacktrace:
 [1] checkbounds
   @ ./strings/basic.jl:216 [inlined]
 [2] codeunit
   @ ./strings/string.jl:106 [inlined]
 [3] getindex
   @ ./strings/string.jl:227 [inlined]
 [4] parse_template(txt::String, config::OteraEngine.ParserConfig)
   @ OteraEngine ~/.julia/packages/OteraEngine/v7eVd/src/parser.jl:68
 [5] OteraEngine.Template(txt::String; path::Bool, config_path::String, config::Dict{String, String})
   @ OteraEngine ~/.julia/packages/OteraEngine/v7eVd/src/template.jl:54
 [6] Template
   @ ~/.julia/packages/OteraEngine/v7eVd/src/template.jl:31 [inlined]
....

this is Julia 1.8.5. OteraEngine 0.2.3, uuid == b2d7f28f-acd6-4007-8b26-bc27716e5513. I am calling this code in a larger project.

How do I even begin to debug something like this?

Sinfaen commented 1 year ago

I also see changes to the project environment happening every once in a while. not sure if that's intended

MommaWatasu commented 1 year ago

Thank you for the report. Changing project environment is intended(it is necessary when you want to use some libraries). When I find something about this bug, I’ll let you know.

MommaWatasu commented 1 year ago

I found and fixed the bug. So, I'll release the next minor release soon and let you know.

MommaWatasu commented 1 year ago

@Sinfaen I released the new version! If you have any problem with the new version, Please report again.