Normalize file path string encoding on darwin. For #1506
This commit is contained in:
parent
f7ba4ada20
commit
a25e9c6382
9 changed files with 47 additions and 9 deletions
|
@ -57,7 +57,9 @@ module Middleman
|
|||
# Root project directory (overwritten in middleman build/server)
|
||||
# @return [String]
|
||||
def self.root
|
||||
ENV['MM_ROOT'] || Dir.pwd
|
||||
r = ENV['MM_ROOT'] ? ENV['MM_ROOT'].dup : ::Middleman::Util.current_directory
|
||||
r.encode!('UTF-8', 'UTF-8-MAC') if RUBY_PLATFORM =~ /darwin/
|
||||
r
|
||||
end
|
||||
delegate :root, to: :"self.class"
|
||||
|
||||
|
|
|
@ -138,7 +138,9 @@ module Middleman::Cli
|
|||
base.remove_file f, force: true
|
||||
end
|
||||
|
||||
Dir[@build_dir.join('**', '*')].select { |d| File.directory?(d) }.each do |d|
|
||||
::Middleman::Util.glob_directory(@build_dir.join('**', '*'))
|
||||
.select { |d| File.directory?(d) }
|
||||
.each do |d|
|
||||
base.remove_file d, force: true if directory_empty? d
|
||||
end
|
||||
end
|
||||
|
|
|
@ -62,7 +62,7 @@ module Middleman::Cli
|
|||
unless ENV['MM_ROOT']
|
||||
puts '== Could not find a Middleman project config.rb'
|
||||
puts '== Treating directory as a static site to be served'
|
||||
ENV['MM_ROOT'] = Dir.pwd
|
||||
ENV['MM_ROOT'] = ::Middleman::Util.current_directory
|
||||
ENV['MM_SOURCE'] = ''
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@ module Middleman
|
|||
helpers_path = File.join(root, config[:helpers_dir])
|
||||
next unless File.exist?(helpers_path)
|
||||
|
||||
Dir[File.join(helpers_path, config[:helpers_filename_glob])].each do |filename|
|
||||
glob = File.join(helpers_path, config[:helpers_filename_glob])
|
||||
::Middleman::Util.glob_directory(glob).each do |filename|
|
||||
module_name = config[:helpers_filename_to_module_name_proc].call(filename)
|
||||
next unless module_name
|
||||
|
||||
|
|
|
@ -95,6 +95,8 @@ module Middleman
|
|||
# @param [Pathname] path The file that changed
|
||||
# @return [void]
|
||||
def did_change(path)
|
||||
path = path.to_s.encode!('UTF-8', 'UTF-8-MAC') if RUBY_PLATFORM =~ /darwin/
|
||||
|
||||
path = Pathname(path)
|
||||
logger.debug "== File Change: #{path}"
|
||||
@known_paths << path
|
||||
|
@ -106,6 +108,8 @@ module Middleman
|
|||
# @param [Pathname] path The file that was deleted
|
||||
# @return [void]
|
||||
def did_delete(path)
|
||||
path = path.to_s.encode!('UTF-8', 'UTF-8-MAC') if RUBY_PLATFORM =~ /darwin/
|
||||
|
||||
path = Pathname(path)
|
||||
logger.debug "== File Deletion: #{path}"
|
||||
@known_paths.delete(path)
|
||||
|
@ -146,7 +150,10 @@ module Middleman
|
|||
end
|
||||
|
||||
def exists?(path)
|
||||
path = path.to_s.encode!('UTF-8', 'UTF-8-MAC') if RUBY_PLATFORM =~ /darwin/
|
||||
|
||||
p = Pathname(path)
|
||||
|
||||
p = p.relative_path_from(Pathname(@app.root)) unless p.relative?
|
||||
@known_paths.include?(p)
|
||||
end
|
||||
|
|
|
@ -503,7 +503,7 @@ module Middleman
|
|||
|
||||
found_path = nil
|
||||
search_paths.each do |path_with_ext|
|
||||
found_path = Dir[path_with_ext].find do |path|
|
||||
found_path = ::Middleman::Util.glob_directory(path_with_ext).find do |path|
|
||||
::Tilt[path]
|
||||
end
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ module Middleman
|
|||
options = { force_polling: @options[:force_polling] }
|
||||
options[:latency] = @options[:latency] if @options[:latency]
|
||||
|
||||
@listener = Listen.to(Dir.pwd, options) do |modified, added, removed|
|
||||
@listener = Listen.to(::Middleman::Util.current_directory, options) do |modified, added, removed|
|
||||
added_and_modified = (modified + added)
|
||||
|
||||
# See if the changed file is config.rb or lib/*.rb
|
||||
|
@ -152,14 +152,16 @@ module Middleman
|
|||
$mm_reload = true
|
||||
@webrick.stop
|
||||
else
|
||||
wd = Pathname(::Middleman::Util.current_directory)
|
||||
|
||||
added_and_modified.each do |path|
|
||||
relative_path = Pathname(path).relative_path_from(Pathname(Dir.pwd)).to_s
|
||||
relative_path = Pathname(path).relative_path_from(wd).to_s
|
||||
next if app.files.ignored?(relative_path)
|
||||
app.files.did_change(relative_path)
|
||||
end
|
||||
|
||||
removed.each do |path|
|
||||
relative_path = Pathname(path).relative_path_from(Pathname(Dir.pwd)).to_s
|
||||
relative_path = Pathname(path).relative_path_from(wd).to_s
|
||||
next if app.files.ignored?(relative_path)
|
||||
app.files.did_delete(relative_path)
|
||||
end
|
||||
|
|
|
@ -222,6 +222,30 @@ module Middleman
|
|||
end
|
||||
end
|
||||
|
||||
# Glob a directory and try to keep path encoding consistent.
|
||||
#
|
||||
# @param [String] path The glob path.
|
||||
# @return [Array<String>]
|
||||
def glob_directory(path)
|
||||
results = ::Dir[path]
|
||||
|
||||
return results unless RUBY_PLATFORM =~ /darwin/
|
||||
|
||||
results.map { |r| r.encode('UTF-8', 'UTF-8-MAC') }
|
||||
end
|
||||
|
||||
# Get the PWD and try to keep path encoding consistent.
|
||||
#
|
||||
# @param [String] path The glob path.
|
||||
# @return [Array<String>]
|
||||
def current_directory
|
||||
result = ::Dir.pwd
|
||||
|
||||
return result unless RUBY_PLATFORM =~ /darwin/
|
||||
|
||||
result.encode('UTF-8', 'UTF-8-MAC')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Is mime type known to be non-binary?
|
||||
|
|
|
@ -133,7 +133,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
|
|||
end
|
||||
|
||||
def configure_i18n
|
||||
::I18n.load_path += Dir[File.join(app.root, @locales_glob)]
|
||||
::I18n.load_path += ::Middleman::Util.glob_directory(File.join(app.root, @locales_glob))
|
||||
::I18n.reload!
|
||||
|
||||
::I18n.default_locale = @mount_at_root
|
||||
|
|
Loading…
Reference in a new issue