1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/lib/middleman/core_extensions/builder.rb

37 lines
801 B
Ruby
Raw Normal View History

module Middleman::CoreExtensions::Builder
class << self
def registered(app)
app.define_hook :after_build
app.extend ClassMethods
2011-11-18 17:09:48 -05:00
app.send :include, InstanceMethods
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
end
end