jaysylvester / citizen

Node.js MVC web application framework. Includes routing, serving, caching, session management, and other helpful tools.
MIT License
100 stars 7 forks source link

View template reorg #121

Closed jaysylvester closed 6 months ago

jaysylvester commented 6 months ago

Remove requirement of separate folders for view templates and default to /app/patterns/views/[controller].html

If there is a view folder for a given controller, set the default template to /app/patterns/views/[controller]/index.html

Allow the view directive to accept a file name or path:

return {
  view: 'view-name.html'
  // or...
  view: 'dir/view.html' // resolves to /app/patterns/views/dir/view-name.html
}

Allow rendering a view without calling a controller (look for controller, if not found, look for matching view, throw 404 otherwise).

jaysylvester commented 6 months ago

After looking into it, rendering a view without a controller is a terrible idea. Even if a view isn't intended to be publicly accessible, it could be rendered directly if it doesn't have a controller sitting in front of it to receive the request. It also makes routing more confusing. A controller will remain a requirement to intercept a request.

jaysylvester commented 6 months ago

For now at least, I think removing the requirement of putting a lone view within a folder is enough of an improvement. The other ideas have complications and don't feel entirely intuitive.

A controller with a single view can have that view placed directly within /app/patterns/views and default to the controller's name, with alternate views specified using the controller's view directive.

Controllers with multiple views can either have all views directly within /app/patterns/views or make use of the older directory structure (a dedicated folder matching the controller name, the default view also matching the controller name, and alternate views alongside the default view).