Tutorial

Installation

OteraEngine can be installed using the Julia package manager. From the Julia REPL, type ] to enter the Pkg REPL mode and run.

pkg > add OteraEngine

Usage

Acutually, this package has only two structure and function, but these are very powerful because of Metaprogramming function of Julia.

Main.OteraEngine.TemplateType
Template(html::String; path::Bool=true)

This is the only structure and function of this package. This structure has 2 parameter,

  • html is the path to the HTML file or HTML of String type.
  • path determines whether the parameter html represents the file path. The default value is true.

HTML

You can write the code of Template in JuliaLang, and just write the variables you want to output to a HTML at the end of the code. The code needs to be enclosed by ```.

For exmaple, this HTML work:

<html>
    <head><title>OteraEngine Test</title></head>
    <body>
        Hello, `usr`!
    </body>
</html>

Rendering

After you create a Template, you just have to execute the codes! For this, you use the Function-like Object of Template structure. tmp(; init::Expr) variables are initialized by init(init is the parameter for Function-like Object). init must be Exprtype. If you don't pass the init, the initialization won't be done. Please see the example below.

Example

tmp = Template("./test1.html") #The last HTML code
init = Dict("usr"=>"OteraEngine")
result = tmp(init)
println(result)
source

Specifically, you can also do this.

#HTML Template File
<html>
    <head><title>MyPage</title></head>
    <body>
        The current time is <strong>
        `
        using Dates
        now()
        `
        </strong>
    </body>
</html>
#Julia code
using OteraEngine

tmp = Template("./time.html") #The last HTML
println(tmp())
#The current time comes in the last HTML code intead of the Julia code and returns it.