lapis
lapis copied to clipboard
views_prefix not working?
From the documentation, it says that you can specify a prefix for loading views...but this isn't working for me.
Does it change how it works with a sub-application? From the error output, it seems to not be doing anything...
Can you paste your example code?
Main app:
lapis = require "lapis"
class extends lapis.Application
@include "users/users"
users/users.moon:
lapis = require "lapis"
class extends lapis.Application
@path: "/users"
@name: "user_"
views_prefix: "users.views"
[admin: "/admin"]: =>
render: true
And there is a widget at users/views/admin.moon.
I also tried with @views_prefix since I believed the lack of @ to be a documentation error, but that does not work either.
views_prefix: "users.views"
This is going to search admin.moon in folder views/users/views
@CriztianiX not quite, it should work as @Guard13007 intended: https://github.com/leafo/lapis/blob/master/lapis/request.moon#L76
The problem is that views_prefix doesn't work when specified in a sub application. It would only use the views prefix on the parent application. (probably would be nice to have, but the implementation would require a bit of refactoring so I've held off)
What I've done in the past is use hello. as the @name in the sub application, this will prefix route name with hello.. This has two effects: @url_for "hello.world" is used to generate a URL, and the module path is views.hello.world when using render: true.
Because of the dot you now get directory based organization in your views.
You can see an example of this on the streak.club admin panel: https://github.com/leafo/streak.club/blob/master/applications/admin.moon#L15 https://github.com/leafo/streak.club/tree/master/views/admin
That wouldn't work for what I'm trying to do, because I'm basically taking the whole users portion of my app and making it a submodule. I'm definitely going to have to rethink it though, because the convenience it was supposed to offer isn't working as well as I would've hoped. >.>
Ah, I see what you're saying. There currently isn't a way to do that then using return: true