1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

Merge pull request #1515 from yterajima/issue/after_render-hook-is-not-work

fixed 'after_render' hook is not work.
This commit is contained in:
Thomas Reynolds 2015-05-06 08:08:29 -07:00
commit 051f102aa0
4 changed files with 62 additions and 1 deletions

View file

@ -0,0 +1,13 @@
Feature: Extension author could use some hooks
Scenario: When build
Given a fixture app "extension-hooks-app"
When I run `middleman build`
Then the exit status should be 0
And the output should contain "/// after_configuration ///"
And the output should contain "/// ready ///"
And the output should contain "/// before_build ///"
And the output should contain "/// before ///"
And the output should contain "/// before_render ///"
And the output should contain "/// after_render ///"
And the output should contain "/// after_build ///"

View file

@ -0,0 +1,39 @@
set :layout, false
class MyFeature < Middleman::Extension
def initialize(app, options_hash = {}, &block)
super
app.before do
puts '/// before ///'
end
app.ready do
puts '/// ready ///'
end
app.before_render do |body, path, locs, template_class|
puts "/// before_render ///"
end
app.after_render do |content, path, locs, template_class|
puts "/// after_render ///"
end
app.before_build do |builder|
puts "/// before_build ///"
end
app.after_build do |builder|
puts "/// after_build ///"
end
end
def after_configuration
puts '/// after_configuration ///'
end
end
::Middleman::Extensions.register(:my_feature, MyFeature)
activate :my_feature

View file

@ -0,0 +1,9 @@
<html>
<head>
<meta charset="utf-8">
<title>extension-hooks-app</title>
</head>
<body>
<h1>extension-hooks-app</h1>
</body>
</html>

View file

@ -76,7 +76,7 @@ module Middleman
end
# Allow hooks to manipulate the result after render
content = @app.callbacks_for(:before_render).reduce(content) do |sum, callback|
content = @app.callbacks_for(:after_render).reduce(content) do |sum, callback|
callback.call(sum, path, locs, template_class) || sum
end