-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tutorial Example is not working #17
Comments
Thank you for your report. This issue was caused by the difference between Linux and WIndows. |
Hi @MommaWatasu, Thanks for taking a look at this is issue. I've pulled down your latest changes and am still running into some issues. Thankfully, no error is getting thrown but the output of the code block isn't getting interpolated inside the final string. Am I calling anything incorrectly? Thanks! Here's the output:
And here is the code: module Main
using OteraEngine
txt = "```using Dates; now()```. Hello {{ usr }}!"
tmp = Template(txt, path = false)
init = Dict("usr"=>"OteraEngine")
output = tmp(tmp_init = init)
println(output)
end |
Hi @MommaWatasu, Just wanted to bring up a couple more things I noticed when writing my own unit tests. 1.) Test number 4 has inconsistent spacing. There's additional tabs inside your own internal tests, specifically the closing body tag has the wrong level of indentation. This indicates that there is additional spacing getting implicitly added to the template files This seems to be consistent across both our tests. Below is an example of how the test fails if the body tags are aligned properly, the test only passes when an additional level of indentation is applied to the closing body tag. function otera(template::String; kwargs...)
tmp = Template(template, path=isfile(template); kwargs...)
return function(data::AbstractDict; template_kwargs...)
tmp(tmp_init=data; template_kwargs...)
end
end
function clean_output(result::String)
# handles running on windows with carrige returns
if occursin("\r\n", result)
return replace(result, "\r\n" =>"\n")
else
return result
end
end
function remove_trailing_newline(s::String)::String
if !isempty(s) && last(s) == '\n'
return s[1:end-1]
end
return s
end
@testset "otera() from string" begin
template = """
<html>
<head><title>MyPage</title></head>
<body>
{% set name = "watasu" %}
{% if name=="watasu" %}
your name is {{ name }}, right?
{% end %}
{% for i in 1 : 10 %}
Hello {{i}}
{% end %}
{% with age = 15 %}
and your age is {{ age }}.
{% end %}
</body>
</html>
""" |> remove_trailing_newline
expected_output = """
<html>
<head><title>MyPage</title></head>
<body>
your name is watasu, right?
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8
Hello 9
Hello 10
and your age is 15.
</body>
</html>
""" |> remove_trailing_newline
data = Dict("name" => "watasu")
render = otera(template)
result = render(data) |> clean_output
@test result == expected_output
end I don't want all these requests to come off as pedantic, I'm currently evaluating which templating engines I may want to integrate into Oxygen.jl and your package is one of them. I'm a fan of this package and want to see if we can get it to a place where I can add support for it. |
Hi @ndortega . I fixed the bugs you reported and released the v0.2.6. So now the jl code blocks work properly, and also the indentation is correct. And I will appreciate it if you would inform me the result that you test this. |
Hi @MommaWatasu , Thanks for your changes, they resolved the issue I was facing. On a related note, I've created the package extension for this package and wanted to get your input on the naming of the top-level function that exposes your library. Right now it's just called
Here's an example of it in use: @testset "otera() combined tmp_init & jl_init test" begin
template = "```parse(Int, value) ^ 3```. Hello {{name}}!"
expected_output = "27. Hello World!"
render = otera(template)
result = render(tmp_init=Dict("name" => "World"), jl_init=Dict("value" => "3"))
end An below is the where it's defined |
Hi @ndortega, I’m glad that OteraEngine is used in your Oxygen. The only thing which I want you to do is to put the link of docs for OteraEngine in your document of |
Hi @MommaWatasu ,
I'm trying to run the following example from your docs but am running into an error. Here are my specs
OS: windows 10
language version: julia 1.6.7
Here is the error logs
The text was updated successfully, but these errors were encountered: