2011-08-04 22:43:42 -04:00
|
|
|
module Middleman::CoreExtensions::Builder
|
|
|
|
class << self
|
|
|
|
def registered(app)
|
2011-11-19 01:57:25 -05:00
|
|
|
app.define_hook :after_build
|
2011-08-04 22:43:42 -04:00
|
|
|
app.extend ClassMethods
|
2011-11-18 17:09:48 -05:00
|
|
|
app.send :include, InstanceMethods
|
2011-08-04 22:43:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
2011-08-04 22:52:23 -04:00
|
|
|
def build_reroute(&block)
|
|
|
|
@build_rerouters ||= []
|
2011-11-18 17:09:48 -05:00
|
|
|
@build_rerouters << block if block_given?
|
|
|
|
@build_rerouters
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module InstanceMethods
|
|
|
|
def build_reroute(&block)
|
|
|
|
self.class.build_reroute(&block)
|
2011-08-04 22:52:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def reroute_builder(desination, request_path)
|
|
|
|
result = [desination, request_path]
|
|
|
|
|
2011-11-18 17:09:48 -05:00
|
|
|
build_reroute.each do |block|
|
|
|
|
output = instance_exec(desination, request_path, &block)
|
2011-08-04 22:52:23 -04:00
|
|
|
if output
|
|
|
|
result = output
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
2011-08-04 22:43:42 -04:00
|
|
|
end
|
|
|
|
end
|