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

Need to support real template usage #7

Closed edyu closed 1 year ago

edyu commented 1 year ago

Let me give you an example:

  <div>
    {% if "name" === "blahblah" %}
    <div>
      <input type="text" name="name" value={{name}}>
    </div>
    {% end %}
  </div>

if

init[name] == "blahblah"
should render to

  <div>
    {% if "name" === "blahblah" %}
    <div>
      <input type="text" name="name" value="blahblah">
    </div>
    {% end %}
  </div>

and if not then it should render to

  <div>
  </div>
edyu commented 1 year ago

if you can make ``` ``` to work instead of {% %} that's fine but whatever works it needs to support this.

MommaWatasu commented 1 year ago

I made this package for my small project, so I didn’t mean to make a perfect template engine. But, I’ll try to make this package more useful because there is other people who use it.

I think it’ll take at least one day, please wait.

edyu commented 1 year ago

I understand. 👍 You don't have to support {% %} or {{ }} but to make a template you do need some way to allowing {% if xxx=xxx %} something using {{ xxx }} {% end %}. Otherwise, the use case of template language is very limited.

MommaWatasu commented 1 year ago

I finish implementing basic template usage(like {%%}). documentation hasn't been updated, but the syntax is simple. When the template is

#HTML Template File
<html>
    <head><title>MyPage</title></head>
    <body>
        {% if name=="julia" %}
        The current time is <strong>
    using Dates
    now()
    ```
    </strong>
    {% end %}
    {% for i in 1 : 10 %}
    Hello Julia
    {% end %}
</body>

the output will be(`init=Dict("name"=>"julia")`)

HTML Template File

MyPage The current time is 2023-05-03T23:02:59.753 Hello Julia Hello Julia Hello Julia Hello Julia Hello Julia Hello Julia Hello Julia Hello Julia Hello Julia Hello Julia

As you can see, I can't do things like removing extra spaces yet. Moreover, I've already found the fatal bug that variables don't work properly in for statement.
But, don't worry, solution for these problems has already been found and I'll fix when I have a enough time.
I'll temporarily release if the PR in General repository is merged.
MommaWatasu commented 1 year ago

I fixed bugs and made docs. please check the docs.

edyu commented 1 year ago

Are you going to release the new version? The current released version in the registry is still v0.1.3.

edyu commented 1 year ago

It looks like your new username is merged. Please release this.

edyu commented 1 year ago

Don't forget to update your new version to v0.1.4 or v.0.2.0 or whatever.

MommaWatasu commented 1 year ago

I think support for real template usage has done. If you have more idea to improve this package, please open a new issue.