Add Viewable
callable object mixin for Ruby components
#959
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR builds upon the recent #892 PR by providing a
Viewable
mixin that Ruby components can use to become fully-fledged views with front matter and layout rendering support. It also fixes a cascade issue, so now you can chain multiple callable objects together and also return things like a Hash from a callable object which will automatically become a JSON response.This effectively means you can now write clean routes in
server/routes
, create Controllers inserver/controllers
, create Views insrc/_components/views
, and get a full MVC paradigm like you would be familiar with coming from frameworks like Rails, Hanami, etc. And because the underlying patterns are so simple (callable objects via mixins), any aspect of this can be further extended by app developers in their projects, e.g. we don't have a class for a "controller" or "action" or whatever, but that could be easily done! For example:I don't want to prematurely optimize for this kind of thing — I personally am not looking for the amount of OOP ceremony as Hanami recommends — but for folks who want that, I like the idea we provide the primitives so you can seamlessly scale up to Hanami levels or down to simple Roda route blocks whenever needed.