diff --git a/bin/middleman b/bin/middleman index b743f2d3..e055fbe3 100755 --- a/bin/middleman +++ b/bin/middleman @@ -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! diff --git a/features/nested_layouts.feature b/features/nested_layouts.feature new file mode 100644 index 00000000..146443c5 --- /dev/null +++ b/features/nested_layouts.feature @@ -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" \ No newline at end of file diff --git a/fixtures/nested-layout-app/config.rb b/fixtures/nested-layout-app/config.rb new file mode 100644 index 00000000..fe617582 --- /dev/null +++ b/fixtures/nested-layout-app/config.rb @@ -0,0 +1 @@ +set :layout, :inner \ No newline at end of file diff --git a/fixtures/nested-layout-app/source/index.html.erb b/fixtures/nested-layout-app/source/index.html.erb new file mode 100644 index 00000000..a1ab916e --- /dev/null +++ b/fixtures/nested-layout-app/source/index.html.erb @@ -0,0 +1 @@ +Template \ No newline at end of file diff --git a/fixtures/nested-layout-app/source/layouts/inner.erb b/fixtures/nested-layout-app/source/layouts/inner.erb new file mode 100644 index 00000000..62dfc12b --- /dev/null +++ b/fixtures/nested-layout-app/source/layouts/inner.erb @@ -0,0 +1,4 @@ +<% wrap_layout :outer do %> + Inner + <%= yield %> +<% end %> \ No newline at end of file diff --git a/fixtures/nested-layout-app/source/layouts/master.erb b/fixtures/nested-layout-app/source/layouts/master.erb new file mode 100644 index 00000000..18dcdbb7 --- /dev/null +++ b/fixtures/nested-layout-app/source/layouts/master.erb @@ -0,0 +1,2 @@ +Master +<%= yield %> \ No newline at end of file diff --git a/fixtures/nested-layout-app/source/layouts/outer.erb b/fixtures/nested-layout-app/source/layouts/outer.erb new file mode 100644 index 00000000..643d8efc --- /dev/null +++ b/fixtures/nested-layout-app/source/layouts/outer.erb @@ -0,0 +1,4 @@ +<% wrap_layout :master do %> + Outer + <%= yield %> +<% end %> \ No newline at end of file diff --git a/lib/middleman/cli/server.rb b/lib/middleman/cli/server.rb index 1cfde75c..b9befb45 100644 --- a/lib/middleman/cli/server.rb +++ b/lib/middleman/cli/server.rb @@ -37,5 +37,4 @@ module Middleman::Cli end Base.map({ "s" => "server" }) - Base.default_task :server end \ No newline at end of file diff --git a/lib/middleman/core_extensions/rendering.rb b/lib/middleman/core_extensions/rendering.rb index 5f066f8b..ba6e564e 100644 --- a/lib/middleman/core_extensions/rendering.rb +++ b/lib/middleman/core_extensions/rendering.rb @@ -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 diff --git a/lib/middleman/guard.rb b/lib/middleman/guard.rb index 650c8ec0..6473c4ce 100644 --- a/lib/middleman/guard.rb +++ b/lib/middleman/guard.rb @@ -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] 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 \ No newline at end of file