diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 13595135..98a04717 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -40,6 +40,9 @@ module Middleman # Ready (all loading and parsing of extensions complete) hook define_hook :ready + # Runs before the build is started + define_hook :before_build + # Runs after the build is finished define_hook :after_build diff --git a/middleman-core/lib/middleman-core/cli/build.rb b/middleman-core/lib/middleman-core/cli/build.rb index 33365949..dde2a1b2 100644 --- a/middleman-core/lib/middleman-core/cli/build.rb +++ b/middleman-core/lib/middleman-core/cli/build.rb @@ -65,6 +65,8 @@ module Middleman::Cli opts[:glob] = options['glob'] if options.has_key?('glob') opts[:clean] = options['clean'] + self.class.shared_instance.run_hook :before_build, self + action BuildAction.new(self, opts) self.class.shared_instance.run_hook :after_build, self diff --git a/middleman-core/lib/middleman-core/extensions.rb b/middleman-core/lib/middleman-core/extensions.rb index 2c97fea0..65e1fbe9 100644 --- a/middleman-core/lib/middleman-core/extensions.rb +++ b/middleman-core/lib/middleman-core/extensions.rb @@ -175,6 +175,7 @@ module Middleman # Bind app hooks to local methods bind_before_configuration bind_after_configuration + bind_before_build bind_after_build end @@ -233,6 +234,19 @@ module Middleman end end + def bind_before_build + ext = self + if ext.respond_to?(:before_build) + @klass.before_build do |builder| + if ext.method(:before_build).arity === 1 + ext.before_build(builder) + else + ext.before_build + end + end + end + end + def bind_after_build ext = self if ext.respond_to?(:after_build)