From cc988ee302cb8aedd5141a036d33e8ca20e9c9fe Mon Sep 17 00:00:00 2001 From: Leon Bogaert Date: Thu, 31 Jan 2013 23:04:49 +0100 Subject: [PATCH] Added before_render & after_render hook Can be used for pre-processing content --- .../lib/middleman-core/core_extensions/rendering.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index 4f1ade6c..83c5d737 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -19,6 +19,9 @@ module Middleman # Include methods app.send :include, InstanceMethods + app.define_hook :before_render + app.define_hook :after_render + # Activate custom renderers require "middleman-core/renderers/erb" app.register Middleman::Renderers::ERb @@ -249,7 +252,10 @@ module Middleman end # Render using Tilt - template.render(context, locs, &block) + run_hook :before_render, template.data, template + content = template.render(context, locs, &block) + run_hook :after_render, content, template + return content ensure # Reset stored buffer @_out_buf = _buf_was