builder hooks
This commit is contained in:
parent
ec0aa868f4
commit
45f18a6580
|
@ -2,6 +2,7 @@ require "thor"
|
||||||
require "thor/group"
|
require "thor/group"
|
||||||
require 'rack/test'
|
require 'rack/test'
|
||||||
require 'find'
|
require 'find'
|
||||||
|
require 'hooks'
|
||||||
|
|
||||||
SHARED_SERVER = Middleman.server
|
SHARED_SERVER = Middleman.server
|
||||||
SHARED_SERVER.set :environment, :build
|
SHARED_SERVER.set :environment, :build
|
||||||
|
@ -31,6 +32,9 @@ module Middleman
|
||||||
class Builder < Thor::Group
|
class Builder < Thor::Group
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
include Middleman::ThorActions
|
include Middleman::ThorActions
|
||||||
|
include ::Hooks
|
||||||
|
|
||||||
|
define_hook :after_build
|
||||||
|
|
||||||
def self.shared_rack
|
def self.shared_rack
|
||||||
@shared_rack ||= begin
|
@shared_rack ||= begin
|
||||||
|
@ -66,23 +70,13 @@ module Middleman
|
||||||
opts[:clean] = options["clean"] if options.has_key?("clean")
|
opts[:clean] = options["clean"] if options.has_key?("clean")
|
||||||
|
|
||||||
action GlobAction.new(self, SHARED_SERVER, opts)
|
action GlobAction.new(self, SHARED_SERVER, opts)
|
||||||
|
|
||||||
|
run_hook :after_build
|
||||||
end
|
end
|
||||||
|
|
||||||
@@hooks = {}
|
# Old API
|
||||||
def self.after_run(name, &block)
|
def self.after_run(name, &block)
|
||||||
@@hooks[name] = block
|
after_build(&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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,7 @@ module Middleman::CoreExtensions::Builder
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# Add a block/proc to be run after features have been setup
|
# Add a block/proc to be run after features have been setup
|
||||||
def after_build(&block)
|
def after_build(&block)
|
||||||
@run_after_build ||= []
|
::Middleman::Builder.after_build(&block)
|
||||||
@run_after_build << block
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_build_callbacks
|
|
||||||
@run_after_build ||= []
|
|
||||||
@run_after_build
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_reroute(&block)
|
def build_reroute(&block)
|
||||||
|
|
Loading…
Reference in a new issue