Blindly attempt to imrpove encoding situation

v3-stable
Thomas Reynolds 2015-06-09 10:15:24 -07:00
parent 915b059e4a
commit bb44e59e6e
3 changed files with 24 additions and 5 deletions

View File

@ -185,7 +185,7 @@ module Middleman::CoreExtensions
# Avoid weird race condition when a file is renamed.
content = begin
File.read(full_path)
read_data_file(full_path)
rescue ::EOFError
rescue ::IOError
rescue ::Errno::ENOENT
@ -208,6 +208,15 @@ module Middleman::CoreExtensions
[data, content]
end
def read_data_file(path)
data = File.open(path, 'rb') { |io| io.read }
if data.respond_to?(:force_encoding)
# Set it to the default external (without verifying)
data.force_encoding(Encoding.default_external) if Encoding.default_external
end
data
end
def normalize_path(path)
path.sub(%r{^#{Regexp.escape(app.source_dir)}\/}, '')
end

View File

@ -217,10 +217,19 @@ module Middleman
# Render the partial if found, otherwide throw exception
_render_with_all_renderers(found_partial, locals, self, options, &block)
else
File.read(found_partial)
read_template_file(found_partial)
end
end
def read_template_file(path)
data = ::File.open(path, 'rb') { |io| io.read }
if data.respond_to?(:force_encoding)
# Set it to the default external (without verifying)
data.force_encoding(::Encoding.default_external) if ::Encoding.default_external
end
data
end
# Partial locator.
#
# @param [String] partial_name
@ -277,6 +286,7 @@ module Middleman
extension = File.extname(path)
options = opts.dup.merge(options_for_ext(extension))
options[:outvar] ||= '@_out_buf'
options[:default_encoding] ||= 'UTF-8'
options.delete(:layout)
# Overwrite with frontmatter options
@ -299,6 +309,8 @@ module Middleman
::Tilt.new(path, 1, options) { body }
end
', :default_encoding => 'Big5'
# Render using Tilt
content = template.render(context || ::Object.new, locs, &block)
@ -326,7 +338,7 @@ module Middleman
# @param [String] path
# @return [String]
def template_data_for_file(path)
File.read(File.expand_path(path, source_dir))
read_template_file(File.expand_path(path, source_dir))
end
# Get a hash of configuration options for a given file extension, from

View File

@ -1,5 +1,3 @@
# encoding: UTF-8
require 'rspec/expectations'
require 'capybara/cucumber'