nested layouts. closes #208
This commit is contained in:
parent
4d2e0d8a7d
commit
ecea540ec7
|
@ -56,7 +56,9 @@ module Middleman
|
|||
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!
|
||||
else
|
||||
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
|
||||
|
||||
Base.map({ "s" => "server" })
|
||||
Base.default_task :server
|
||||
end
|
|
@ -44,6 +44,8 @@ module Middleman::CoreExtensions::Rendering
|
|||
# the template don't persist for other templates.
|
||||
context = self.dup
|
||||
|
||||
@current_locs = locs, @current_opts = opts
|
||||
|
||||
while ::Tilt[path]
|
||||
content = render_individual_file(path, locs, opts, context)
|
||||
path = File.basename(path, File.extname(path))
|
||||
|
@ -60,6 +62,8 @@ module Middleman::CoreExtensions::Rendering
|
|||
ensure
|
||||
@current_engine = engine_was
|
||||
@content_blocks = nil
|
||||
@current_locs = nil
|
||||
@current_opts = nil
|
||||
end
|
||||
|
||||
# Sinatra/Padrino render method signature.
|
||||
|
@ -198,6 +202,12 @@ module Middleman::CoreExtensions::Rendering
|
|||
|
||||
layout_path
|
||||
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
|
||||
@current_engine ||= nil
|
||||
|
|
|
@ -41,12 +41,6 @@ module Guard
|
|||
def initialize(watchers = [], options = {})
|
||||
super
|
||||
@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
|
||||
|
||||
# Start Middleman in a fork
|
||||
|
@ -81,7 +75,7 @@ module Guard
|
|||
puts "== The Middleman is shutting down"
|
||||
if ::Middleman::JRUBY
|
||||
else
|
||||
Process.kill(kill_command, @server_job)
|
||||
Process.kill(self.class.kill_command, @server_job)
|
||||
Process.wait @server_job
|
||||
@server_job = nil
|
||||
end
|
||||
|
@ -113,6 +107,10 @@ module Guard
|
|||
paths.each { |path| tell_server(:delete => path) }
|
||||
end
|
||||
|
||||
def self.kill_command
|
||||
::Middleman::WINDOWS ? 1 : :INT
|
||||
end
|
||||
|
||||
private
|
||||
# Whether the passed files are config.rb or lib/*.rb
|
||||
# @param [Array<String>] paths Array of paths to check
|
||||
|
@ -129,9 +127,11 @@ module Guard
|
|||
uri = URI.parse("http://#{@options[:host]}:#{@options[:port]}/__middleman__")
|
||||
Net::HTTP.post_form(uri, {}.merge(params))
|
||||
end
|
||||
|
||||
def kill_command
|
||||
::Middleman::WINDOWS ? 1 : :INT
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Trap the interupt signal and shut down Guard (and thus the server) smoothly
|
||||
trap(::Guard::Middleman.kill_command) do
|
||||
::Guard.stop
|
||||
# exit!(0)
|
||||
end
|
Loading…
Reference in a new issue