Work around Listen :only weirdness. Addresses #1637

feature/livereload-locales-data
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
Metrics/PerceivedComplexity:
Enabled: false
Style/ParallelAssignment:
Enabled: false
Style/BlockDelimiters:
Enabled: false

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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