Blindly attempt to imrpove encoding situation

This commit is contained in:
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. # Avoid weird race condition when a file is renamed.
content = begin content = begin
File.read(full_path) read_data_file(full_path)
rescue ::EOFError rescue ::EOFError
rescue ::IOError rescue ::IOError
rescue ::Errno::ENOENT rescue ::Errno::ENOENT
@ -208,6 +208,15 @@ module Middleman::CoreExtensions
[data, content] [data, content]
end 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) def normalize_path(path)
path.sub(%r{^#{Regexp.escape(app.source_dir)}\/}, '') path.sub(%r{^#{Regexp.escape(app.source_dir)}\/}, '')
end end

View file

@ -217,10 +217,19 @@ module Middleman
# Render the partial if found, otherwide throw exception # Render the partial if found, otherwide throw exception
_render_with_all_renderers(found_partial, locals, self, options, &block) _render_with_all_renderers(found_partial, locals, self, options, &block)
else else
File.read(found_partial) read_template_file(found_partial)
end end
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. # Partial locator.
# #
# @param [String] partial_name # @param [String] partial_name
@ -277,6 +286,7 @@ module Middleman
extension = File.extname(path) extension = File.extname(path)
options = opts.dup.merge(options_for_ext(extension)) options = opts.dup.merge(options_for_ext(extension))
options[:outvar] ||= '@_out_buf' options[:outvar] ||= '@_out_buf'
options[:default_encoding] ||= 'UTF-8'
options.delete(:layout) options.delete(:layout)
# Overwrite with frontmatter options # Overwrite with frontmatter options
@ -299,6 +309,8 @@ module Middleman
::Tilt.new(path, 1, options) { body } ::Tilt.new(path, 1, options) { body }
end end
', :default_encoding => 'Big5'
# Render using Tilt # Render using Tilt
content = template.render(context || ::Object.new, locs, &block) content = template.render(context || ::Object.new, locs, &block)
@ -326,7 +338,7 @@ module Middleman
# @param [String] path # @param [String] path
# @return [String] # @return [String]
def template_data_for_file(path) def template_data_for_file(path)
File.read(File.expand_path(path, source_dir)) read_template_file(File.expand_path(path, source_dir))
end end
# Get a hash of configuration options for a given file extension, from # 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 'rspec/expectations'
require 'capybara/cucumber' require 'capybara/cucumber'