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/routing.rb

54 lines
1.4 KiB
Ruby
Raw Normal View History

2011-07-06 13:46:06 -04:00
module Middleman::CoreExtensions::Routing
class << self
def registered(app)
app.extend ClassMethods
end
alias :included :registered
end
2011-11-08 18:38:15 -05:00
module ClassMethods
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-07-06 13:46:06 -04:00
class_eval(&block) if block_given?
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
# The page method allows the layout to be set on a specific path
# page "/about.html", :layout => false
# page "/", :layout => :homepage_layout
def page(url, options={}, &block)
2011-11-08 18:38:15 -05:00
options[:layout] = layout if options[:layout].nil?
2011-11-14 00:57:53 -05:00
url = full_path(url)
if options.has_key?(:proxy)
reroute(url, options[:proxy])
2011-11-07 20:58:07 -05:00
2011-07-27 17:14:22 -04:00
if options.has_key?(:ignore) && options[:ignore]
2011-11-08 18:38:15 -05:00
ignore(options[:proxy])
2011-11-14 00:57:53 -05:00
options.delete(:ignore)
end
options.delete(:proxy)
2011-07-27 17:14:22 -04:00
else
if options.has_key?(:ignore) && options[:ignore]
2011-11-08 18:38:15 -05:00
ignore(url)
2011-11-14 00:57:53 -05:00
options.delete(:ignore)
2011-07-27 17:14:22 -04:00
end
end
2011-11-14 00:57:53 -05:00
a_block = block_given? ? block : nil
if a_block || !options.empty?
sitemap.set_context(url, options, a_block)
2011-07-06 13:46:06 -04:00
end
end
end
end