Merge pull request #486 from rstacruz/encoding_fix

Implement the :encoding setting which defaults to 'utf-8'
This commit is contained in:
Thomas Reynolds 2012-06-16 15:04:54 -07:00
commit f6b55e8674
3 changed files with 35 additions and 1 deletions

View file

@ -117,6 +117,10 @@ module Middleman
# @return [String] # @return [String]
set :http_prefix, "/" set :http_prefix, "/"
# Default string encoding for templates and output.
# @return [String]
set :encoding, "utf-8"
# Whether to catch and display exceptions # Whether to catch and display exceptions
# @return [Boolean] # @return [Boolean]
set :show_exceptions, true set :show_exceptions, true
@ -128,6 +132,9 @@ module Middleman
# Activate custom features and extensions # Activate custom features and extensions
include Middleman::CoreExtensions::Extensions include Middleman::CoreExtensions::Extensions
# Manage Ruby string encodings
include Middleman::CoreExtensions::RubyEncoding
# Basic Rack Request Handling # Basic Rack Request Handling
include Middleman::CoreExtensions::Request include Middleman::CoreExtensions::Request

View file

@ -27,4 +27,7 @@ require "middleman-core/core_extensions/rendering"
require "middleman-core/core_extensions/routing" require "middleman-core/core_extensions/routing"
# Catch and show exceptions at the Rack level # Catch and show exceptions at the Rack level
require "middleman-core/core_extensions/show_exceptions" require "middleman-core/core_extensions/show_exceptions"
# Manage Ruby string encodings
require "middleman-core/core_extensions/ruby_encoding"

View file

@ -0,0 +1,24 @@
# Simple extension to manage Ruby encodings
module Middleman::CoreExtensions::RubyEncoding
# Setup extension
class << self
# Once registerd
def registered(app)
app.send :include, InstanceMethods
end
end
module InstanceMethods
def initialize
if Object.const_defined?(:Encoding)
Encoding.default_internal = encoding
Encoding.default_external = encoding
end
super
end
end
end