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

Feature #298: Views Namespace #300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vikaskandari
Copy link

@vikaskandari vikaskandari commented Aug 11, 2024

Feature Request : #298

i am not sure if code qualiy meets the codebase standards however i did add some comments and try to keep code changes as minimal as possible , i have tested it with bun and seems to work fine , let me know if you got any changes in mind or any issues with code , i did removed the !template.startsWith('@') from code i was not sure what was the use of it although directories can be named with @ prefix so i haven't tested with it otherwise everything works fine.

@vikaskandari vikaskandari changed the title Views namespace feature implimentation #298 Feature #298: Views Namespace Aug 11, 2024
@nebrelbug
Copy link
Collaborator

Unfortunately @ already has a defined usage: for templates that have been programatically defined but don't exist on the filesystem. (See https://eta.js.org/docs/intro/template-syntax#name-resolution-of-partials-and-layouts)

As far as this change goes, I'm not completely closed to the idea but I'm not sure that it adds much advantage over just using local folders. I'd love to hear other users' thoughts or comments.

@vikaskandari
Copy link
Author

Thanks for mentioning the documentation now I get why @ was being ignored in code.
What if we use a different character for namespace like # or $ or something else that is not a valid directory or file name and also not part of template engine

I am really looking forward for this update because i have a project which allows devs upload there own themes and with namespaces I can give them a fake server directory structure instead of giving them actual directory structure also it helps reorganizing files and folders easily without actually editing the templates and there include paths

@nebrelbug
Copy link
Collaborator

@vikaskandari ok, that makes sense! I think you might be able to do that using the method I linked above, actually -- maybe you could give that a try?

@vikaskandari
Copy link
Author

partials and automatic template resolution is cool but it solves 50% of my problem, i acutally need paths that will resolve templates outside the root/main directory and i really don't want to give .../../ in templates and include paths thats why i was suggesting namespaces, i haven't seen this feature in any template engine as far as i know, i hope other devs can see the some more use cases in this.

btw is there any option to provide custom path resolver ? like a interceptor / middleware for path so i can modify the path of each template with my own custom syntax of include for eaxmple if user sets @project/includes/component1 then i can intercept it and resolve the actual path ? this will eliminiate the need of namespaces we can impliment our own custom logic to resolve path.

@nebrelbug
Copy link
Collaborator

nebrelbug commented Aug 14, 2024

@vikaskandari hmm, that makes sense. I'll leave this issue open to gauge interest.

As far as overriding, you should just be able to override readFile and resolvePath on the Eta object.

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

Successfully merging this pull request may close these issues.

3 participants