From dd0ee24ca3ae728b00f8987d74c360557c910946 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Fri, 27 Nov 2015 15:26:46 -0800 Subject: [PATCH] Work around Listen :only weirdness. Addresses #1637 --- .rubocop.yml | 4 ++++ .../lib/middleman-core/callback_manager.rb | 6 +++--- .../core_extensions/collections/step_context.rb | 2 +- .../lib/middleman-core/core_extensions/i18n.rb | 4 ++-- .../lib/middleman-core/file_renderer.rb | 3 +-- .../lib/middleman-core/sitemap/store.rb | 2 +- middleman-core/lib/middleman-core/sources.rb | 4 ++-- .../lib/middleman-core/sources/source_watcher.rb | 16 ++++++++-------- .../lib/middleman-core/template_context.rb | 3 +-- middleman-core/middleman-core.gemspec | 2 +- 10 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e4beee7e..30e6b9ee 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -57,3 +57,7 @@ Metrics/AbcSize: Enabled: false Metrics/PerceivedComplexity: Enabled: false +Style/ParallelAssignment: + Enabled: false +Style/BlockDelimiters: + Enabled: false diff --git a/middleman-core/lib/middleman-core/callback_manager.rb b/middleman-core/lib/middleman-core/callback_manager.rb index b2b03ba8..4315256a 100644 --- a/middleman-core/lib/middleman-core/callback_manager.rb +++ b/middleman-core/lib/middleman-core/callback_manager.rb @@ -8,8 +8,8 @@ module Middleman Contract Any def initialize - @callbacks = ::Hamster.hash - @subscribers = ::Hamster.vector + @callbacks = ::Hamster::Hash.empty + @subscribers = ::Hamster::Vector.empty end Contract RespondTo[:define_singleton_method], ArrayOf[Symbol] => Any @@ -55,7 +55,7 @@ module Middleman Contract Or[Symbol, ArrayOf[Symbol]] => ::Hamster::Vector def callbacks_for(keys) immutable_keys = keys.is_a?(Symbol) ? keys : ::Hamster::Vector.new(keys) - @callbacks.get(immutable_keys) || ::Hamster.vector + @callbacks.get(immutable_keys) || ::Hamster::Vector.empty end end end diff --git a/middleman-core/lib/middleman-core/core_extensions/collections/step_context.rb b/middleman-core/lib/middleman-core/core_extensions/collections/step_context.rb index fcf1d11f..c33c0833 100644 --- a/middleman-core/lib/middleman-core/core_extensions/collections/step_context.rb +++ b/middleman-core/lib/middleman-core/core_extensions/collections/step_context.rb @@ -11,7 +11,7 @@ module Middleman attr_reader :descriptors def initialize - @descriptors = ::Hamster.set + @descriptors = ::Hamster::Set.empty end def method_missing(name, *args, &block) diff --git a/middleman-core/lib/middleman-core/core_extensions/i18n.rb b/middleman-core/lib/middleman-core/core_extensions/i18n.rb index 3555f398..b9b112d6 100644 --- a/middleman-core/lib/middleman-core/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-core/core_extensions/i18n.rb @@ -183,12 +183,12 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension def on_file_changed(_updated_files, _removed_files) @_langs = nil # Clear langs cache - # TODO, add new file to ::I18n.load_path + ::I18n.load_path |= app.files.by_type(:locales).files.map { |p| p[:full_path].to_s } ::I18n.reload! end def configure_i18n - ::I18n.load_path += app.files.by_type(:locales).files.map { |p| p[:full_path].to_s } + ::I18n.load_path |= app.files.by_type(:locales).files.map { |p| p[:full_path].to_s } ::I18n.reload! ::I18n.default_locale = @mount_at_root diff --git a/middleman-core/lib/middleman-core/file_renderer.rb b/middleman-core/lib/middleman-core/file_renderer.rb index 2d2137e6..31b1e799 100644 --- a/middleman-core/lib/middleman-core/file_renderer.rb +++ b/middleman-core/lib/middleman-core/file_renderer.rb @@ -37,8 +37,7 @@ module Middleman engine = extension[1..-1].to_sym # Store last engine for later (could be inside nested renders) - context.current_engine = engine - engine_was = context.current_engine + context.current_engine, engine_was = engine, context.current_engine # Save current buffer for later buf_was = context.save_buffer diff --git a/middleman-core/lib/middleman-core/sitemap/store.rb b/middleman-core/lib/middleman-core/sitemap/store.rb index 24a26442..2d1e052d 100644 --- a/middleman-core/lib/middleman-core/sitemap/store.rb +++ b/middleman-core/lib/middleman-core/sitemap/store.rb @@ -69,7 +69,7 @@ module Middleman @resources = [] @update_count = 0 - @resource_list_manipulators = ::Hamster.vector + @resource_list_manipulators = ::Hamster::Vector.empty @needs_sitemap_rebuild = true @lock = Monitor.new diff --git a/middleman-core/lib/middleman-core/sources.rb b/middleman-core/lib/middleman-core/sources.rb index 7a7c7af9..3d5edaae 100644 --- a/middleman-core/lib/middleman-core/sources.rb +++ b/middleman-core/lib/middleman-core/sources.rb @@ -47,10 +47,10 @@ module Middleman @options = options # Set of procs wanting to be notified of changes - @on_change_callbacks = ::Hamster.vector + @on_change_callbacks = ::Hamster::Vector.empty # Global ignores - @ignores = ::Hamster.hash + @ignores = ::Hamster::Hash.empty # Whether we're "running", which means we're in a stable # watch state after all initialization and config. diff --git a/middleman-core/lib/middleman-core/sources/source_watcher.rb b/middleman-core/lib/middleman-core/sources/source_watcher.rb index 1280cec1..ff18c6f9 100644 --- a/middleman-core/lib/middleman-core/sources/source_watcher.rb +++ b/middleman-core/lib/middleman-core/sources/source_watcher.rb @@ -161,7 +161,7 @@ module Middleman @listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change)) @listener.ignore(/^\.sass-cache/) - @listener.only(@only) unless @only.empty? + # @listener.only(@only) unless @only.empty? @listener.start end @@ -216,8 +216,6 @@ module Middleman return if updated.empty? && removed.empty? - updated |= find_related_files(updated + removed) - update(updated.map { |s| Pathname(s) }, removed.map { |s| Pathname(s) }) end @@ -227,7 +225,7 @@ module Middleman # @return [void] Contract ArrayOf[Pathname], ArrayOf[Pathname] => Any def update(updated_paths, removed_paths) - valid_updates = updated_paths + valid_updates = (updated_paths | find_related_files(updated_paths + removed_paths)) .lazy .map(&method(:path_to_source_file)) .select(&method(:valid?)) @@ -304,13 +302,15 @@ module Middleman # Finds files which should also be considered to be dirty when # the given file(s) are touched. # - # @param [Array] files The original touched file paths. - # @return [Array] All related file paths, not including the source file paths. - Contract ArrayOf[String] => ArrayOf[String] + # @param [Pathname] files The original touched file paths. + # @return [Pathname] All related file paths, not including the source file paths. + Contract ArrayOf[Pathname] => ArrayOf[Pathname] def find_related_files(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?('_') + if File.basename(file).start_with?('_') + Dir[File.join(@directory, app.config[:source], "**/[^_]*.#{File.extname(file)}")].map { |p| Pathname(p) } + end end.compact.uniq - files end end diff --git a/middleman-core/lib/middleman-core/template_context.rb b/middleman-core/lib/middleman-core/template_context.rb index 1461e185..f424c2b1 100644 --- a/middleman-core/lib/middleman-core/template_context.rb +++ b/middleman-core/lib/middleman-core/template_context.rb @@ -42,8 +42,7 @@ module Middleman # @api private # @return [String] The old buffer. def save_buffer - buf_was = @_out_buf - @_out_buf = '' + @_out_buf, buf_was = '', @_out_buf buf_was end diff --git a/middleman-core/middleman-core.gemspec b/middleman-core/middleman-core.gemspec index 6fda5d8e..e910d6b9 100644 --- a/middleman-core/middleman-core.gemspec +++ b/middleman-core/middleman-core.gemspec @@ -53,6 +53,6 @@ Gem::Specification.new do |s| # Hash stuff s.add_dependency('hashie', ['~> 3.4']) - s.add_dependency('hamster', ['~> 1.0']) + s.add_dependency('hamster', ['~> 2.0']) s.add_dependency('backports', ['~> 3.6']) end