Adding before build hook

This commit is contained in:
Jonathan Soeder 2014-02-04 23:03:24 -06:00
parent 3b3ed654b7
commit 8d346e74a5
3 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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)