the-moisrex / webpp

C++ web framework | web development can be done with C++ as well.
https://t.me/webpp
MIT License
129 stars 9 forks source link

view support #88

Open the-moisrex opened 2 years ago

the-moisrex commented 2 years ago

Adding initial ctx.view("file.mustache") support.

View Manager Features:

Possible Views:

the-moisrex commented 2 years ago

Caching

We need to finish caching system (#91) before we can start implementing a good view system.

lru_cache with memory_gate seems a good choice for caching parsed data.

possible implementations:

  1. Pass the cache from above,
  2. Create the cache inside the view-manager.

Either way, the lru_cache requires a bit of configuration, so we're not gonna let the user configure this by default but we do want them to be able to.

the-moisrex commented 2 years ago

Data Conversion

Where should the data conversion happen?

  1. inside view
  2. inside view manager
  3. inside view manager but customized for that specific view
  4. Inside view manager and pass the view manager to the view
  5. Inside view manager the conversion happens, inside data_view, conversion to the view's necessary types happen.

Inside the view means code duplication

the-moisrex commented 2 years ago

Where should view_manager be used?

  1. In the context
  2. In the server/protocol
  3. In the application
  4. In the request
  5. Call applications with a context and not request

In the context, it wouldn't be able to cache the parsed files unless with a few tricks that I don't like. Context is router specific thing. The user may want to use another type of router.

In the server/protocol, it can be stored for a long running process. But it's not that straight forward to pass it to the application. There are multiple ways we can achieve this but it'll complicate the things that the user needs to do in order to use it.

In the application, everything seems okay, but the problem is that the user has to manage its life time and that'll complicate things for the user.

The request needs to stay a request, it doesn't make sense for a request to contain a view.

Calling application with a context will probably save the whole issue; at this point, I'm not sure why I designed the routing system this way; I should check this more...