2011-07-06 13:46:06 -04:00
|
|
|
module Middleman::CoreExtensions::Routing
|
|
|
|
class << self
|
|
|
|
def registered(app)
|
2011-11-18 03:34:56 -05:00
|
|
|
app.send :include, InstanceMethods
|
2011-07-06 13:46:06 -04:00
|
|
|
end
|
|
|
|
alias :included :registered
|
|
|
|
end
|
|
|
|
|
2011-11-18 03:34:56 -05:00
|
|
|
module InstanceMethods
|
2011-07-06 13:46:06 -04:00
|
|
|
# Takes a block which allows many pages to have the same layout
|
|
|
|
# with_layout :admin do
|
|
|
|
# page "/admin/"
|
|
|
|
# page "/admin/login.html"
|
|
|
|
# end
|
|
|
|
def with_layout(layout_name, &block)
|
2011-11-08 18:38:15 -05:00
|
|
|
old_layout = layout
|
2011-07-06 13:46:06 -04:00
|
|
|
|
2011-07-08 18:01:57 -04:00
|
|
|
set :layout, layout_name
|
2011-11-18 03:34:56 -05:00
|
|
|
instance_exec(&block) if block_given?
|
2011-07-06 13:46:06 -04:00
|
|
|
ensure
|
2011-07-08 18:01:57 -04:00
|
|
|
set :layout, old_layout
|
2011-07-06 13:46:06 -04:00
|
|
|
end
|
2011-07-27 17:14:22 -04:00
|
|
|
|
2011-07-24 01:21:52 -04:00
|
|
|
# The page method allows the layout to be set on a specific path
|
|
|
|
# page "/about.html", :layout => false
|
|
|
|
# page "/", :layout => :homepage_layout
|
2011-11-20 16:48:28 -05:00
|
|
|
def page(url, opts={}, &block)
|
|
|
|
opts[:layout] = layout if opts[:layout].nil?
|
2011-11-14 00:57:53 -05:00
|
|
|
|
|
|
|
url = full_path(url)
|
2011-11-10 15:26:20 -05:00
|
|
|
|
2011-11-20 16:48:28 -05:00
|
|
|
if opts.has_key?(:proxy)
|
|
|
|
reroute(url, opts[:proxy])
|
2011-11-07 20:58:07 -05:00
|
|
|
|
2011-11-20 16:48:28 -05:00
|
|
|
if opts.has_key?(:ignore) && opts[:ignore]
|
|
|
|
ignore(opts[:proxy])
|
|
|
|
opts.delete(:ignore)
|
2011-11-10 15:26:20 -05:00
|
|
|
end
|
|
|
|
|
2011-11-20 16:48:28 -05:00
|
|
|
opts.delete(:proxy)
|
2011-07-27 17:14:22 -04:00
|
|
|
else
|
2011-11-20 16:48:28 -05:00
|
|
|
if opts.has_key?(:ignore) && opts[:ignore]
|
2011-11-08 18:38:15 -05:00
|
|
|
ignore(url)
|
2011-11-20 16:48:28 -05:00
|
|
|
opts.delete(:ignore)
|
2011-07-27 17:14:22 -04:00
|
|
|
end
|
2011-07-24 01:21:52 -04:00
|
|
|
end
|
2011-11-14 00:57:53 -05:00
|
|
|
|
|
|
|
a_block = block_given? ? block : nil
|
2011-11-20 16:48:28 -05:00
|
|
|
if a_block || !opts.empty?
|
|
|
|
sitemap.page(url) do
|
|
|
|
template.options = opts
|
|
|
|
template.blocks = [a_block]
|
|
|
|
end
|
2011-07-06 13:46:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|