mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
builder hooks
This commit is contained in:
parent
ec0aa868f4
commit
45f18a6580
2 changed files with 9 additions and 21 deletions
|
@ -2,6 +2,7 @@ require "thor"
|
|||
require "thor/group"
|
||||
require 'rack/test'
|
||||
require 'find'
|
||||
require 'hooks'
|
||||
|
||||
SHARED_SERVER = Middleman.server
|
||||
SHARED_SERVER.set :environment, :build
|
||||
|
@ -31,6 +32,9 @@ module Middleman
|
|||
class Builder < Thor::Group
|
||||
include Thor::Actions
|
||||
include Middleman::ThorActions
|
||||
include ::Hooks
|
||||
|
||||
define_hook :after_build
|
||||
|
||||
def self.shared_rack
|
||||
@shared_rack ||= begin
|
||||
|
@ -66,23 +70,13 @@ module Middleman
|
|||
opts[:clean] = options["clean"] if options.has_key?("clean")
|
||||
|
||||
action GlobAction.new(self, SHARED_SERVER, opts)
|
||||
|
||||
run_hook :after_build
|
||||
end
|
||||
|
||||
@@hooks = {}
|
||||
# Old API
|
||||
def self.after_run(name, &block)
|
||||
@@hooks[name] = block
|
||||
end
|
||||
|
||||
def run_hooks
|
||||
return if options.has_key?("glob")
|
||||
|
||||
@@hooks.each do |name, proc|
|
||||
instance_eval(&proc)
|
||||
end
|
||||
|
||||
SHARED_SERVER.after_build_callbacks.each do |proc|
|
||||
instance_eval(&proc)
|
||||
end
|
||||
after_build(&block)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,13 +8,7 @@ module Middleman::CoreExtensions::Builder
|
|||
module ClassMethods
|
||||
# Add a block/proc to be run after features have been setup
|
||||
def after_build(&block)
|
||||
@run_after_build ||= []
|
||||
@run_after_build << block
|
||||
end
|
||||
|
||||
def after_build_callbacks
|
||||
@run_after_build ||= []
|
||||
@run_after_build
|
||||
::Middleman::Builder.after_build(&block)
|
||||
end
|
||||
|
||||
def build_reroute(&block)
|
||||
|
|
Loading…
Reference in a new issue