middleman/middleman-core/lib/middleman-core/core_extensions/routing.rb

45 lines
1.4 KiB
Ruby
Raw Normal View History

2012-01-14 21:46:22 +01:00
# Routing extension
module Middleman
module CoreExtensions
module Routing
2014-01-01 03:21:30 +01:00
# The page method allows the layout to be set on a specific path
#
# page "/about.html", layout: false
# page "/", layout: :homepage_layout
2014-01-01 03:21:30 +01:00
#
# @param [String] url
# @param [Hash] opts
# @return [void]
def page(url, opts={})
options = opts.dup
2014-01-01 03:21:30 +01:00
# Default layout
options[:layout] = @app.config[:layout] if options[:layout].nil?
2014-04-29 19:50:21 +02:00
metadata = { options: options, locals: options.delete(:locals) || {} }
2014-01-01 03:21:30 +01:00
# If the url is a regexp
unless url.is_a?(Regexp) || url.include?('*')
# Normalized path
url = '/' + Middleman::Util.normalize_path(url)
2014-01-01 03:21:30 +01:00
if url.end_with?('/') || File.directory?(File.join(@app.source_dir, url))
url = File.join(url, @app.config[:index_file])
end
# Setup proxy
if target = options.delete(:proxy)
# TODO: deprecate proxy through page?
@app.proxy(url, target, opts.dup)
2014-01-01 03:21:30 +01:00
return
elsif options.delete(:ignore)
# TODO: deprecate ignore through page?
2014-01-01 03:21:30 +01:00
@app.ignore(url)
end
end
2014-01-01 03:21:30 +01:00
# Setup a metadata matcher for rendering those options
@app.sitemap.provides_metadata_for_path(url) { |_| metadata }
end
2011-07-06 19:46:06 +02:00
end
end
end