Allow layouts to be disabled entirely
This commit is contained in:
parent
daf217567f
commit
0b9ea13364
|
@ -136,6 +136,9 @@ module Middleman
|
|||
|
||||
# Proxy web services requests in dev mode only
|
||||
autoload :Proxy, "middleman/features/proxy"
|
||||
|
||||
# Sprockets 2
|
||||
# autoload :Sprockets, "middleman/features/sprockets"
|
||||
|
||||
# Automatically resize images for mobile devises
|
||||
# autoload :TinySrc, "middleman/features/tiny_src"
|
||||
|
|
|
@ -11,11 +11,7 @@ module Middleman::CoreExtensions::Routing
|
|||
alias :included :registered
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def current_layout
|
||||
@layout
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def path_to_index(path)
|
||||
parts = path ? path.split('/') : []
|
||||
if parts.last.nil? || parts.last.split('.').length == 1
|
||||
|
@ -30,12 +26,12 @@ module Middleman::CoreExtensions::Routing
|
|||
# page "/admin/login.html"
|
||||
# end
|
||||
def with_layout(layout_name, &block)
|
||||
old_layout = current_layout
|
||||
old_layout = settings.layout
|
||||
|
||||
layout(layout_name)
|
||||
set :layout, layout_name
|
||||
class_eval(&block) if block_given?
|
||||
ensure
|
||||
layout(old_layout)
|
||||
set :layout, old_layout
|
||||
end
|
||||
|
||||
# The page method allows the layout to be set on a specific path
|
||||
|
@ -49,7 +45,7 @@ module Middleman::CoreExtensions::Routing
|
|||
paths << "#{url}/" if url.length > 1 && url.split("/").last.split('.').length <= 1
|
||||
paths << "#{path_to_index(url)}"
|
||||
|
||||
options[:layout] = current_layout if options[:layout].nil?
|
||||
options[:layout] = settings.layout if options[:layout].nil?
|
||||
|
||||
paths.each do |p|
|
||||
get(p) do
|
||||
|
|
|
@ -64,7 +64,7 @@ module Middleman
|
|||
end
|
||||
|
||||
# Default layout name
|
||||
layout :layout
|
||||
set :layout, :layout
|
||||
|
||||
# This will match all requests not overridden in the project's config.rb
|
||||
not_found do
|
||||
|
@ -98,15 +98,23 @@ module Middleman
|
|||
|
||||
options.merge!(request['custom_options'] || {})
|
||||
|
||||
old_layout = settings.current_layout
|
||||
settings.layout(options[:layout]) if !options[:layout].nil?
|
||||
layout = settings.fetch_layout_path.to_sym
|
||||
layout = false if options[:layout] == false or request.path_info =~ /\.(css|js)$/
|
||||
old_layout = settings.layout
|
||||
settings.set :layout, options[:layout] if !options[:layout].nil?
|
||||
|
||||
layout = if settings.layout
|
||||
if options[:layout] == false || request.path_info =~ /\.(css|js)$/
|
||||
false
|
||||
else
|
||||
settings.fetch_layout_path(settings.layout).to_sym
|
||||
end
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
render_options = { :layout => layout }
|
||||
render_options[:layout_engine] = options[:layout_engine] if options.has_key? :layout_engine
|
||||
result = render(request.path_info, render_options)
|
||||
settings.layout(old_layout)
|
||||
settings.set :layout, old_layout
|
||||
|
||||
if result
|
||||
content_type mime_type(File.extname(request.path_info)), :charset => 'utf-8'
|
||||
|
|
Loading…
Reference in a new issue