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