mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
37 lines
No EOL
801 B
Ruby
37 lines
No EOL
801 B
Ruby
module Middleman::CoreExtensions::Builder
|
|
class << self
|
|
def registered(app)
|
|
app.define_hook :after_build
|
|
app.extend ClassMethods
|
|
app.send :include, InstanceMethods
|
|
end
|
|
end
|
|
|
|
module ClassMethods
|
|
def build_reroute(&block)
|
|
@build_rerouters ||= []
|
|
@build_rerouters << block if block_given?
|
|
@build_rerouters
|
|
end
|
|
end
|
|
|
|
module InstanceMethods
|
|
def build_reroute(&block)
|
|
self.class.build_reroute(&block)
|
|
end
|
|
|
|
def reroute_builder(desination, request_path)
|
|
result = [desination, request_path]
|
|
|
|
build_reroute.each do |block|
|
|
output = instance_exec(desination, request_path, &block)
|
|
if output
|
|
result = output
|
|
break
|
|
end
|
|
end
|
|
|
|
result
|
|
end
|
|
end
|
|
end |