nested layouts. closes #208

This commit is contained in:
Thomas Reynolds 2011-12-22 00:42:14 -08:00
parent 4d2e0d8a7d
commit ecea540ec7
10 changed files with 45 additions and 13 deletions

View file

@ -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!

View 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"

View file

@ -0,0 +1 @@
set :layout, :inner

View file

@ -0,0 +1 @@
Template

View file

@ -0,0 +1,4 @@
<% wrap_layout :outer do %>
Inner
<%= yield %>
<% end %>

View file

@ -0,0 +1,2 @@
Master
<%= yield %>

View file

@ -0,0 +1,4 @@
<% wrap_layout :master do %>
Outer
<%= yield %>
<% end %>

View file

@ -37,5 +37,4 @@ module Middleman::Cli
end
Base.map({ "s" => "server" })
Base.default_task :server
end

View file

@ -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.
@ -199,6 +203,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
end

View file

@ -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
end
end
def kill_command
::Middleman::WINDOWS ? 1 : :INT
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