nested layouts. closes #208
This commit is contained in:
parent
4d2e0d8a7d
commit
ecea540ec7
|
@ -56,7 +56,9 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if ARGV.length < 1 || %w(server build migrate).include?(ARGV.first)
|
ARGV << "server" if ARGV.length < 1
|
||||||
|
|
||||||
|
if %w(server build migrate).include?(ARGV)
|
||||||
Middleman::ProjectLocator.locate_middleman_root!
|
Middleman::ProjectLocator.locate_middleman_root!
|
||||||
else
|
else
|
||||||
Middleman::ProjectLocator.start_cli!
|
Middleman::ProjectLocator.start_cli!
|
||||||
|
|
9
features/nested_layouts.feature
Normal file
9
features/nested_layouts.feature
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Feature: Allow nesting of layouts
|
||||||
|
|
||||||
|
Scenario: A page uses an inner layout when uses an outer layout
|
||||||
|
Given the Server is running at "nested-layout-app"
|
||||||
|
When I go to "/index.html"
|
||||||
|
Then I should see "Template"
|
||||||
|
And I should see "Inner"
|
||||||
|
And I should see "Outer"
|
||||||
|
And I should see "Master"
|
1
fixtures/nested-layout-app/config.rb
Normal file
1
fixtures/nested-layout-app/config.rb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
set :layout, :inner
|
1
fixtures/nested-layout-app/source/index.html.erb
Normal file
1
fixtures/nested-layout-app/source/index.html.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Template
|
4
fixtures/nested-layout-app/source/layouts/inner.erb
Normal file
4
fixtures/nested-layout-app/source/layouts/inner.erb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<% wrap_layout :outer do %>
|
||||||
|
Inner
|
||||||
|
<%= yield %>
|
||||||
|
<% end %>
|
2
fixtures/nested-layout-app/source/layouts/master.erb
Normal file
2
fixtures/nested-layout-app/source/layouts/master.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Master
|
||||||
|
<%= yield %>
|
4
fixtures/nested-layout-app/source/layouts/outer.erb
Normal file
4
fixtures/nested-layout-app/source/layouts/outer.erb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<% wrap_layout :master do %>
|
||||||
|
Outer
|
||||||
|
<%= yield %>
|
||||||
|
<% end %>
|
|
@ -37,5 +37,4 @@ module Middleman::Cli
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.map({ "s" => "server" })
|
Base.map({ "s" => "server" })
|
||||||
Base.default_task :server
|
|
||||||
end
|
end
|
|
@ -44,6 +44,8 @@ module Middleman::CoreExtensions::Rendering
|
||||||
# the template don't persist for other templates.
|
# the template don't persist for other templates.
|
||||||
context = self.dup
|
context = self.dup
|
||||||
|
|
||||||
|
@current_locs = locs, @current_opts = opts
|
||||||
|
|
||||||
while ::Tilt[path]
|
while ::Tilt[path]
|
||||||
content = render_individual_file(path, locs, opts, context)
|
content = render_individual_file(path, locs, opts, context)
|
||||||
path = File.basename(path, File.extname(path))
|
path = File.basename(path, File.extname(path))
|
||||||
|
@ -60,6 +62,8 @@ module Middleman::CoreExtensions::Rendering
|
||||||
ensure
|
ensure
|
||||||
@current_engine = engine_was
|
@current_engine = engine_was
|
||||||
@content_blocks = nil
|
@content_blocks = nil
|
||||||
|
@current_locs = nil
|
||||||
|
@current_opts = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sinatra/Padrino render method signature.
|
# Sinatra/Padrino render method signature.
|
||||||
|
@ -199,6 +203,12 @@ module Middleman::CoreExtensions::Rendering
|
||||||
layout_path
|
layout_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wrap_layout(layout_name, &block)
|
||||||
|
content = capture(&block) if block_given?
|
||||||
|
layout_path = locate_layout(layout_name, current_engine)
|
||||||
|
concat render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content }
|
||||||
|
end
|
||||||
|
|
||||||
def current_engine
|
def current_engine
|
||||||
@current_engine ||= nil
|
@current_engine ||= nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,12 +41,6 @@ module Guard
|
||||||
def initialize(watchers = [], options = {})
|
def initialize(watchers = [], options = {})
|
||||||
super
|
super
|
||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
# Trap the interupt signal and shut down Guard (and thus the server) smoothly
|
|
||||||
trap(kill_command) do
|
|
||||||
::Guard.stop
|
|
||||||
exit!(0)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Start Middleman in a fork
|
# Start Middleman in a fork
|
||||||
|
@ -81,7 +75,7 @@ module Guard
|
||||||
puts "== The Middleman is shutting down"
|
puts "== The Middleman is shutting down"
|
||||||
if ::Middleman::JRUBY
|
if ::Middleman::JRUBY
|
||||||
else
|
else
|
||||||
Process.kill(kill_command, @server_job)
|
Process.kill(self.class.kill_command, @server_job)
|
||||||
Process.wait @server_job
|
Process.wait @server_job
|
||||||
@server_job = nil
|
@server_job = nil
|
||||||
end
|
end
|
||||||
|
@ -113,6 +107,10 @@ module Guard
|
||||||
paths.each { |path| tell_server(:delete => path) }
|
paths.each { |path| tell_server(:delete => path) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.kill_command
|
||||||
|
::Middleman::WINDOWS ? 1 : :INT
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# Whether the passed files are config.rb or lib/*.rb
|
# Whether the passed files are config.rb or lib/*.rb
|
||||||
# @param [Array<String>] paths Array of paths to check
|
# @param [Array<String>] paths Array of paths to check
|
||||||
|
@ -129,9 +127,11 @@ module Guard
|
||||||
uri = URI.parse("http://#{@options[:host]}:#{@options[:port]}/__middleman__")
|
uri = URI.parse("http://#{@options[:host]}:#{@options[:port]}/__middleman__")
|
||||||
Net::HTTP.post_form(uri, {}.merge(params))
|
Net::HTTP.post_form(uri, {}.merge(params))
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def kill_command
|
# Trap the interupt signal and shut down Guard (and thus the server) smoothly
|
||||||
::Middleman::WINDOWS ? 1 : :INT
|
trap(::Guard::Middleman.kill_command) do
|
||||||
end
|
::Guard.stop
|
||||||
end
|
# exit!(0)
|
||||||
end
|
end
|
Loading…
Reference in a new issue