Work around Listen :only weirdness. Addresses #1637

This commit is contained in:
Thomas Reynolds 2015-11-27 15:26:46 -08:00
parent 822a9f0ecc
commit dd0ee24ca3
10 changed files with 24 additions and 22 deletions

View file

@ -57,3 +57,7 @@ Metrics/AbcSize:
Enabled: false Enabled: false
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Enabled: false Enabled: false
Style/ParallelAssignment:
Enabled: false
Style/BlockDelimiters:
Enabled: false

View file

@ -8,8 +8,8 @@ module Middleman
Contract Any Contract Any
def initialize def initialize
@callbacks = ::Hamster.hash @callbacks = ::Hamster::Hash.empty
@subscribers = ::Hamster.vector @subscribers = ::Hamster::Vector.empty
end end
Contract RespondTo[:define_singleton_method], ArrayOf[Symbol] => Any Contract RespondTo[:define_singleton_method], ArrayOf[Symbol] => Any
@ -55,7 +55,7 @@ module Middleman
Contract Or[Symbol, ArrayOf[Symbol]] => ::Hamster::Vector Contract Or[Symbol, ArrayOf[Symbol]] => ::Hamster::Vector
def callbacks_for(keys) def callbacks_for(keys)
immutable_keys = keys.is_a?(Symbol) ? keys : ::Hamster::Vector.new(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 end
end end

View file

@ -11,7 +11,7 @@ module Middleman
attr_reader :descriptors attr_reader :descriptors
def initialize def initialize
@descriptors = ::Hamster.set @descriptors = ::Hamster::Set.empty
end end
def method_missing(name, *args, &block) def method_missing(name, *args, &block)

View file

@ -183,12 +183,12 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
def on_file_changed(_updated_files, _removed_files) def on_file_changed(_updated_files, _removed_files)
@_langs = nil # Clear langs cache @_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! ::I18n.reload!
end end
def configure_i18n 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.reload!
::I18n.default_locale = @mount_at_root ::I18n.default_locale = @mount_at_root

View file

@ -37,8 +37,7 @@ module Middleman
engine = extension[1..-1].to_sym engine = extension[1..-1].to_sym
# Store last engine for later (could be inside nested renders) # Store last engine for later (could be inside nested renders)
context.current_engine = engine context.current_engine, engine_was = engine, context.current_engine
engine_was = context.current_engine
# Save current buffer for later # Save current buffer for later
buf_was = context.save_buffer buf_was = context.save_buffer

View file

@ -69,7 +69,7 @@ module Middleman
@resources = [] @resources = []
@update_count = 0 @update_count = 0
@resource_list_manipulators = ::Hamster.vector @resource_list_manipulators = ::Hamster::Vector.empty
@needs_sitemap_rebuild = true @needs_sitemap_rebuild = true
@lock = Monitor.new @lock = Monitor.new

View file

@ -47,10 +47,10 @@ module Middleman
@options = options @options = options
# Set of procs wanting to be notified of changes # Set of procs wanting to be notified of changes
@on_change_callbacks = ::Hamster.vector @on_change_callbacks = ::Hamster::Vector.empty
# Global ignores # Global ignores
@ignores = ::Hamster.hash @ignores = ::Hamster::Hash.empty
# Whether we're "running", which means we're in a stable # Whether we're "running", which means we're in a stable
# watch state after all initialization and config. # watch state after all initialization and config.

View file

@ -161,7 +161,7 @@ module Middleman
@listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change)) @listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change))
@listener.ignore(/^\.sass-cache/) @listener.ignore(/^\.sass-cache/)
@listener.only(@only) unless @only.empty? # @listener.only(@only) unless @only.empty?
@listener.start @listener.start
end end
@ -216,8 +216,6 @@ module Middleman
return if updated.empty? && removed.empty? return if updated.empty? && removed.empty?
updated |= find_related_files(updated + removed)
update(updated.map { |s| Pathname(s) }, removed.map { |s| Pathname(s) }) update(updated.map { |s| Pathname(s) }, removed.map { |s| Pathname(s) })
end end
@ -227,7 +225,7 @@ module Middleman
# @return [void] # @return [void]
Contract ArrayOf[Pathname], ArrayOf[Pathname] => Any Contract ArrayOf[Pathname], ArrayOf[Pathname] => Any
def update(updated_paths, removed_paths) def update(updated_paths, removed_paths)
valid_updates = updated_paths valid_updates = (updated_paths | find_related_files(updated_paths + removed_paths))
.lazy .lazy
.map(&method(:path_to_source_file)) .map(&method(:path_to_source_file))
.select(&method(:valid?)) .select(&method(:valid?))
@ -304,13 +302,15 @@ module Middleman
# Finds files which should also be considered to be dirty when # Finds files which should also be considered to be dirty when
# the given file(s) are touched. # the given file(s) are touched.
# #
# @param [Array] files The original touched file paths. # @param [Pathname] files The original touched file paths.
# @return [Array] All related file paths, not including the source file paths. # @return [Pathname] All related file paths, not including the source file paths.
Contract ArrayOf[String] => ArrayOf[String] Contract ArrayOf[Pathname] => ArrayOf[Pathname]
def find_related_files(files) def find_related_files(files)
files.flat_map do |file| files.flat_map do |file|
# If any partial file changes, reload all non-partials # 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.compact.uniq - files
end end
end end

View file

@ -42,8 +42,7 @@ module Middleman
# @api private # @api private
# @return [String] The old buffer. # @return [String] The old buffer.
def save_buffer def save_buffer
buf_was = @_out_buf @_out_buf, buf_was = '', @_out_buf
@_out_buf = ''
buf_was buf_was
end end

View file

@ -53,6 +53,6 @@ Gem::Specification.new do |s|
# Hash stuff # Hash stuff
s.add_dependency('hashie', ['~> 3.4']) s.add_dependency('hashie', ['~> 3.4'])
s.add_dependency('hamster', ['~> 1.0']) s.add_dependency('hamster', ['~> 2.0'])
s.add_dependency('backports', ['~> 3.6']) s.add_dependency('backports', ['~> 3.6'])
end end