-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
Avoid code repetition in templates filters #212
Comments
I just noticed that we have the same situation with |
That's a great catch. I think we should probably attack #214 first. This way we could implement hooks as packages and filters as packages. Otherwise, we'll bloat the generator. What do you think? |
At the moment filters registration works this way that https://github.com/asyncapi/generator/blob/master/lib/generator.js#L331 walks over all files from There is basically no other option for generic filters than putting them in one library and publish to npm as Open questions:
Any thoughts? |
Hi, i'm from Java world and since Java 9 we split everything onto small packages :) which are depended/reused by other packages picture. Another example could be Apache Commons where they split libraries by purposes. |
I think they should be separated. Even each hook and each filter should be a separate package (not necessarily a separate repo). If we see useful groups of filters or hooks, we can maintain another package that would be a sum of them, like stdlib in C or Babel presets. |
markdown-template PR -> asyncapi/markdown-template#11 |
🎉 This issue has been resolved in version 0.41.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description:
Templating in the generator is based on Nunjucks. One of its features is
filters
that allow you to apply custom functions on variables https://mozilla.github.io/nunjucks/templating.html#filters.Generic filters/functions should be abstracted to one common location and shared with other filters. There is no specific proposal on how to do it, it can be just a part of the generator but in one common place, specific filters should stay in current locations.
We also need to take into account users that do not use existing templates located in repository but instead, they keep them privately. We need to have a good solution here, that will allow these users to easily import generic filters to their templates if they want, so they can clean up their filters.
Reason:
The current issue is that those filters are not shared but every template have own filters, even the basic ones.
Example: a
log
function is duplicated here https://github.com/asyncapi/generator/blob/master/templates/html/.filters/all.js#L116 and https://github.com/asyncapi/generator/blob/master/templates/markdown/.filters/all.js#L3.The text was updated successfully, but these errors were encountered: