From 3b6c63fbfd302ff1cd2e6cda2dc92f5aaee8410c Mon Sep 17 00:00:00 2001 From: Jordan Hollinger Date: Wed, 17 Jan 2024 15:53:09 -0500 Subject: [PATCH] Add Extensions section to README.md Signed-off-by: Jordan Hollinger Signed-off-by: Jordan Hollinger --- README.md | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 42ec3795..abc0c52b 100644 --- a/README.md +++ b/README.md @@ -933,7 +933,7 @@ Output:
Reflection -Blueprint classes may be reflected on to inspect their views, fields, and associations. +Blueprint classes may be reflected on to inspect their views, fields, and associations. Extensions often make use of this ability. ```ruby # A Hash of views keyed by name @@ -959,6 +959,42 @@ assoc[:category].options ```
+
+Extensions + +Blueprinter offers an extension system to hook into and modify certain behavior. + +```ruby +Blueprinter.configure do |config| + config.extensions << MyExtension.new + config.extensions << OtherExtension.new +end +``` + +The following class implements all extension hooks. If you have an idea for a new one, open an issue or PR. + +```ruby +class ExampleExtension < Blueprinter::Extension + # + # Called eary during "render", this method receives the object to be rendered and + # returns a new or modified object. If there are multiple pre_render extensions, + # the return value of one becomes the input object of the next. The final return + # value is used to render. + # + # @param object [Object] The object that was passed to "render" + # @param blueprint [Class] The Blueprinter class + # @param view [Symbol] The blueprint view + # @param options [Hash] Options passed to "render" + # @return [Object] The modified, or new, object to render + # + def pre_render(object, blueprint, view, options) + # modify or replace object + object + end +end +``` +
+
Deprecations