Skip to content
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

Includes/template extension #18

Closed
frankier opened this issue Oct 27, 2023 · 8 comments
Closed

Includes/template extension #18

frankier opened this issue Oct 27, 2023 · 8 comments

Comments

@frankier
Copy link
Contributor

frankier commented Oct 27, 2023

Thanks for the package. It looks great and it's amazing it's so small. I think leaning heavily on having complicated stuff done in Julia and mainly working via generating Julia from syntax sugar and not introducing too much additional syntax is the reason for this and something you should stick with.

However, one thing that would be nice however is to have template inclusion, which is quite important for reusability.

In addition, the template extension concept is rather useful for generating nested formats like html, however this could get more complicated. Perhaps there is a nice way to just implement this on generating functions with default keyword arguments for base templates and having subtemplates call them with all generated block?

@MommaWatasu
Copy link
Owner

Hi @frankier ,

Sorry for the delayed response, and thanks for your suggestion. I'm not sure what syntax do you want me to add, but I guess you mean {% extends %}, {% include %} and {% block %}.
I'll implement this new syntax, and inform you know when I finish it.
If these syntax aren't what you expected, please let me know.

@frankier
Copy link
Contributor Author

Yes that would be great!

@MommaWatasu
Copy link
Owner

Hi @frankier ,

I finished implement extends and include, and they are available in new v0.2.7.
Please look at the document for details.

@frankier
Copy link
Contributor Author

frankier commented Nov 7, 2023

Hi. This looks great! Sorry for being a bit slow getting back.

One wrinkle is that when using this with Oxygen.jl, I have a layout like so:

/entrypoint.jl
/src/myfile.jl
/templates/mytemplate.html
/templates/base.html

My PWD might be anything, but often the parent of entrypoint.jl. When I extend base.html in mytemplate.html, it won't be found since Julia will look in my PWD. There are two possible solutions here:

  1. Simple solution: Try opening the file relative to its parent. Downside, it's possible for templates to be passed in as strings.
  2. Flexible solution: Allow the user to pass a custom callback which is used to get the contents of the template. Then an integrating framework such as Oxygen.jl is responsible for making sure things are resolved relative to either the parent template or the templates directory.

@MommaWatasu
Copy link
Owner

MommaWatasu commented Nov 7, 2023

Thanks for your suggestion. I think that the best solution is to create dir option in ParserConfig.
This option is initialized with either pwd() or parent directory of the given template file. But if you want to use other directory as template folder, you can change dir option with config or config_path argument.
I’ll implement this function.

@MommaWatasu
Copy link
Owner

Hi @frankier

I released new version 0.3.0 a while ago.
In new version, the syntax is much more similar to Jinja2 and many functions are implemented.
Please look at the docs for detail.

@frankier
Copy link
Contributor Author

Thanks for letting me know. I'll check it out!

@MommaWatasu
Copy link
Owner

This issue has already been solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants