From 9c8908ab12005b18f89d6c0a299f7531c9392260 Mon Sep 17 00:00:00 2001 From: Chris Andreae Date: Tue, 30 May 2023 12:31:34 +0900 Subject: [PATCH] VM::Controller: add hook to render metadata in the same context This would permit metadata serialization to contribute referenced viewmodels. --- lib/iknow_view_models/version.rb | 2 +- lib/view_model/controller.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/iknow_view_models/version.rb b/lib/iknow_view_models/version.rb index 46d591de..70f8420b 100644 --- a/lib/iknow_view_models/version.rb +++ b/lib/iknow_view_models/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module IknowViewModels - VERSION = '3.7.3' + VERSION = '3.8.0' end diff --git a/lib/view_model/controller.rb b/lib/view_model/controller.rb index 43a6d5de..3220b4b7 100644 --- a/lib/view_model/controller.rb +++ b/lib/view_model/controller.rb @@ -24,6 +24,8 @@ def prerender_viewmodel(viewmodel, status: nil, serialize_context: viewmodel.cla ViewModel.serialize(viewmodel, json, serialize_context: serialize_context) end + render_response_metadata(json, serialize_context: serialize_context) + if serialize_context && serialize_context.has_references? json.references do serialize_context.serialize_references(json) @@ -34,6 +36,9 @@ def prerender_viewmodel(viewmodel, status: nil, serialize_context: viewmodel.cla end end + def render_response_metadata(json, serialize_context:) + end + # Render an arbitrarily nested tree of hashes and arrays with pre-rendered # JSON string terminals. Useful for rendering cached views without parsing # then re-serializing the cached JSON.