From 4594f46fb8ca8227e50e51a9706224cdd1ea5397 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 27 Nov 2015 14:16:55 -0800 Subject: [PATCH] Minor tweak to #1695 --- .../lib/middleman-core/application.rb | 1 - .../lib/middleman-core/file_renderer.rb | 3 ++- .../lib/middleman-core/preview_server.rb | 4 ++-- .../server_information_callback_proxy.rb | 6 ++--- .../lib/middleman-core/sitemap/resource.rb | 4 +--- .../middleman-core/sources/source_watcher.rb | 24 +++++-------------- .../lib/middleman-core/template_context.rb | 3 ++- .../lib/middleman-core/util/data.rb | 8 +++---- 8 files changed, 20 insertions(+), 33 deletions(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 75713c2f..5b8cbe9d 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -398,7 +398,6 @@ module Middleman execute_callbacks(:before_shutdown) end - # Set attributes (global variables) # # @deprecated Prefer accessing settings through "config". diff --git a/middleman-core/lib/middleman-core/file_renderer.rb b/middleman-core/lib/middleman-core/file_renderer.rb index 31b1e799..2d2137e6 100644 --- a/middleman-core/lib/middleman-core/file_renderer.rb +++ b/middleman-core/lib/middleman-core/file_renderer.rb @@ -37,7 +37,8 @@ module Middleman engine = extension[1..-1].to_sym # Store last engine for later (could be inside nested renders) - context.current_engine, engine_was = engine, context.current_engine + context.current_engine = engine + engine_was = context.current_engine # Save current buffer for later buf_was = context.save_buffer diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 25bb5276..8080868a 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -62,7 +62,7 @@ module Middleman # To output the child PID, let's make preview server a daemon by hand if child_pid = fork app.logger.info "== Middleman preview server is running in background with PID #{child_pid}" - Process.detach child_pid + Process.detach child_pid exit 0 else $stdout.reopen('/dev/null', 'w') @@ -183,7 +183,7 @@ module Middleman app.logger.warn format('== The Middleman uses a different port "%s" then the configured one "%s" because some other server is listening on that port.', server_information.port, configured_port) unless app.config[:port] == configured_port - @environment = app.config[:environment] + @environment = app.config[:environment] @ssl_certificate = app.config[:ssl_certificate] @ssl_private_key = app.config[:ssl_private_key] diff --git a/middleman-core/lib/middleman-core/preview_server/server_information_callback_proxy.rb b/middleman-core/lib/middleman-core/preview_server/server_information_callback_proxy.rb index 106abba0..e913612d 100644 --- a/middleman-core/lib/middleman-core/preview_server/server_information_callback_proxy.rb +++ b/middleman-core/lib/middleman-core/preview_server/server_information_callback_proxy.rb @@ -13,15 +13,15 @@ module Middleman attr_reader :server_name, :port, :site_addresses, :listeners def initialize(server_information) - @listeners = ServerUrl.new( + @listeners = ServerUrl.new( hosts: server_information.listeners, - port: server_information.port, + port: server_information.port, https: server_information.https?, format_output: false ).to_bind_addresses @port = server_information.port - @server_name = server_information.server_name.dup unless server_information.server_name == nil + @server_name = server_information.server_name.dup unless server_information.server_name.nil? @site_addresses = ServerUrl.new( hosts: server_information.site_addresses, diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index cb054460..c763cdf8 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -133,9 +133,7 @@ module Middleman locs[:current_path] ||= destination_path # Certain output file types don't use layouts - unless opts.key?(:layout) - opts[:layout] = false if ext != '.html' - end + opts[:layout] = false unless opts.key?(:layout) || !ext != '.html' renderer = ::Middleman::TemplateRenderer.new(@app, file_descriptor[:full_path].to_s) renderer.render(locs, opts) diff --git a/middleman-core/lib/middleman-core/sources/source_watcher.rb b/middleman-core/lib/middleman-core/sources/source_watcher.rb index 3f496594..1280cec1 100644 --- a/middleman-core/lib/middleman-core/sources/source_watcher.rb +++ b/middleman-core/lib/middleman-core/sources/source_watcher.rb @@ -182,14 +182,8 @@ module Middleman # @return [void] Contract Any def poll_once! - removed = @files.keys - - updated = [] - - ::Middleman::Util.all_files_under(@directory.to_s).each do |filepath| - removed.delete(filepath) - updated << filepath - end + updated = ::Middleman::Util.all_files_under(@directory.to_s) + removed = @files.keys.reject { |p| updated.include?(p) } update(updated, removed) @@ -314,16 +308,10 @@ module Middleman # @return [Array] All related file paths, not including the source file paths. Contract ArrayOf[String] => ArrayOf[String] def find_related_files(files) - files.map do |file| - related_files = [] - - # If any SASS file changes, reload all non-partials - if file =~ /\.(sass|scss)$/ - related_files |= Dir[File.join(@directory, app.config[:css_dir], '**/[^_]*.{scss,sass}')] - end - - related_files - end.flatten.uniq - files + files.flat_map do |file| + # If any partial file changes, reload all non-partials + Dir[File.join(@directory, app.config[:source], "**/[^_]*.#{File.extname(file)}")] if File.basename(file).start_with?('_') + end.compact.uniq - files end end end diff --git a/middleman-core/lib/middleman-core/template_context.rb b/middleman-core/lib/middleman-core/template_context.rb index f424c2b1..1461e185 100644 --- a/middleman-core/lib/middleman-core/template_context.rb +++ b/middleman-core/lib/middleman-core/template_context.rb @@ -42,7 +42,8 @@ module Middleman # @api private # @return [String] The old buffer. def save_buffer - @_out_buf, buf_was = '', @_out_buf + buf_was = @_out_buf + @_out_buf = '' buf_was end diff --git a/middleman-core/lib/middleman-core/util/data.rb b/middleman-core/lib/middleman-core/util/data.rb index d2668dda..0b3d0967 100644 --- a/middleman-core/lib/middleman-core/util/data.rb +++ b/middleman-core/lib/middleman-core/util/data.rb @@ -25,10 +25,10 @@ module Middleman::Util::Data end start_delims, stop_delims = frontmatter_delims - .values - .flatten(1) - .transpose - .map(&Regexp.method(:union)) + .values + .flatten(1) + .transpose + .map(&Regexp.method(:union)) match = / \A(?:[^\r\n]*coding:[^\r\n]*\r?\n)?